I need help with this in c++ please Write a class for time objects that store th
ID: 664809 • Letter: I
Question
I need help with this in c++ please
Write a class for time objects that store three integer values for hour, minute, and second. Also, write a program to test the functionality of your class. Make sure it does all of the following:
Create time objects with no values (default)
Create time objects with all three values (hours, minutes, seconds)
Create time objects with only hours and minutes
Change hours, minutes, and seconds independently
Change time (all three values)
Display military time
Display standard time
Explanation / Answer
Answer:
class time
{
int minutes;
int seconds;
int hours;
public:
time()
{
hours=0;
minutes=0;
seconds=0;
}
time(int h1,int m1,int s1)
{
hours=h1;
minutes=m1;
seconds=s1;
}
time(int h1,int m1)
{
hours=h1;
minutes=m1;
seconds=0;
}
public void setHours(int h1)
{
hours=h1;
}
public void setMinutes(int m1)
{
minutes=m1;
}
public void setSeconds1(int s1)
{
seconds=s1;
}
public void displayTime()
{
cout<<: Display Time in Military format:";
if(hours>12)
{
cout<<(hours)<<":"<<minutes<<":"<<seconds<< " PM";
}
else
{
cout<<hours<<""<<minutes<<":"<<seconds<<" AM";
}
}
void displayTime2()
{
cout<<"Time in standard format:";
if(hours>12)
{
cout<<(hours-12)<<":"<<minutes<<":"<<seconds<<" PM";
}
else
cout<<hours<<":"<<minutes<<":"<<seconds<<" AM";
}
};
int main()
{
time a_time(12,56,00);
a_time.displayTime();
a_time.displayTime2();
return 0;
}