Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 1430: Programming in C++ No time to cover HiC.

Similar presentations


Presentation on theme: "CS 1430: Programming in C++ No time to cover HiC."— Presentation transcript:

1 CS 1430: Programming in C++ No time to cover HiC

2 Tracing Range Known Tracing Input: 48 54 66 53 59 -1
const int LOW_LIMIT = 0; const int HIGH_LIMIT = 60; int score, max = LOW_LIMIT; cin >> score; while (score != -1) { if (score < LOW_LIMIT || score > HIGH_LIMIT) cout << “Invalid score: ” << score; else if (score > max) max = score; } Tracing Input: score max ? 48 54 66 53 59 -1 How to do it? One statement each line Do not cross old values Blank when no new value WILL BE ON QUIZ And Test 1 And Final!

3 Quiz3-2 10 Minutes

4 Write C++ Statements // Decrease theCount by 2 until theCount is negative. while ( theCount >= 0 ) { theCount -= 2; } // Another way while ( !(theCount < 0) ) // Incorrect! while ( theCount !< 0 ) while ( theCount > 0 ) Slides could be moved to an earlier note

5 Write C++ Statements // While theValue is not positive, increase its value by 5. while ( theValue <= 0 ) { theValue += 5; } // Another way while ( !(theValue > 0) ) // Incorrect! while ( theValue < 0 )

6 Write C++ Statements DeMorgan’s Law
// While theValue is not positive and theCount is // less than 10, increase theValue by 5 and theCount by 1. while ( theValue <= 0 && theCount < 10 ) { theValue += 5; theCount ++; } // increase theValue by 5 and theCount by 1 // until theValue is positive or theCount is 10 or higher. while ( !(theValue > 0 || theCount >= 10) ) // The same? DeMorgan’s Law

7 Example int someValue = 0; int i = 0; while (i < 10) { int j = 0; while (j < 5) someValue += i * j; // A j ++; } i ++; How many times is statement A executed? None of above 50

8 Example int count = 0; int i = 0; while (i < 10) { int j = 5; while (j > 0) count ++; j --; } i ++; What is the final value of count? None of above 50

9 Example int total = 0; int i = 5; while (i > 0) { int j = i; while (j > 0) total += j; j --; } i --; What is the final value of total? None of above 35

10 Tracing Nested Loops int xValue, yValue, zValue; xValue = 3; while (xValue > 1) { zValue = 1; yValue = xValue; while (yValue > 0) zValue *= yValue; yValue --; } cout << "What is this: " << zValue; xValue --; xValue yValue zValue ? ? ? 3 1 2 6

11 Schedule Quiz3-3 Lab3 Prog1 Due 10 pm today Due 5 pm Thursday
Past Due already Grace Time: 10 pm Friday

12 Schedule Prog2 Test 1 Nested loops Started Tuesday, 9-22
Friday, October 2 60 points If, While, and Others

13 Getting Help Pals 9 – 3 pm, Thursdays Lab Assistants 6 – 9 pm, Mon - Thur Come to me for help Name your file: UserName_Lab/ProgX Drop your program in K:\Courses\CSSE\yangq\Dropbox

14 You can still receive 15 points on Prog1!


Download ppt "CS 1430: Programming in C++ No time to cover HiC."

Similar presentations


Ads by Google