Kat H.

asked • 03/31/21

Your job is to implement the constructor that takes an hour and minute value. Hint: The constructor is going to need Time:: in front of its name.

Read 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 constructor that takes an hour and minute value. 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(int startHour, int startMinute);


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(15, 31);

t1.print();



Time t2(2, 18);

t2.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


1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.