w3bw
DESCRIPTION
wwwwTRANSCRIPT
![Page 1: w3bw](https://reader036.vdocuments.net/reader036/viewer/2022062519/5695ceff1a28ab9b028c253e/html5/thumbnails/1.jpg)
1
WORKSHOP 3 ~ LoopsCOMP 1117B 510/2015
![Page 2: w3bw](https://reader036.vdocuments.net/reader036/viewer/2022062519/5695ceff1a28ab9b028c253e/html5/thumbnails/2.jpg)
2
OUTLINE
Assignment 1 Feedback
Loops While For
Exercises
![Page 3: w3bw](https://reader036.vdocuments.net/reader036/viewer/2022062519/5695ceff1a28ab9b028c253e/html5/thumbnails/3.jpg)
3
ASSIGNMENT 1 TEST CASES
![Page 4: w3bw](https://reader036.vdocuments.net/reader036/viewer/2022062519/5695ceff1a28ab9b028c253e/html5/thumbnails/4.jpg)
4
COMMON MISTAKES
Incorrect filenames @-2%
Examples: UNo-dive.cpp Uno-lb.cpp dive_.cpp dive (2).cpp dive_assessment.cpp bl.cpp diving.cpp
![Page 5: w3bw](https://reader036.vdocuments.net/reader036/viewer/2022062519/5695ceff1a28ab9b028c253e/html5/thumbnails/5.jpg)
5
COMMON MISTAKES
Incorrect Results Example: Set the input to be integer variable
![Page 6: w3bw](https://reader036.vdocuments.net/reader036/viewer/2022062519/5695ceff1a28ab9b028c253e/html5/thumbnails/6.jpg)
6
COMMON MISTAKES
Incorrect Input/Output format
![Page 7: w3bw](https://reader036.vdocuments.net/reader036/viewer/2022062519/5695ceff1a28ab9b028c253e/html5/thumbnails/7.jpg)
7
COMMON MISTAKES
Spacing
Poor indentation
![Page 8: w3bw](https://reader036.vdocuments.net/reader036/viewer/2022062519/5695ceff1a28ab9b028c253e/html5/thumbnails/8.jpg)
8
COMMON MISTAKES
Poor indentation
Missing documentation
![Page 9: w3bw](https://reader036.vdocuments.net/reader036/viewer/2022062519/5695ceff1a28ab9b028c253e/html5/thumbnails/9.jpg)
9
CHECK YOUR MARKS AND COMMENTS
In Moodle, choose “Administration” “Grades”
Marks and Comments are given
Comment format like: lb.cpp (xx): Incorrect result for test cases
2, 3, 4. dive.cpp (yy): Incorrect result for test cases 1, 2. Warnings: Poor indentation.
xx – marks for lb.cpp, maximum 30%yy – marks for dive.cpp, maximum 70%Warnings: marks will not be deducted for this first assignment
![Page 10: w3bw](https://reader036.vdocuments.net/reader036/viewer/2022062519/5695ceff1a28ab9b028c253e/html5/thumbnails/10.jpg)
10
SAMPLE SOLUTIONS// COMP1117B Assignment 1 Question 1
// Convert kg to lb
#include <iostream>
using namespace std;
int main()
{
double kg = 0.0;
cin >> kg;
cout << kg * 2.2046;
return 0;
}
![Page 11: w3bw](https://reader036.vdocuments.net/reader036/viewer/2022062519/5695ceff1a28ab9b028c253e/html5/thumbnails/11.jpg)
11
SAMPLE SOLUTIONS// COMP 1117B Assignment 1 Question 2
// calculating diving score
#include <iostream>
using namespace std;
int main()
{
int m1, m2, m3, m4, m5, h, l;
m1 = m2 = m3 = m4 = m5 = h = l = 0;
cin >> m1 >> m2 >> m3 >> m4 >> m5;
// Discard the highest and lowest scores
h = l = m1;
if (m2 > h)
h = m2;
else if (m2 < l)
l = m2;
if (m3 > h)
h = m3;
else if (m3 < l)
l = m3;
if (m4 > h)
h = m4;
else if (m4 < l)
l = m4;
if (m5 > h)
h = m5;
else if (m5 < l)
l = m5;
cout << m1 + m2 + m3 + m4 + m5 - h - l << endl;
return 0;
}
![Page 12: w3bw](https://reader036.vdocuments.net/reader036/viewer/2022062519/5695ceff1a28ab9b028c253e/html5/thumbnails/12.jpg)
12
LOGIC ERROR
![Page 13: w3bw](https://reader036.vdocuments.net/reader036/viewer/2022062519/5695ceff1a28ab9b028c253e/html5/thumbnails/13.jpg)
13
LOOPS
While loop (Chapter 3 Page 24)
![Page 14: w3bw](https://reader036.vdocuments.net/reader036/viewer/2022062519/5695ceff1a28ab9b028c253e/html5/thumbnails/14.jpg)
14
LOOPS
For loop (Chapter 3 Page 32)
![Page 15: w3bw](https://reader036.vdocuments.net/reader036/viewer/2022062519/5695ceff1a28ab9b028c253e/html5/thumbnails/15.jpg)
15
EXAMPLE
Write a program to read 7 integers and then only report the average of the first 3 positive numbers.
![Page 16: w3bw](https://reader036.vdocuments.net/reader036/viewer/2022062519/5695ceff1a28ab9b028c253e/html5/thumbnails/16.jpg)
16
SAMPLE RUNS
![Page 17: w3bw](https://reader036.vdocuments.net/reader036/viewer/2022062519/5695ceff1a28ab9b028c253e/html5/thumbnails/17.jpg)
17
WRITTEN EXERCISE
What is the output of the following program? int a = 1; int b = 2;
if (a = b) cout << "Same!\n"; else cout << "Different!\n";
if (a == b)
![Page 18: w3bw](https://reader036.vdocuments.net/reader036/viewer/2022062519/5695ceff1a28ab9b028c253e/html5/thumbnails/18.jpg)
EXERCISE 1
Write a program (game.cpp) to ask the user to input a character until he/she input ‘!’. Print how many characters did the user input before entering ‘!’. (Ignore the space and newline)
Input: Ask the user to input a character (repeatedly until encountered ‘!’)
Process: Count the number of characters
Output: The count18
![Page 19: w3bw](https://reader036.vdocuments.net/reader036/viewer/2022062519/5695ceff1a28ab9b028c253e/html5/thumbnails/19.jpg)
19
SAMPLE RUNS
![Page 20: w3bw](https://reader036.vdocuments.net/reader036/viewer/2022062519/5695ceff1a28ab9b028c253e/html5/thumbnails/20.jpg)
20
EXERCISE 2
Let’s implement another game. Let’s set the secret number to be “66”
Write a program to ask the user to input a number between 1-100.
If the input number exactly same as the secret number, then print “Bingo” message.
Else tell the user to try again with hints
![Page 21: w3bw](https://reader036.vdocuments.net/reader036/viewer/2022062519/5695ceff1a28ab9b028c253e/html5/thumbnails/21.jpg)
21
SAMPLE RUNS
![Page 22: w3bw](https://reader036.vdocuments.net/reader036/viewer/2022062519/5695ceff1a28ab9b028c253e/html5/thumbnails/22.jpg)
22
THANKS!