Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Thomas Birt
- COSC 1336
- PA - Elapsed Time
- January 22, 2020
- Program prompts the user to input the elapsed time for an event in seconds stored as an integer. The program then outputs the elapsed time in days, hours, minutes and seconds.
- */
- #include <iostream>
- using namespace std;
- // Write the function PROTOTYPES here for
- // getSeconds, getMinutes, getRemainder, getHours, getDays and displayElapsedTime
- // See the Function Demo Program for examples
- int getSeconds();
- int getMinutes(int);
- int getRemainder(int);
- int getHours(int);
- int getDays(int);
- void displayElapsedTime(int, int, int, int);
- const int SECONDS_PER_MINUTE = 60;
- const int MINUTES_PER_HOUR = 60;
- const int HOURS_PER_DAY = 24;
- int main()
- {
- int seconds; // number of seconds user has entered
- int remainder; // seconds remaining
- int minutes;
- int hours;
- int days;
- // Get the number of seconds to prime loop (or 0 to quit)
- seconds = getSeconds();
- while (seconds != 0) // continue processes while seconds not 0
- {
- minutes = getMinutes(seconds);
- remainder = getRemainder(seconds);
- if (seconds > 60)
- {
- seconds %= SECONDS_PER_MINUTE;
- }
- hours = getHours(minutes);
- if (minutes > 60) {
- minutes %= MINUTES_PER_HOUR;
- }
- days = getDays(hours);
- if (hours > 24) {
- hours %= HOURS_PER_DAY;
- }
- displayElapsedTime(days, hours, minutes, remainder);
- seconds = getSeconds(); // modify loop control variable
- }
- system("pause");
- return 0;
- }
- // Write the function DEFINITIONS here for
- int getSeconds()
- {
- int seconds; // radius value input by user
- cout << "\nEnter the elapsed time in seconds: ";
- cin >> seconds;
- return seconds;
- }
- int getRemainder(int seconds)
- {
- return seconds % SECONDS_PER_MINUTE; // seconds left over from dividing
- }
- int getMinutes(int seconds)
- {
- return seconds / SECONDS_PER_MINUTE; // calculating number of minutes
- }
- int getHours(int minutes)
- {
- // calculating number of hours
- return minutes / MINUTES_PER_HOUR;
- }
- int getDays(int hours)
- {
- return hours / HOURS_PER_DAY; // calculating number of days
- }
- void displayElapsedTime(int days, int hours, int minutes, int remainder)
- {
- cout << "\nThe equivalent time in days hours:minutes:seconds = " << days << " and " << hours << ":" << minutes << ":" << remainder << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement