Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/ / clockType . h , the specification file for the class clockType #ifndef H _ ClockType #define H _ ClockType class clockType { public:

//clockType.h, the specification file for the class clockType
#ifndef H_ClockType
#define H_ClockType
class clockType
{
public:
void setTime(int hours, int minutes, int seconds);
void getTime(int& hours, int& minutes, int& seconds) const;
void printTime() const;
void incrementSeconds();
void incrementMinutes();
void incrementHours();
bool equalTime(const clockType& otherClock) const;
clockType(int hours, int minutes, int seconds);
d clockType();
private:
int hr; //variable to store the hours
int min; //variable to store the minutes
int sec; //variable to store the seconds
};
#endif
//Implementation File for the class clockType
#include
#include "clockType.h"
using namespace std;
void clockType::setTime(int hours, int minutes, int seconds)
{
if (0<= hours && hours <24)
hr = hours;
else
hr =0;
if (0<= minutes && minutes <60)
min = minutes;
else
min =0;
if (0<= seconds && seconds <60)
sec = seconds;
else
sec =0;
}
void clockType::getTime(int& hours, int& minutes,
int& seconds) const
{
hours = hr;
minutes = min;
seconds = sec;
}
void clockType::incrementHours()
{
hr++;
if (hr >23)
hr =0;
}
void clockType::incrementMinutes()
{
min++;
if (min >59)
{
min =0;
incrementHours();
}
}
void clockType::incrementSeconds()
{
sec++;
if (sec >59)
{
sec =0;
incrementMinutes();
}
}
void clockType::printTime() const
{
if (hr <10)
cout <<"0";
cout << hr <<":";
if (min <10)
cout <<"0";
cout << min <<":";
if (sec <10)
cout <<"0";
cout << sec;
}
bool clockType::equalTime(const clockType & otherClock) const
{
return (hr == otherClock.hr
&& min == otherClock.min
&& sec == otherClock.sec);
}
clockType::clockType(int hours, int minutes, int seconds)
{
if (0<= hours && hours <24)
hr = hours;
else
hr =0;
if (0<= minutes && minutes <60)
min = minutes;
else
min =0;
if (0<= seconds && seconds <60)
sec = seconds;
else
sec =0;
}
clockType::clockType()//default constructor
{
hr =0;
min =0;
sec =0;
}In Chapter 1, the class clockType was designed to implement the time of day in a program. Certain
applications, in addition to hours, minutes, and seconds, might require you to store the time zone. By
using the files provided (clockType.h and clockTypeImp.cpp), derive the class extClockType from the
class clockType by adding a member variable to store the time zone. Override a member function
printTime and add constructors to make the derived class functional. Finally, test your program by
setting the time to 5: 10: 15(CST) and output it on the console.
Submit a header file consisting of the derived class declaration, a cpp file which include member function
definitions of the derived class, and another cpp file which includes the main function. Copy and paste the
screenshot of the output here

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions