Topical Information
This project will let you prove your mastery of input, functions
(especially reference arguments), and
(hopefully) program design.
Program Information
Write a program that allows the user to enter two times (which are
within the same day). Once you've read their times, then you
should tell the user what the difference of those times is (i.e. tell the
number of hours and minutes [strictly] between the two ...and why not tell
them the number of [whole] minutes between them as well).
Make sure they can enter their times in standard, military (i.e. 24-hour)
format.
As an example, you might have the program interaction look something like
(the parts in this color are typed by the
user):
$ ./time.out
Welcome to the Time Calculation Program!!!
What is your first time? 12:40
What is your second time? 18:24
There are 343 minutes between the two times (345 inclusive).
That's the same as 5 hours and 43 minutes (or 5:45 inclusive).
Oh...and that's also 5.716667 hours (or 5.75 inclusive).
Thank you for using the TCP!!
Endeavor to have a turbulent day!
$ ./time.out
Welcome to the Time Calculation Program!!!
What is your first time? 13:20
What is your second time? 18:24
There are 303 minutes between the two times (305 inclusive).
That's the same as 5 hours and 3 minutes (or 5:05 inclusive).
Oh...and that's also 5.05 hours (or 5.083333 inclusive).
Thank you for using the TCP!!
Endeavor to have an ebullient day!
$
Please notice that the differences displayed are
a) exclusive and b) inclusive.
That is, the first one does not include the times
themselves and the second one includes both of the 'end'
times.
Hint: Create re-usable functions to save yourself effort.
Hint: You'll probably end up with at least 4 functions (including
main; not including options). But having more
than that is NOT a problem!!!
Thought Provoking Questions
- How can you get the '0' to print in front of
times with only one digit (like the 5:05 in the
second run above)? It seems there must be some way to have cout automatically fill this in for us...*ponder*
- How many functions did you write for this program? (I see at
least 4...) Describe each briefly — explain what needs to come
into each function, what it sends back out, and its general purpose.
(Hmm... Pretty much the same things you'll be putting in those function
comments above both of the function's heads...odd, that.)
- How are reference arguments used in this program? (On what function(s)?
How many references on each function?) (And, yes, this means you
need to be using reference arguments!)
- Describe the flow of information in this program. Where does the data
start? Where do variables exist? How is data passed from one function to
another? Where are references made? Where are copies of data made? (See
the notes for
the pertinent example to get a better idea of what 'data flow'
is.)
- How can you get the program to print a random
message at the end of every run?
This assignment is (Level 3.5).
Options
- Add (Level 0.5) to handle when the user
[accidentally] enters their two times in the opposite order. (That is,
they enter the earlier time after they enter the later time.) Do
NOT use a branch for this — a little cmath can go a long way...that's all I'm saying...
Oh, and this piece of code would make an excellent and re-usable function.
(Okay, I'm done nudging now...I swear!)
- Add (Level 1) to add bounds (aka domain value)
and [translation] failure checking to your
time entry function.
Should a failure be detected, the time entry
function should return with cin still in a failed
state.
Should a boundary error be detected, you should place cin into a failed
state and set the appropriate variable to either one less than the minimum
value (if the bounds error was that the user's entry was too small) or one
more than the maximum (if the bounds error was that the user's entry was
too large).
If you do this by [re-]using separate, generic
functions, you may even add an additional
(Level 1).
- Add (Level 1.5) to place all of your time
handling functions in a library.
- Add (Level 1.5) to place all of your input
handling functions in a library. (The time input function would go in the
time library. The generic input functions would go in
here.)
- Add (Level 1.5) to place any generic
math-oriented functions in a library. (Like ones that calculate an
absolute difference between two values...) (Okay, now I swear that's the
last nudge...*wink*)
- Add (Level 1) to adjust for boundary conditions
such as: exclusive = 5:59, inclusive = 5:61. Oops! (Hint: this
might need help from Chapter 3 — although it can be done
purely with integer math.)
- Add (Level 1.5) to allow the user to enter their
times in either 24-hour format or AM/PM time at their discretion.
This AM/PM detection could benefit from another input helper function, of
course — a peeking-ahead facility. Making this a function would be
worth another (Level
0.5). (And it would, of course, go into the input library
if you did that option...)
Total Level Possible
If you did all above options, this lab could be worth as much as (Level 13.5).