7. Predicates and Loops

7. Predicates and Loops - ENGR 101 Sec. 100 Fall 10...

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

View Full Document Right Arrow Icon
ENGR 101 Sec. 100 Fall 10 Prof. M. Wellman 1 Predicates and Loops ENGR 101, Lecture 7: 29 Sep 10 Announcements Project 3 due Wed 9PM (29 Sep) Exam #1 Tue 5 Oct sample exams available this weekend take practice “gateway” exam for participation credit review session: Monday lecture
Background image of page 1

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

View Full DocumentRight Arrow Icon
ENGR 101 Sec. 100 Fall 10 Prof. M. Wellman 2 How Many Hours Left to Work? int workHoursLeft(int date, int dueDate, int firstDay) // calculates # work hours before project is due, // given month started on firstDay { int hours = 0; while (date <= dueDate) { if ( date is not a weekend day ) hours += 10; date++; } return hours; } 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 21 22 23 24 25 26 27 28 29 30 31 1 2 3 4 5 6 0 What Day is date ? (firstDay – 1 + date) % 7 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 21 22 23 24 25 26 27 28 29 30 31 firstDay is 3 1 2 3 4 5 6 0
Background image of page 2
ENGR 101 Sec. 100 Fall 10 Prof. M. Wellman 3 Testing for the Weekend bool weekendDay(int date, int firstDay) // true if date falls on the weekend, // given that month started on firstDay { int day; day = (firstDay – 1 + date) % 7; return (day == 0 or day == 1); } 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 21 22 23 24 25 26 27 28 29 30 31 1 2 3 4 5 6 0 How Many Hours Left to Work?
Background image of page 3

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

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

Page1 / 9

7. Predicates and Loops - ENGR 101 Sec. 100 Fall 10...

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

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