07 Predicates and Intro to Loops

07 Predicates and Intro to Loops - Click to edit Master...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Click to edit Master subtitle style Engineering 101 Predicates and Intro to Loops Quote of the Day- Gandhi It is unwise to be too sure of one's own wisdom. It is healthy to be reminded that the strongest might weaken and the wisest might err. Using operators to construct n Start on some given day. While the day is not a weekend, add 8 hours to my timeclock and work, otherwise rest. 1 2 3 4 5 6 7 8 9 10 1112 13 14 15 16 17 18 19 Su M T W Th F Sa 20 2122 23 24 25 26 27 28 29 30 31 Using operators to construct 1 2 3 4 5 6 7 8 9 10 1112 13 14 15 16 17 18 19 Su M T W Th F Sa 20 2122 23 24 25 26 27 28 29 30 31 int Sun=0, Mon=1, Tue=2, Wed=3, Thu=4, Fri=5, Sat=6; int firstday= Tue; int timeclock=0, day = 9; firstday tells which day of the week the first day of the month falls upon Using operators to construct 1 2 3 4 5 6 7 8 9 10 1112 13 14 15 16 17 18 19 Su M T W Th F Sa 20 2122 23 24 25 26 27 28 29 30 31 int Sun=0, Mon=1, Tue=2, Wed=3, Thu=4, Fri=5, Sat=6; int firstday= Tue; int timeclock=0, day = 9; How do we determine whether it is a weekday? Using operators to construct 1 2 3 4 5 6 7 8 9 10 1112 13 14 15 16 17 18 19 Su M T W Th F Sa 20 2122 23 24 25 26 27 28 29 30 31 int Sun=0, Mon=1, Tue=2, Wed=3, Thu=4, Fri=5, Sat=6; int firstday= Tue; int timeclock=0, day = 9; (firstday+day-1) % 7 != Sun When is the above true? Using operators to construct 1 2 3 4 5 6 7 8 9 10 1112 13 14 15 16 17 18 19 Su M T W Th F Sa 20 2122 23 24 25 26 27 28 29 30 31 int Sun=0, Mon=1, Tue=2, Wed=3, Thu=4, Fri=5, Sat=6; int firstday= Tue; int timeclock=0, day = 9; while ( (firstday+day-1) % 7 != Sun and (firstday+day-1) % 7 != Sat ) { timeclock = timeclock + 8; cout << “I’m working.” << endl; This is only true on weekdays Using operators to construct 1 2 3 4 5 6 7 8 9 10 1112 13 14 15 16 17 18 19 Su M T W Th F Sa 20 2122 23 24 25 26 27 28 29 30 31 int Sun=0, Mon=1, Tue=2, Wed=3, Thu=4, Fri=5, Sat=6; int firstday= Tue; int timeclock=0, day = 9; while ( (firstday+day-1) % 7 != Sun and (firstday+day-1) % 7 != Sat ) { timeclock = timeclock + 8; cout << “I’m working.” << endl; What is the initialization? What is the condition? Where is the loop incremented? Using operators to construct 1 2 3 4 5 6 7 8 9 10 1112 13 14 15 16 17 18 19 Su M T W Th F Sa 20 2122 23 24 25 26 27 28 29 30 31 int Sun=0, Mon=1, Tue=2, Wed=3, Thu=4, Fri=5, Sat=6; int firstday= Tue; int timeclock=0, day = 9 ; while ( (firstday+day-1) % 7 != Sun and (firstday+day-1) % 7 != Sat ) { timeclock = timeclock + 8; cout << “I’m working.” << endl; What is the initialization?...
View Full Document

This note was uploaded on 04/07/2010 for the course ENGR engr 101 taught by Professor Rinenberg during the Spring '10 term at University of Michigan.

Page1 / 45

07 Predicates and Intro to Loops - Click to edit Master...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online