we defined, implemented, and tested a class Time. In this lab, we will continue working with the Time class. A. Separate the class definition and class implementation from the client program. Move the class definition into a header file named Time.h and move the class implementation into a cpp file named Time.cpp. Use preprocessor directive to include header files as needed. B. Modify the Time class as follows: 1. Replace the default constructor and overloaded constructor with a constructor with default parameters to initialize year, month, and day. The default value for the hour, minute, and second is 0. (See Classes and Objects slides page 30 for constructor with default parameters.) 2. Add a copy constructor to initialize year, month, and day using a Time object. 3. Add an equals function to compare two Time objects’ values. Return true if they are the same, otherwise, return false. The equals function has a formal parameter which is a Time object. C. In the main function, write statements to test constructors and equals function. D. Add a new text file named lab6data to your project. Copy and paste the following data (representing the hour, minute, and second) into the text file and save the file: 10 20 30 22 33 44 1 2 3 24 30 99 15 56 12 E. In the main function, create an array clocks that can hold 10 Time objects. Read data from the data file and store them into the clocks array. F. In the client program, write a printArray function to print out the contents of an array of Time objects. The function has the following function prototype: void printArray(Time array[], int arraySize); G. In the main function, call the printArray function to output the contents of the clocks array. Answer in c++
#include <iostream>
using namespace std;
class Time {
private:
int hour;
int minute;
int second;
public:
Time() {
hour = 0;
minute = 0;
second = 0;
}
Time(int h, int m, int s) {
hour = h;
minute = m;
second = s;
}
void setTime(int h, int m, int s) {
if (h >=0 && h>23)
{
hour = 0;
}
else {
hour = h;
}
if (m >=0 && m>59)
{
minute =
0;
}
else {
minute =
m;
}
if (s >=0 && s < 59)
{
second =
0;
}
else {
second =
s;
}
}
void print() {
cout << hour << "-"
<< minute << "-" << second << endl;
}
int getHour() {
return hour;
}
int getMinute() {
return minute;
}
int getSecond() {
return second;
}
};
int main()
{
Time getUpTime;
getUpTime.setTime(6, 30, 0);
getUpTime.print();
cout << getUpTime.getMinute() <<
endl;
cout << endl << endl;
Time alarms[5];
alarms[0].setTime(9, 25, 00);
alarms[1].setTime(10, 50, 00);
alarms[2].setTime(12, 15, 00);
alarms[3].setTime(01, 40, 00);
alarms[4].setTime(02, 55, 00);
for (int i = 0; i < 5; i++) {
alarms[i].print();
}
return 0;
}
output of above program all conditions and all operations to added
Get Answers For Free
Most questions answered within 1 hours.