Programming using C Also include comments in each step to ex
Programming using C++:
Also include comments in each step to explain what it does.
Question #2: Implementing a class (9 pts) Time class Standard time also know as 12 hour clock (https en.wikipedia.or wiki 12-hour clock) Military time which just shoes the hours and minutes a) Write a declaration for the class Expression including its data members and function members based on the following UML and save it in a file called Time.h Time hour: int minute: int second int Time() set Time(int, int, int): void Seth Hour(int): void setMinute(int): void setMinute(int): void getHouro: int getMinute(): int getSecond0: int printMilitary(): void pintStandard0: void b) Implement the member functions based on the following descriptions, and save them in a file called expression. cpp Time(): is the default constructor. It requires no arguments setTime(): will set the time using the passed arguments. It will use the set methods of each attribute to do so setHour(): will set the hour data member to the passed value if it is greater than or equal to O and less than24, otherwise it will set it to OSolution
----------------- Time.h file -------------------
#ifndef TIME_H
#define TIME_H
class Time{
public:
int hour;
int minute;
int second;
//Constructor
Time();
// Method Declarations
void setTime(int,int,int);
void setHour(int);
void setMinute(int);
void setSecond(int);
int getHour();
int getMinute();
int getSecond();
void printMilitary();
void printStandard();
};
#endif
------------------------------ Time.cpp file ------------------------------
#include <iostream>
#include <string>
#include \"Time.h\"
using namespace std;
Time::Time(void){
hour = 0;
minute = 0;
second = 0;
}
void Time::setTime(int h,int m,int s){
setHour(h);
setMinute(m);
setSecond(s);
}
void Time::setHour(int h){
if(h>=0 && h<=24)
hour = h;
else
hour = 0;
}
void Time::setMinute(int m){
if(m>=0 && m<=60)
minute = m;
else
minute = 0;
}
void Time::setSecond(int s){
if(s>=0 && s<=60)
second = s;
else
second = 0;
}
int Time::getHour(){
return hour;
}
int Time::getMinute(){
return minute;
}
int Time::getSecond(){
return second;
}
void Time::printMilitary(){
cout << \"Your Time in Military format is \";
if(hour<10)
cout<<\"0\";
cout << hour << \":\";
if(minute<10)
cout << \"0\";
cout << minute << endl;
}
void Time::printStandard(){
cout << \"Your Time in Standard format is \";
string ap = \"PM\";
if(hour%12 == 0){
cout << 12 << \":\";
if(hour==0 || hour==24)
ap = \"AM\";
}
else if(hour<12){
cout << hour << \":\";
ap = \"AM\";
}
else{
cout << hour%12 << \":\";
}
if(minute<10)
cout << \"0\";
cout<<minute<< \":\";
if(second<10)
cout<<\"0\";
cout<<second<< \" \" << ap <<endl;
}
----------------------------------------------- Main.cpp file --------------------------------------
#include <iostream>
#include \"Time.h\"
using namespace std;
int main() {
char choice;
cout << \"------------Time Class Tester------------\"<<endl;
do{
cout << \"Enter hh mm sec-->\";
int h,m,s;
cin >> h >> m >> s;
Time t;
t.setTime(h,m,s);
cout << \"Here is how your entered time was processed\"<<endl;
cout << \"Hour \"<< h << \" was set to \" << t.getHour()<<endl;
cout << \"Minute \"<< m << \" was set to \" << t.getMinute()<<endl;
cout << \"Hour \"<< s << \" was set to \" << t.getSecond()<<endl;
t.printMilitary();
t.printStandard();
cout << \"Do you want to enter a new time? (Y or y for yes, any other letter for no):\";
cin >> choice;
}while(choice==\'y\' || choice == \'Y\');
}
/* sample output
------------Time Class Tester------------
Enter hh mm sec--> 12 0 0
Here is how your entered time was processed
Hour 12 was set to 12
Minute 0 was set to 0
Hour 0 was set to 0
Your Time in Military format is 12:00
Your Time in Standard format is 12:00:00 PM
Do you want to enter a new time? (Y or y for yes, any other letter for no): y
Enter hh mm sec--> 24 10 20
Here is how your entered time was processed
Hour 24 was set to 24
Minute 10 was set to 10
Hour 20 was set to 20
Your Time in Military format is 24:10
Your Time in Standard format is 12:10:20 AM
Do you want to enter a new time? (Y or y for yes, any other letter for no): Y
Enter hh mm sec--> 0 65 65
Here is how your entered time was processed
Hour 0 was set to 0
Minute 65 was set to 0
Hour 65 was set to 0
Your Time in Military format is 00:00
Your Time in Standard format is 12:00:00 AM
Do you want to enter a new time? (Y or y for yes, any other letter for no): n
*/


