We will create a clock program in this exercise. You will define clock time valu
ID: 3621140 • Letter: W
Question
We will create a clock program in this exercise. You will define clock time values using int data types:int hour, minute, second;
You will initialize both the clocks as 12:00:00 in the beginning. Then you will display a menu like this:
Enter from one of the following options:
1 Set clock
2 Print clock
3 Increment hour
4 Increment minute
5 Increment second
6 Exit
? Set clock option will allow user to set new values of hour, minute and second.
? Print clock option will display the time.
? Increment hour option will increment hour value by 1.
? Increment minute option will increment minute value by 1.
? Increment second option will increment second value by 1.
? Exit will allow user to exit from the program.
You will keep running this program until user selects the Exit option. You have to implement the following:
1. When clock is being set, you have to make sure that user enters only valid value for hour, minute and second.
Valid values are: hour: 0-23, minutes: 0-59, second: 0-59
2. Clock display time in HH:MM:SS format. If any of these three values are less than 10, display a zero before the value.
3. When you increment hour and the value of hour becomes 24, it should be reset to 0.
4. When you increment minute and the value of minute becomes 60, it should be reset to 0 and value of hour should be incremented by 1.
5. When you increment second and the value of second becomes 60, it should be reset to 0 and value of minute should be incremented by 1. If after this increment value of
minute becomes 60, it should be reset to 0 and value of hour should be incremented by 1. If after this increment value of hour becomes 24, it should be reset to 0.
Check your program for the following wrong input values:
1. Hour: -13, 24, 45
2. Minute: -19, 60, 123
3. Second: -34, 60, 98
When the above values are entered program should keep asking input from the user, as these values are incorrect.
Validate your program using the following input values:
1. Set your clock to 01:12:26. After incrementing hour, Output should be 02:12:26.
2. Set your clock to 23:34:43. After incrementing hour, Output should be 00:34:43.
3. Set your clock to 00:59:34. After incrementing minute, Output should be 01:00:34.
4. Set your clock to 15:23:37. After incrementing minute, Output should be 15:24:37.
5. Set your clock to 12:34:59. After incrementing second, Output should be 12:35:00.
6. Set your clock to 12:59:59. After incrementing second, Output should be 13:00:00.
7. Set your clock to 00:59:59. After incrementing second, Output should be 01:00:00.
Sample Code Given to Get Started
#include <iostream>
/* Sample code for Group Assignment-1 */
using namespace std;
int main()
{
int hour=12, minute=0, second=0, choice;
bool flag = false;
while ( !flag )
{
cout << " Enter from one of the following options:";
cout <<" 1 Set clock";
cout <<" 2 Print clock";
cout <<" 3 Increment hour";
cout <<" 4 Increment minute";
cout <<" 5 Increment second";
cout <<" 6 Exit";
cout <<" Selected option:";
cin >> choice;
switch( choice) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6: flag = true;
break;
default: cout << " Please try again:";
break;
}
}
system("pause");
return 0;
}
Explanation / Answer
#include using namespace std; int main() { int hour = 12, minute = 0, second = 0, choice,inc_hrs,inc_min,inc_sec,hr, min,sec; bool flag = false; while ( !flag ) { coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.