Please implement the following problem in basic C++ code and include detailed co
ID: 3873656 • Letter: P
Question
Please implement the following problem in basic C++ code and include detailed comments so that I am able to understand the processes for the solution. Thanks in advance.
The class clockType is used to implement time in a program. The class includes functions named "setTime(int hours, int minutes, int seconds)" and “getTime(int& hours, int& minutes, int& seconds) const" in order to set and get clock time, respectively. Modify the class by adding six additional functions (settlours, setMinutes, setSecands getHours, getMinutes, and getSeconds) so that the users can set/get hours, minutes, or seconds separately. Make sure your code provides the same output as follows: C:WINDOWSlsystem321cmd.exe Current clock (hr: min: sec ) : Update hours: 06 5 : 04 : 30 Current clock (hr:min): 06:04 Update minutes: 35 urrent clock (min:sec) 35:3 Update seconds: 59 ock (hr:min:sec): 06:35:59 Current cl Press any key to continue .Explanation / Answer
**.c file
//The user program that uses the class clockType
#include <iostream>
#include "clockType.h"
using namespace std;
int main()
{
clockType myClock;
clockType yourClock;
int hours;
int minutes;
int seconds;
myClock.setTime(5, 4, 30);
cout << "Current clock (hr:min:sec): ";
myClock.printTime();
cout << endl;
cout << "Update hours: ";
cin >> hours;
myClock.setHours(hours);
cout << endl;
cout << "Current clock (hr:min): ";
myClock.printHourMin();
cout << endl;
cout << "Update minutes: ";
cin >> minutes;
myClock.setMinutes(minutes);
cout << endl;
cout << "Current clock (min:sec): ";
myClock.printMinSec();
cout << endl;
cout << "Update seconds: ";
cin >> seconds;
cout << endl;
myClock.setMinutes(seconds);
cout << endl;
cout << "Current clock (hr:min:sec): ";
myClock.printTime();
cout << endl;
return 0;
}
.h file
#include <iostream>
//clockType.h, the specification file for the class clockType
using namespace std;
class clockType
{
public:
void setTime(int hours, int minutes, int seconds);
void setHours(int hours);
void setMinutes(int minutes);
void setSeconds(int seconds);
//Function to set the time.
//The time is set according to the parameters.
//Postcondition: hr = hours; min = minutes;
// sec = seconds;
// The function checks whether the
// values of hours, minutes, and seconds
// are valid. If a value is invalid, the
// default value 0 is assigned.
void getTime(int& hours, int& minutes, int& seconds) const;
void getHourMin(int& hours, int& minutes) const;
void getMinSec(int& minutes, int& seconds) const;
//Function to return the time.
//Postcondition: hours = hr; minutes = min;
// seconds = sec;
void printTime() const;
void printMinSec() const;
void printHourMin() const;
//Function to print the time.
//Postcondition: The time is printed in the form
// hh:mm:ss.
void incrementSeconds();
//Function to increment the time by one second.
//Postcondition: The time is incremented by one second.
// If the before-increment time is
// 23:59:59, the time is reset to 00:00:00.
void incrementMinutes();
//Function to increment the time by one minute.
//Postcondition: The time is incremented by one minute.
// If the before-increment time is
// 23:59:53, the time is reset to 00:00:53.
void incrementHours();
//Function to increment the time by one hour.
//Postcondition: The time is incremented by one hour.
// If the before-increment time is
// 23:45:53, the time is reset to 00:45:53.
bool equalTime(const clockType& otherClock) const;
//Function to compare the two times.
//Postcondition: Returns true if this time is equal to
// otherClock; otherwise, returns false.
clockType(int hours, int minutes, int seconds);
//Constructor with parameters
//The time is set according to the parameters.
//Postcondition: hr = hours; min = minutes;
// sec = seconds;
// The constructor checks whether the
// values of hours, minutes, and seconds
// are valid. If a value is invalid, the
// default value 0 is assigned.
clockType();
//Default constructor
//The time is set to 00:00:00.
//Postcondition: hr = 0; min = 0; sec = 0;
private:
int hr; //variable to store the hours
int min; //variable to store the minutes
int sec; //variable to store the seconds
};
void clockType::setHours(int hours){
hr = hours;
}
void clockType::setMinutes(int minutes){
min = minutes;
}
void clockType::setSeconds(int seconds){
sec = seconds;
}
void clockType::setTime(int hours, int minutes, int seconds)
{
if (0 <= hours && hours < 24)
hr = hours;
else
hr = 0;
if (0 <= minutes && minutes < 60)
min = minutes;
else
min = 0;
if (0 <= seconds && seconds < 60)
sec = seconds;
else
sec = 0;
}
void clockType::getTime(int& hours, int& minutes, int& seconds) const
{
hours = hr;
minutes = min;
seconds = sec;
}
void clockType::getHourMin(int& hours, int& minutes) const
{
hours = hr;
minutes = min;
}
void clockType::getMinSec(int& minutes, int& seconds) const
{
minutes = min;
seconds = sec;
}
void clockType::incrementHours()
{
hr++;
if(hr > 23)
hr = 0;
}
void clockType::incrementMinutes()
{
min++;
if (min > 59)
{
min = 0;
incrementHours();
}
}
void clockType::incrementSeconds()
{
sec++;
if (sec > 59)
{
sec = 0;
incrementMinutes();
}
}
void clockType::printTime() const
{
if (hr < 10)
cout << "0";
cout << hr << ":";
if (min < 10)
cout << "0";
cout << min << ":";
if (sec < 10)
cout << "0";
cout << sec;
}
void clockType::printHourMin() const
{
if (hr < 10)
cout << "0";
cout << hr << ":";
if (min < 10)
cout << "0";
cout << min << ":";
}
void clockType::printMinSec() const
{
if (min < 10)
cout << "0";
cout << min << ":";
if (sec < 10)
cout << "0";
cout << sec;
}
bool clockType::equalTime(const clockType& otherClock) const
{
return (hr == otherClock.hr
&& min == otherClock.min
&& sec == otherClock.sec);
}
clockType::clockType(int hours, int minutes, int seconds)
{
if (0 <= hours && hours < 24)
hr = hours;
else
hr = 0;
if (0 <= minutes && minutes < 60)
min = minutes;
else
min = 0;
if (0 <= seconds && seconds < 60)
sec = seconds;
else
sec = 0;
}
clockType::clockType() //default constructor
{
hr = 0;
min = 0;
sec = 0;
}