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

Please implement the following problem in basic C++ code and include detailed co

ID: 3589209 • 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.

// clockType

Question: The definition of the class clockType isl given. Think of the class clockType as the base class Derive the class extClockType from the class clockType, by adding a class member variable to store the time zone (int tz) and necessary class member functions to make the class functional. Finally, use the driver program to test your classes Hint: Extending the timezone is only one modification required by the extClockType derived class. Further modifications include Override printTime () function to include the timezone in the output as given output format Overload setTime( ) function to accept the timezone in the parameter list Add the incrementTimeZones () function to add 1 hour to the current time zone. · ° You must not change the code in the driver program, and you should get the same output. Output: C:AWINDOWSlsystem321cmd.exe Following are outputs from the base class clockType! The time is: 10: 23 11 The time is: 2 23: 12 Following are outputs from the derived class extClockType! The time is: 11: 12 13 Time Zone: 10 The time is: 14: 15 16 Time Zone: 20 The time is: 12: 12 13 Time Zone: 11 The time is: 15: 15 16 Time Zone: 21 Press any key to continue . . .

Explanation / Answer

This is a way clear question. The only thing that you need to solve this question is a sequential approach. Just one by one follow the instructions given in the question. Like :-

1. Create derived class

2. Create member function - which are mentioned in question

3. Create member variable - which are mentioned in question

4. Define all of them

Below is the well commented working code; which produces exactly the same output as asked in the question

// clockType
#include<iostream>
#include <string>
#include<iomanip>
using namespace std;

class clockType
{
public:
void setTime(int,int,int);
void getTime(int&,int&,int&)const;
void printTime()const;
void setH(int);
void setM(int);
void setS(int);
int getH()const;
int getM()const;
int getS()const;
void incrementSeconds();
void incrementMinutes();
void incrementHours();
bool equalTime(const clockType& other) const;

private:
int hr;
int min;
int sec;
};
//------------------------ clockType class function implementation

void clockType::setTime(int i, int j, int k){
hr = i;
min = j;
sec = k;
}
void clockType::setH(int h){
hr = h;
}
void clockType::setM(int m){
min = m;
}
void clockType::setS(int s){
sec = s;
}
void clockType::getTime(int& i, int& j, int& k)const{
i = hr;
j = min;
k = sec;
}
int clockType::getH() const{
return hr;
}
int clockType::getM() const{
return min;
}
int clockType::getS() const{
return sec;
}

void clockType::printTime() const{
cout << "The time is: " << hr << " : " << min << " : " << sec << endl;
}

void clockType::incrementHours(){
hr += 1;
}

void clockType::incrementMinutes(){
min += 1;
}

void clockType::incrementSeconds(){
sec += 1;
}


bool clockType::equalTime(const clockType& other) const {
return (hr == other.hr && min == other.min && sec == other.sec);
}
//----------------------------------------------------extClocktype
//Start from here

// Create derived class `extClockType` from base class `clockType`
// Derive it publicly so that all public methods are available in derived
// Because the `hr,min,sec` are private in base class
// we have to access/modify them via base class public functions
class extClockType : public clockType {
public:
// The question asks to override printTime() method.
// That means we have to give this a new definition
void printTime()const;

// The question asks to overload setTime() to cover `timezone`
// So we give it a new set of parameters
void setTime(int i, int j, int k, int timezone);

// This is a new function. For the new class variable `tz`
void incrementTimeZones();


private:
// This variable specifies the timezone
int tz;
};

// Check function definition. The only change is of `timezone`
// Because the hr,min,sec are private in base clas
// we have to access/modify them via base class public functions
void extClockType::setTime(int i, int j, int k, int timezone){
clockType::setH(i);
clockType::setM(j);
clockType::setS(k);
tz = timezone;
}

// Increment `timezone` value by 1
// timezone variable is only in derived class
// So, it will be directly accessed
// And not by any base-class-public-method
void extClockType::incrementTimeZones() {
tz += 1;
}

// Notice that this function is being overrided
// Its function declaration is same as the base class
// But its function definition is different
// That' what is overriding a function
// same signature but different definition
// Again note that the public method of base clas are used to bring value of hr,min,sec.
// becaue those variable are private
void extClockType::printTime() const{
cout << "The time is: " << clockType::getH() << " : " << clockType::getM() << " : " << clockType::getS() << " " << "Time Zone: " << tz << endl;
}


//-----------------------------------Driver Program
int main()
{
clockType c1, c2;
int i = 0, j = 0, k = 0;
c1.setTime(10, 23, 11);
c2.setTime(2, 23, 12);
c1.getTime(i, j, k);
cout << "Following are outputs from the base class clockType! ";
c1.printTime();
c2.printTime();
cout << endl;

extClockType c3, c4;
c3.setTime(11, 12, 13, 10);
c4.setTime(14, 15, 16, 20);
cout << "Following are outputs from the derived class extClockType! ";
c3.printTime();
c4.printTime();
c3.incrementTimeZones();
c4.incrementTimeZones();
c3.incrementHours();
c4.incrementHours();
c3.printTime();
c4.printTime();
cout << endl;
return 0;
}

Please comment if any concerns on the answer