Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assume the existence of a Time class with the class specification shown below. D

ID: 3546221 • Letter: A

Question

Assume the existence of a Time class with the class specification shown below.   Define a derived class extendedTime that contains a single additional data member named timeZone (of type string) to hold the time zone (e.g. Eastern Time Zone ETZ, Central Time Zone CTZ, etc) .  The derived class should also have a constructor that accepts two integer parameters and one string parameter which are used to initialize the hour, minutes and timeZone data members (ETZ is the default time zone), a set function name setTime to set the time (hour, minute, and time zone), a function named  getTimeZone that returns the timeZone, and a function named write to display the time on the standard output device in the format   hour:minute  followed by the time zone.

For this question write the specification of the derived class extendedTime.

class Time {

    private:

                int hour;

                int minute;

    public:

                Time(int hr=0, int mn= 0); // initializes hour to hr and minute to mn

                void setTime(int hr. int mn);  // sets the time to hr:mn

                int getHour();  // returns hour

                int getMinute(); // returns minute

                void write(); // displays the time on the standard output device in the format hour:minute.

};

Explanation / Answer

#include<iostream>
#include<string>
using namespace std;

class Time {
private:
int hour;
int minute;
public:
Time(int hr=0, int mn= 0) // initializes hour to hr and minute to mn
{
setTime(hr,mn);
}
void setTime(int hr, int mn) // sets the time to hr:mn
{
hour = hr;
minute = mn;
}
int getHour() // returns hour
{
return hour;
}
int getMinute()// returns minute
{
return minute;
}
void write() // displays the time on the standard output device in the format hour:minute.
{
cout << hour << " : " << minute<< endl;
}
};

class extendedTime:public Time
{
private:
string timeZone;
public:
extendedTime(int hr=0,int mn=0,string zone="ETZ"):Time(hr,mn),timeZone(zone)
{

}
void setTime(int hr,int mn,string Zone)
{
Time::setTime(hr,mn);
timeZone = Zone;
}
string getTimeZone() { return timeZone; }
void write()
{
cout << getHour() << " : " << getMinute() << " " << timeZone << endl;
}
};

int main()
{
Time T1(8,34);
T1.write();
extendedTime ET1(4,23);
ET1.write();
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote