1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include <iostream>
#include <string>
using namespace std;
void getHours (int &, const string &);
void getMinutes (int &, const string &);
void totalTime (int &, int &, int &, int &);
bool validMinutes (int mins);
bool validHours(int hours);
const int MAX_MINS = 59;
const int MAX_HOURS = 23;
const int MIN_MINS = 0;
const int MIN_HOURS = 0;
int main ()
{
int hours, minutes, addedHours, addedMinutes;
getHours (hours, "Enter number of hours for starting time: ");
getMinutes (minutes, "Enter number of minutes for starting time: ");
getHours (addedHours, "Enter number of hours to be added to starting time: ");
getMinutes (addedMinutes, "Enter number of minutes to be added to starting time: ");
totalTime (hours, minutes, addedHours, addedMinutes);
cout << "The total time is " << hours << " hours and " << minutes << " minutes." << endl;
return 0;
}
void getHours (int &hours, const string &prompt)
{
cout << prompt;
cin >> hours;
}
void getMinutes (int &minutes, const string &prompt)
{
cout << prompt;
cin >> minutes;
}
void totalTime (int &hours, int &minutes, int &addedHours, int &addedMinutes)
{
hours = hours + addedHours;
minutes = minutes +addedMinutes;
}
bool validMins(int mins)
{
if (mins >= MIN_MINS && mins <= MAX_MINS)
return true;
return false;
}
bool validHours(int hours)
{
if (hours >= MIN_HOURS && hours <= MAX_HOURS)
return true;
return false;
}
|