For C design a class named TimeClock The class should be der
For C++, design a class named TimeClock. The class should be derived from the Time class listed below:
// Specification file for the Time class
class Time
{
protected:
int Hour;
int Min;
int Sec;
public:
Time(int H, int M, int S) //constructor
{ Hour = H; Min = M; Sec = S; }
// Accessors
int GetHour()
{ return Hour; }
int GetMin()
{ return Min; }
int GetSec()
{ return Sec; }
};
. The class should allow the programmer to pass two times to it: starting time and ending time. The class should have a member function that returns the amount of time elapsed between the two times. For example, if the starting time is 900 hours (9:00 am), and the ending time is 1300 hours (1:00 pm), the elapsed time is 4 hours. Input Validation: The class should not accept hours greater than 2359 or less than 0.
Solution
class Time
{
protected:
int Hour; // 1hr= 60min , 3600sec
int Min; // 1min= 60sec
int Sec;
public:
Time(int H, int M, int S) //constructor
{
Hour = H; Min = M; Sec = S; }
// Accessors
int GetHour() // 1-12
{ return Hour; }
int GetMin() // 1-60
{ return Min; }
int GetSec() // 1-60
{ return Sec; }
}; // class end
main()
{
int start_time,end_time;
int hr,min,sec;
int hr1,min1,sec1;
time s1; //s1 obj created
cout<<\"\ enter the start time:\";
cin>>start_time;
//cout<<\"\ enter the end time:\";
//cin>>end_time;
if(start_time>=100&&start_time<=2400)
{
hr=start_time;
if(start_time>=10&&start_time<60)
{
min=start_time;
if(start_time>=0&&start_time<10)
{
sec=start_time;
}
}
cout<<\"\ enter the end time:\";
cin>>end_time;
if(start_time>end_time)
{
break;
}
if(end_time>=100&&end_time<=2400)
{
hr1=start_time;
if(end_time>=10&&end_time<60)
{
min=start_time;
if(end_time>=0&&end_time<10)
{
sec=start_time;
}
}
}

