# lecture2b - Introduction to Computer Programming with...

• Test Prep
• 4

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

Introduction to Computer Programming with MATLAB CEE/MAE M20 Lecture 2b Time and Calendar Calculations CEE/MAE M20 Kim Peek: the real Rain Man 2 CEE/MAE M20 Model Problem I Take input from the console for a start and end time. Then compute the number of hours, minutes, and seconds between the two. 3 Input: Output: Enter start hour: 4 Enter start minute: 23 Enter start second: 12 Enter end hour: 8 Enter end minute: 12 Enter end second: 45 ***** Start Time: 04:23:12 End Time: 08:12:45 There are 3 hours(s), 49 minutes(s), and 33 seconds(s) between the start and end times. >> CEE/MAE M20 Model Problem II Take input from the console for a start and end date. Then compute the number of days between the two dates. 4 Use this to check: Enter start month: 7 Enter start day: 20 Enter start year: 1982 Enter end month: 1 Enter end day: 13 Enter end year: 2015 Total number of days between the two dates is 11865 >> Input: Output: For both model problems, should verify that user input is valid CEE/MAE M20 Calculating difference between two times delta Hour = End hour - Start hour delta Minute = End minute - Start minute delta Second = End second - Start second Is this sufficient? 5 CEE/MAE M20 6 Calculating difference between two times delta Hour = End hour - Start hour delta Minute = End minute - Start minute delta Second = End second - Start second If deltaSecond < 0, Add 60 to delta Second.

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

CEE/MAE M20 7 Calculating difference between two times delta Hour = End hour - Start hour delta Minute = End minute - Start minute delta Second = End second - Start second If deltaSecond < 0, Add 60 to delta Second.
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