
Patrick B. answered 04/01/21
Math and computer tutor/teacher
Time::Time()
{
hour=minute=0;
}
Kat H.
asked 04/01/21Read the existing code for Time. It stores a time of day in 24 hour format with 0 hours indicating midnight and 12 hours indicating noon.
Your job is to implement the default (no argument) constructor that sets time to midnight. Hint: The constructor is going to need Time:: in front of its name.
Code:
#include <iostream>
#include <iomanip>
using namespace std;
class Time {
private:
int hour;
int minute;
public:
Time();
void print() {
int twelveHour = hour % 12;
if(twelveHour == 0)
twelveHour = 12;
cout << setfill('0'); //pad with 0's
cout << twelveHour << ":" << setw(2) << minute << " ";
if(hour >= 12)
cout << "PM" << endl;
else
cout << "AM" << endl;
}
};
int main()
{
Time t1;
t1.print();
}
//Do not modify anything on or above the line below this
//YOUR_CODE_BELOW
//YOUR_CODE
//YOUR_CODE_ABOVE
//Do not modify anything on or below the line above this
Patrick B. answered 04/01/21
Math and computer tutor/teacher
Time::Time()
{
hour=minute=0;
}
Get a free answer to a quick problem.
Most questions answered within 4 hours.
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.