Question
NEED HELP!!!!!! Modify the Time class of (attached) to work with Date class, Date time class and employee class. The Time object should always remain
NEED HELP!!!!!!
Modify the Time class of (attached) to work with Date class, Date time class and employee class. The Time object should always remain in a consistent state.
Modify the Date and Employee class (attached) to work with other class in the assignment.
Create DateTime class that includes a Time class object 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.
In the CISP400V10AD4.cpp, we instantiate three Employee objects and assign them to the first three elements of a 10 element Employee pointer array. Use for loop to print out the each Employee objects information before and after a set of training time.
The following is a description of each class.
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, and printStandard public functions.
The Time function is a default constructor. It takes three integers and each has default value of 23, 59, and 58.
The setTime function takes three integers but does not return any value. It initializes the private data members (hour, minute and second) data.
The setHour function takes one integer but doesnt return anything. It validates and stores the integer to the hour private data member.
The setMinute function takes one integer but doesnt return anything. It validates and stores the integer to the minute private data member.
The setSecond function takes one integer but doesnt return anything. It validates and stores the integer to the second private data member.
The getHour constant function returns one integer but doesnt take anything. It returns the private data member hours data.
The getMinute constant function returns one integer but doesnt take anything. It returns the private data member minutes data.
The getSecond constant function returns one integer but doesnt take anything. It returns the private data member seconds data.
The Time destructor does not take anything.
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), and one static constant integer variable (monthsPerYear).
It has Date, print, ~Date, setMonth, setYear, and setDay public functions. It has one private checkDay function.
The Date function is a default constructor. It takes 3 integers. The three integers have default data (1, 1, 1900).
The print constant function does not take or return data. It prints out the month, day and year information.
The ~Date function is a destructor of the Date class. It also displays "Date object destructor is called "; message and calls Time object destructor.
The setDay function takes an integer and does not return anything. It validates the day information by calling checkDay function and saves the validated information.
The setMonth function takes an integer and does not return anything. It validates the month information and saves the validated information.
The setYear function takes an integer and does not return anything. It validates the year information and saves the validated information. If year greater than 2020 or less than 1920 displays invalid year and set to 2011 information i
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.
DateTime class
The DateTime class has three private integer data members (month, day and year), one Time class object (time) and one static constant integer variable (monthsPerYear).
It has DateTime, print, increaseADay, tick, getMonth, getYear, getDay, setMonth, setYear, setDay, getHour, getMinute, getSecond, setHour, setMinute, setSecond, and ~DateTime public functions. It has one private checkDay function.
The DateTime function is a default constructor. It takes 3 integers and a Time object information. The three integers have default data of 0, 0, and 0. The Time object also has 0, 0, and 0 as default data.
The print constant function does not take or return data. It prints out the month, day, year and Time object information.
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.
The tick function does not takes or return data. It increases one second to the Time object of the DateTime 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.
The getMonth function returns an integer but does not take anything. It returns the month private data member.
The getYear function returns an integer but does not take anything. It returns the year private data member.
The getDay function returns an integer but does not take anything. It returns the day private data member.
The setDay function takes an integer and does not return anything. It validates the day information by calling checkDay function and saves the validated information.
The setMonth function takes an integer and does not return anything. It validates the month information and saves the validated information.
The setYear function takes an integer and does not return anything. It validates the year information and saves the validated information. If year greater than 2020 or less than 1920 displays invalid year and set to 2011 information i
The getHour function returns an integer but does not take anything. It returns the hour information of the Time object (time) private data member.
The getMinute function returns an integer but does not take anything. It returns the minute information of the Time object (time) private data member.
The getSecond function returns an integer but does not take anything. It returns the second information of the Time object (time) private data member.
The setHour function takes an integer but does not return anything. It validates the integer and set the validated information to hour component of the Time object (time) private data member.
The setMinute function takes an integer but does not return anything. It validates the integer and set the validated information to minute component of the Time object (time) private data member.
The setSecond function takes an integer but does not return anything. It validates the integer and set the validated information to the second component of theTime object (time) private data member.
The ~DateTime function is a destructor of the DateTime class.
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.
The Employee class has two private string data members (firstName and lastName), two private Date objects (hireDate and birthDate), two private DateTime objects (startDateTime and endDateTime), and one private static integer (count). The count is used to count the existence of Employee object.
It has Employee, getFirstName, getLastName, gethireDate, getbirthDate, getstartDateTime, getendDateTime, testZeroDateTime, setendDateTime, print, ~Employee, and getCount public functions.
The Employee function is a default constructor. It takes 2 strings, two Date objects, and two DateTime objects information.
The getFirstName function returns a string but does not take any data. It returns the private data member firstName information.
The getLastName function returns a string but does not take any data. It returns the private data member lastName information.
The gethireDate function does not take or returns any data. It displays the private data member Date object hireDate information.
The getbirthDate function does not take or returns any data. It displays the private data member Date object birthDate information.
The getstartDateTime function does not take or returns any data. It displays the private data member DateTime object startDateTime information.
The getendDateTime function does not take or returns any data. It displays the private data member DateTime object endDateTime information.
The testZeroDateTime function takes a DateTime object and returns a Boolean data. It testes the passed in DataTime object whether the object contains all 0s in its data members. If yes than return true otherwise return false.
The setendDateTime function takes three integers (hour, minute and second) but does not return anything. It takes the integers of training time needed for each employee to update the endDateTime objects data members.
The print function does not take or return any data. It displays an Empolyee objects information. It shows employees first name last name, birth date, hire date, Training starts at, and Training ends at. If there is not training time set yet then displays No specified end training date and time.
The ~Employee is the destructor of the class.
The getCount static function does not take any data but return an integer. It returns the number of existence of the Employee class objects.
The Code that was given was:
Date.h:
//Date.h // Date class definition; Member functions defined in Date.cpp #ifndef DATE_H #define DATE_H
class Date { public: static const unsigned int monthsPerYear = 12; // months in a year explicit Date(int = 1, int = 1, int = 1900); // default constructor void print() const; // print date in month/day/year format ~Date(); // provided to confirm destruction order private: unsigned int month; // 1-12 (January-December) unsigned int day; // 1-31 based on month unsigned int year; // any year
// utility function to check if day is proper for month and year unsigned int checkDay(int) const; }; // end class Date
#endif
Employee.h:
// Employee.h // Employee class definition showing composition. // Member functions defined in Employee.cpp. #ifndef EMPLOYEE_H #define EMPLOYEE_H
#include
class Employee { public: Employee(const std::string &, const std::string &, const Date &, const Date &); void print() const; ~Employee(); // provided to confirm destruction order private: std::string firstName; // composition: member object std::string lastName; // composition: member object const Date birthDate; // composition: member object const Date hireDate; // composition: member object }; // end class Employee
#endif
Time.h:
// Time.h // Time class containing a constructor with default arguments. // Member functions defined in Time.cpp.
// prevent multiple inclusions of header #ifndef TIME_H #define TIME_H
// Time class definition class Time { public: explicit Time(int = 0, int = 0, int = 0); // default constructor
// set functions void setTime(int, int, int); // set hour, minute, second void setHour(int); // set hour (after validation) void setMinute(int); // set minute (after validation) void setSecond(int); // set second (after validation)
// get functions unsigned int getHour() const; // return hour unsigned int getMinute() const; // return minute unsigned int getSecond() const; // return second
void printUniversal() const; // output time in universal-time format void printStandard() const; // output time in standard-time format private: unsigned int hour; // 0 - 23 (24-hour clock format) unsigned int minute; // 0 - 59 unsigned int second; // 0 - 59 }; // end class Time
#endif
Date.cpp:
// Date.cpp // Date class member-function definitions. #include
// constructor confirms proper value for month; calls // utility function checkDay to confirm proper value for day Date::Date(int mn, int dy, int yr) { if (mn > 0 && mn <= monthsPerYear) // validate the month month = mn; else throw invalid_argument("month must be 1-12");
year = yr; // could validate yr day = checkDay(dy); // validate the day
// output Date object to show when its constructor is called cout << "Date object constructor for date "; print(); cout << endl; } // end Date constructor
// print Date object in form month/day/year void Date::print() const { cout << month << '/' << day << '/' << year; } // end function print
// output Date object to show when its destructor is called Date::~Date() { cout << "Date object destructor for date "; print(); cout << endl; } // end ~Date destructor
// utility function to confirm proper day value based on // month and year; handles leap years, too unsigned int Date::checkDay(int testDay) const { static const array< int, monthsPerYear + 1 > daysPerMonth = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
// determine whether testDay is valid for specified month if (testDay > 0 && testDay <= daysPerMonth[month]) return testDay;
// February 29 check for leap year 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
Employee.cpp:
// Employee.cpp // Employee class member-function definitions. #include
// constructoar uses member initializer list to pass initializer // values to constructors of member objects Employee::Employee(const string &first, const string &last, const Date &dateOfBirth, const Date &dateOfHire) : firstName(first), // initialize firstName lastName(last), // initialize lastName birthDate(dateOfBirth), // initialize birthDate hireDate(dateOfHire) // initialize hireDate { // output Employee object to show when constructor is called cout << "Employee object constructor: " << firstName << ' ' << lastName << endl; } // end Employee constructor
// print Employee object void Employee::print() const { cout << lastName << ", " << firstName << " Hired: "; hireDate.print(); cout << " Birthday: "; birthDate.print(); cout << endl; } // end function print
// output Employee object to show when its destructor is called Employee::~Employee() { cout << "Employee object destructor: " << lastName << ", " << firstName << endl; } // end ~Employee destructor
Time.cpp:
// Time.cpp // Member-function definitions for class Time. #include
// Time constructor initializes each data member Time::Time(int hour, int minute, int second) { setTime(hour, minute, second); // validate and set time } // end Time constructor
// set new Time value using universal time 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
// set hour value void Time::setHour(int h) { if (h >= 0 && h < 24) hour = h; else throw invalid_argument("hour must be 0-23"); } // end function setHour
// set minute value void Time::setMinute(int m) { if (m >= 0 && m < 60) minute = m; else throw invalid_argument("minute must be 0-59"); } // end function setMinute
// set second value void Time::setSecond(int s) { if (s >= 0 && s < 60) second = s; else throw invalid_argument("second must be 0-59"); } // end function setSecond
// return hour value unsigned int Time::getHour() const { return hour; } // end function getHour
// return minute value unsigned int Time::getMinute() const { return minute; } // end function getMinute
// return second value unsigned int Time::getSecond() const { return second; } // end function getSecond
// print Time in universal-time format (HH:MM:SS) void Time::printUniversal() const { cout << setfill('0') << setw(2) << getHour() << ":" << setw(2) << getMinute() << ":" << setw(2) << getSecond(); } // end function printUniversal
// print Time in standard-time format (HH:MM:SS AM or PM) void Time::printStandard() const { cout << ((getHour() == 0 || getHour() == 12) ? 12 : getHour() % 12) << ":" << setfill('0') << setw(2) << getMinute() << ":" << setw(2) << getSecond() << (hour < 12 ? " AM" : " PM"); } // end function printStandard
cisp.cpp
// CISP400V10AD4.cpp // static data member tracking the number of objects of a class. #include
int main() { Employee *ers[10]; // no objects exist; use class name and binary scope resolution // operator to access static member function getCount cout << "Number of employees before instantiation of any objects is " << Employee::getCount() << endl; // use class name
// the following scope creates and destroys // Employee objects before main terminates {Date hd1(2, 30, 2013), hd2(4, 31, 2014), hd3(9, 31, 2012), bd1(2, 29, 1985), bd2(11, 30, 1988), bd3(6, 14, 19830); Time st1(23, 10, 30), st2(11, 11, 59), st3(0, 70, 70), zt(0, 0, 0); DateTime DTst1(10, 9, 2016, st1), DTst2(12, 25, 2017, st2), DTst3(2, 28, 2016, st3), DTet1(0, 0, 0, zt), DTet2(0, 0, 0, zt), DTet3(0, 0, 0, zt); Employee e1("Susan", "Baker", hd1, bd1, DTst1, DTet1); Employee e2("Robert", "Jones", hd2, bd2, DTst2, DTet2); Employee e3("John", "Lin", hd3, bd3, DTst3, DTet3); // three objects exist; call static member function getCount again // using the class name and the binary scope resolution operator cout << "Number of employees after objects are instantiated is " << Employee::getCount(); //assignment Employee objects to Employee pointer array ers[0] = &e1; ers[1] = &e2; ers[2] = &e3; //usinjg for loop to call print function for (int i = 0; i<3; i++) ers[i]->print(); //provid training time needed for each employee in hours, minutes and seconds formate e1.setendDateTime(155, 34, 20); e2.setendDateTime(333, 22, 59); e3.setendDateTime(564, 0, 0); //using for loop to call print function to display the object data for (int i = 0; i<3; i++) ers[i]->print();
} // end nested scope in main
// no objects exist, so call static member function getCount again // using the class name and the binary scope resolution operator cout << " Number of employees after objects are deleted is " << Employee::getCount() << endl;
system("PAUSE"); } // end main
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started