CSc 220 Assignment 1

Assigned
Due

Aug 19
25 pts
Sep 1

This is a simple project mainly for practice running and submitting a C++ program.

Write a program which requests integer numbers of hours, minutes, and seconds, and reports two values:
  • The number of seconds in the period, as an integer value, and
  • The number of hours as a double.
For instance,
[bennet@bennet asst1]$ ./hms Please enter numbers of hours, minutes and seconds. 5 8 22 5 hrs, 8 mins, and 22 secs is 18502 seconds, or 5.13944 hours.
Note that the input values may not be negative, but are not limited otherwise. In particular, input values of zero, and minutes or seconds of 60 or more are allowed.
[bennet@bennet asst1]$ ./hms Please enter numbers of hours, minutes and seconds. 0 100 218 0 hrs, 100 mins, and 218 secs is 6218 seconds, or 1.72722 hours.

Write in C++ and use the file extension .cpp. Your program should be commented. Even something this short at least needs a comment to say what the program does. Commenting is a good habit that you should develop.

There's probably more than one way to do this, but I just added up the total seconds, as the sum of the input seconds, minutes times 60 and hours times 3600, and put that total number seconds into an integer variable. To get the hours, I divided the total seconds by 3600, and made sure to use a floating point (double) division. This can be done with a cast or in other ways.

When your program works and looks nice, submit over the web here.