Question
#include using namespace std; // Time class class Time { public: int h1,h2,m1,m2,s1,s2; // default constructor // Two clocks : 12-hour format and // 24-hour
#include
using namespace std;
// Time class
class Time
{
public:
int h1,h2,m1,m2,s1,s2;
// default constructor
// Two clocks : 12-hour format and
// 24-hour format
Time()
{
this->h1 = 12;
this->h2 = 00;
this->m1 = 00;
this->m2 = 00;
this->s1 = 00;
this->s2 = 00;
}
// it check time limit on each action
// i.e. checking second and minute should not exceed 60
void managetime(int t=1)
{
if(t==1)
{
if(s1/60>0)
{
s1 %= 60;
m1++;
}
if(m1/60 > 0)
{
m1 %= 60;
h1++;
}
if(h1/12>0)
{
h1 %= 12;
if(h1==0)
h1=12;
}
}
if(t==2)
{
if(s2/60>0)
{
s2 %= 60;
m2++;
}
if(m2/60 > 0)
{
m2 %= 60;
h2++;
}
if(h2/24>0)
{
h1 %= 24;
}
}
}
// function to add 1 sec
void addSecond()
{
s1++;
s2++;
managetime(1);
managetime(2);
}
// function to wait 1 sec
void waitSecond()
{
s1++;
s2++;
managetime(1);
managetime(2);
}
// function to add 1 min
void addMinute()
{
m1++;
m2++;
managetime(1);
managetime(2);
}
// function to add 1 hour
void addHour()
{
h1++;
h2++;
managetime(1);
managetime(2);
}
// function to display both times
void display()
{
printf(" Time 1: %02d:%02d:%02d ",h1,m1,s1);
printf("Time 2: %02d:%02d:%02d ",h2,m2,s2);
}
};
int main()
{
Time t ;
int p,n,m,f=1;
// Menu as given in flowchart
while(f>0)
{
t.display();
cout<<"Press Button? (1:yes, 2:no): "< cin>>p; if(p==1) { cout<<"Choose option 1. Add Time 2. EXIT Enter 1 or 2: "; cin>>n; if(n==1) { cout<<"Choose option 1. Add 1 hour 2. Add 1 minute 3. Add 1 second Enter 1 or 2 or 3: "; cin>>m; switch(m) { case 1: t.addHour(); break; case 2: t.addMinute(); break; case 3: t.addSecond(); } } if(n==2) { f=-1; } } else if(p==2) { t.addSecond(); t.waitSecond(); } } } Write a function to format numbers as two digits. Get feedback on how well my function works and tips on how to make it better. Write a function that repeats the * to use in formatting your programs output. Get feedback on how well my function works and tips on how to make it better. Write a function that outputs time using 24-hour time format. Get feedback on how well my function works and tips on how to make it better. Write a function that outputs time using 12-hour time format. Get feedback on how well my function works and tips on how to make it better. Write a function that prints out the menu illustrated in the project and functional requirements documentation. Get feedback on how well my function works and tips on how to make it better. Write a function that processes user input from the menu choices in the user interface. Get feedback on how well my function works and tips on how to make it better. Write a function that displays BOTH 12- and 24-hour time formats on the interface at the same time. Get feedback on how well my function works and tips on how to make it better. Write main function (main.cpp) to control your program. The feedback will be limited to the logic in main and not for any input or return values from your functions. It will test to see that all are called the correct number of times. Get feedback on how well my function works and tips on how to make it better. Write a function to add a second to your clocks time. Get feedback on how well my function works and tips on how to make it better. Write a function to add a minute to your clocks time. Get feedback on how well my function works and tips on how to make it better. Write a function to add an hour to your clocks time. Get feedback on how well my function works and tips on how to make it better.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started