Question: C++ Modify the Time class(attached) to be able to work with Date class. The Time object should always remain in a consistent state. Correct result

C++ Modify the Time class(attached) to be able to work with Date class. The Time object should always remain in a consistent state. Correct result is in the picture below. Must match desired result.

Modify the Date class(attached) to include a Time class object as a composition, a tick member function that increments the time stored in a Date object by one second, and increaseADay function to increase day, month and year when it is proper. Please use CISP400V8A4.cpp that tests the tick member function in a loop that prints the time in standard format during iteration of the loop to illustrate that the tick member function works correctly. Be aware that we are testing the following cases:

a) Incrementing into the next minute.

b) Incrementing into the next hour.

c) Incrementing into the next day (i.e., 11:59:59 PM to 12:00:00 AM).

d) Incrementing into the next month and next year.

Time class

The Time class has three private integer data members, hour (0 - 23 (24-hour clock format)), minute (0 59), and second (0 59).

It also has Time, setTime, setHour, setMinute, setSecond, getHour(), getMinute, getSecond,~Time, printUniversal, and printStandard public functions.

  1. The Time function is a default constructor. It takes three integers and they all have 0 as default values. It also displays "Time object constructor is called." message and calls printStandard and printUniversal functions.
  2. The setTime function takes three integers but does not return any value. It initializes the private data members (hour, minute and second) data.
  3. The setHour function takes one integer but doesnt return anything. It validates and stores the integer to the hour private data member.
  4. The setMinute function takes one integer but doesnt return anything. It validates and stores the integer to the minute private data member.
  5. The setSecond function takes one integer but doesnt return anything. It validates and stores the integer to the second private data member.
  6. The getHour constant function returns one integer but doesnt take anything. It returns the private data member hours data.
  7. The getMinute constant function returns one integer but doesnt take anything. It returns the private data member minutes data.
  8. The getSecond constant function returns one integer but doesnt take anything. It returns the private data member seconds data.
  9. The Time destructor does not take anything. It displays "Time object destructor is called." message and calls printStandard and printUniversal functions.
  10. The printUniversal constant function does not return or accept anything. It displays time in universal-time format.
  11. The printStandard constant function does not return or accept anything. It displays time in standard-time format.

Date class

The Date class has three private integer data members (month, day and year), one private Time object (time) data member and one static constant integer variable (monthsPerYear).

It has Date, print, increaseADay, tick, and ~Date public functions. It has one private checkDay function.

  1. The Date function is a default constructor. It takes 3 integers and one Time object. The three integers have default data (1, 2, and 1900) and the Time has (0, 0, and 0) as default data. It displays "Date object constructor for date" information when the constructor is called.
  2. The print constant function does not take or return data. It prints out the month day year, hour, minute and second information.
  3. The increaseADay function does not take or return data. It increases the private data member day by one. It also checks the day to make sure the data is accurate. If the data is not accurate it will adjust all the necessary corresponding data.
  4. The tick function does not takes or return data. It increases one second to the Time object of the Date class private data member. This function has to make sure that the second increased is proper or it will adjust all the necessary corresponding data.
  5. The ~Date function is a destructor of the Date class. It also displays "Date object destructor is called "; message and calls Time object destructor.
  6. The constant checkDay function takes and returns an integer. It makes sure the accuracy of day, month, and year information. This utility function to confirm proper day value based on month and year, it also handles leap years, too.

// Date.cpp #include #include #include #include "Date.h" using namespace std;

Date::Date( int mn, int dy, int yr ) { if ( mn > 0 && mn

year = yr; // could validate yr day = checkDay( dy ); // validate the day cout

void Date::print() const { cout

Date::~Date() { cout

unsigned int Date::checkDay( int testDay ) const { static const array daysPerMonth = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

if ( testDay > 0 && testDay

if ( month == 2 && testDay == 29 && ( year % 400 == 0 || ( year % 4 == 0 && year % 100 != 0 ) ) ) return testDay;

throw invalid_argument( "Invalid day for current month and year" ); } // end function checkDay

// Time.cpp #include #include #include #include "Time.h" using namespace std; Time::Time( int hour, int minute, int second ) { setTime( hour, minute, second ); // validate and set time } // end Time constructor void Time::setTime( int h, int m, int s ) { setHour( h ); // set private field hour setMinute( m ); // set private field minute setSecond( s ); // set private field second } // end function setTime void Time::setHour( int h ) { if ( h >= 0 && h = 0 && m = 0 && s

// print Time in universal-time format (HH:MM:SS) void Time::printUniversal() const { cout

// print Time in standard-time format (HH:MM:SS AM or PM) void Time::printStandard() const { cout

Please do not change test program.

// TEST PROGRAM

#include using std::cout; using std::endl;

#include "Time.h" // include Time class definition #include "Date.h" // include Date class definition

#include "Time.h" // include Time class definition #include "Date.h" // include Date class definition

const int MAX_TICKS = 30000;

int main() { Time t(23, 59, 58);// create a time object

Date d(12, 31, 2017, t); // create date object

// output Time object t's values for ( int ticks = 1; ticks

Desired result:

C++ Modify the Time class(attached) to be able to work with Date

23:59:58 11:59:58 PM 23:59:58 23:59:58 Time object constructor is called 11:59:58 PM Date object constructor for date 12/31/2017 Time object destructor is called 11:59:58 PM 12/31/2017 11:59:58 PM 23:59:58 12/31/2017 11:59:59 PM 23:59:59 day (32) set to 1. 1/1/2018 12:00:00 AM 00:00:00 1/1/2018 12:00:01 AM 00:00:01 1/1/2018 12:00:02 AM 00:00:02 1/1/2018 12:00:03 AM 00:00:03 1/1/2018 12:00:04 AM 00:00:04 1/1/2018 12:00:05 AM 00:00:05 1/1/2018 12:00:06 AM 00:00:06 1/1/2018 12:00:07 AM 00:00:07 1/1/2018 12:00:08 AM 00:00:08 1/1/2018 12:00:09 AM 00:00:09 1/1/2018 12:00:10 AM ee:e0:10 1/1/2018 12:00:11 AM 00:00:11 1/1/2018 12:00:12 AM 00:00:12 1/1/2018 12:00:13 AM 00:00:13 1/1/2018 12:00:14 AM 00:00:14 1/1/2018 12:00:15 AM 00:00:15 1/1/2018 12:00:16 AM 00:00:16 1/1/2018 12:00:17 AM 00:00:17 1/1/2018 12:00:18 AM 00:00:18 1/1/2018 12:00:19 AM 00:00:19 1/1/2018 12:00:20 AM 00:00:20 1/1/2018 12:00:21 AM 00:00:21 1/1/2018 12:00:22 AM 00:00:22 21/1/2018 12:00:23 AM 00:00:23

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!