{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

07 - Predicates and Intro to Loops

# 07 - Predicates and Intro to Loops - Engineering 101...

This preview shows pages 1–11. Sign up to view the full content.

Engineering 101 Predicates and Intro to

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

View Full Document
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.
One more bit of selection: Switch Statements n A switch statement is used to decide between a  number of cases n switch ( integer_expression ){ case  value expression case  value expression default:  expression } n The integer expression is evaluated and the thread of execution  starts from the matching case.  If none matches it starts from  the default.

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

View Full Document
switch (weekday){ case 1:  cout << “Monday”; break ; case 2: cout << “Tuesday”; break ; case 3:  cout << “Wednesday”; break ; case 4: cout << “Thursday”; break ; case 5:  cout << “Friday”; break ; default: cout << “Weekend”; } breaks are needed. Otherwise switch drops through to next expression. One more bit of selection: Switch Statements
Using operators to construct  conditional expressions 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 11 12 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

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

View Full Document
Using operators to construct  conditional expressions 1 2 3 4 5 6 7 8 9 10 11 12 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  conditional expressions 1 2 3 4 5 6 7 8 9 10 11 12 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?

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

View Full Document
Using operators to construct  conditional expressions 1 2 3 4 5 6 7 8 9 10 11 12 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  conditional expressions 1 2 3 4 5 6 7 8 9 10 11 12 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; day = day + 1; } This is only true on weekdays

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

View Full Document
Using operators to construct  conditional expressions 1 2 3 4 5 6 7 8 9 10 11 12 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 the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern