Need help quickly. Please answer completely. Thank you! C++ only Design and impl
ID: 3792412 • Letter: N
Question
Need help quickly. Please answer completely. Thank you! C++ only
Design and implement the class Clock, a wall-clock with an hour, minute, and second hand. Follow object-oriented practices, and include the following properties: get() and set() functions for each variable, with appropriate checks a non-default constructor that takes the hour as input, and initializes the time an update_second() function, that increases the time by 1 second an overloaded addition operator, resulting in the wall-clock from 2 added Clocks get_angle() function, that returns the smaller angle made by the minute and hour hand. Assume that each hand points exactly to its value on the clockExplanation / Answer
#include <iostream>
using namespace std;
class Time
{
public :
Time();
Time( int hours2,
int minutes2);
int getHours()
const;
int getMinutes()
const;
void setHours( const
int hours2);
void setMinutes(const int minutes2);
Time operator+(const Time &t1) const;
void show() const ;
private :
int hours, minutes;
};
Time::Time()
{
hours = minutes=0;
}
Time::Time( int hours2, int
minutes2)
{
hours = hours2;
minutes = minutes2;
}
int Time::getHours() const
{
return hours;
}
int Time::getMinutes() const
{
return minutes;
}
void Time::setHours( const int
hours2)
{
hours = hours2;
}
void Time::setMinutes( const int
minutes2)
{
minutes = minutes2;
}
Time Time::operator+( const Time &t1) const
{
Time sum;
sum.minutes = minutes + t1.minutes;
sum.hours = hours + t1.hours + sum.minutes/60;
sum.minutes %=60;
return sum;
}
void Time::show() const
{
cout<<hours<< ":" <<minutes<< endl;
}
int main()
{
Time t1;
Time t2;
Time t3;
t1.setHours(2);
t2.setMinutes(25);
t3.show();
t3 = t1 + t2;
t3.show();
system ("pause" );
}