In C Design a class named TimeClock The class should be deri
In 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
I really dont understand the use of given Time class. The requirement could be done withut tht class
#include<iostream>
class Time
 {
    protected:
    int Hour;
    int Min;
    int Sec;
    public:
    Time()
    {
        Hour=Min=Sec=0;
    }
    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; }
 };
 class TimeClock:public Time
 {
    private:
        int startTime, endTime;
    public:
        TimeClock(int start, int end)
        {
            Time(10,10,10);
            if(start < 2359 && end < 2359 && start >=0 && end >=0)
            {
                startTime=start;
                endTime=end;
            }
            else
            {
                startTime=0;
                endTime=0;
            }
        }
        void elapsedTime()
        {
            //return endTime-startTime;
            int m1=startTime % 100;
            int h1=startTime / 100;
           
            int m2=endTime % 100;
            int h2=endTime / 100;
           
            int h = abs(h2-h1);
            int m= abs(m2-m1);
            cout <<h<<\" hours and \"<<m<<\" minnutes\";
        }
 };
 int main()
 {
    TimeClock t(900,1100);
   
    t.elapsedTime();
 }


