Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ source code include #include using namespace std; class clockType { public: void setTime(int, int, int); void getTime(int &, int &, int &) const; void

C++ source code
include
#include
using namespace std;
class clockType
{
public:
void setTime(int, int, int);
void getTime(int &, int &, int &) const;
void printTime() const;
void incrementSeconds();
void incrementMinutes();
void incrementHours();
bool equalTime(const clockType&) const;
private:
int hr;
int min;
int sec;
};
int main()
{
clockType myClock;
clockType yourClock;
int hours;
int minutes;
int seconds;
myClock.setTime(5, 4, 30);
cout
myClock.printTime();
cout
cout
yourClock.printTime();
cout
yourClock.setTime(5, 45, 16);
cout
yourClock.printTime();
cout
if (myClock.equalTime(yourClock))
cout
else
cout
cout
cin >> hours >> minutes >> seconds;
cout
myClock.setTime(hours, minutes, seconds);
cout
myClock.printTime();
cout
myClock.incrementSeconds();
cout
myClock.printTime();
cout
myClock.getTime(hours, minutes, seconds);
cout
system("PAUSE");
return 0;
}
void clockType::setTime(int hours, int minutes, int seconds)
{
if (0
hr = hours;
else
hr = 0;
if (0
min = minutes;
else
min = 0;
if (0
sec = seconds;
else
sec = 0;
}
void clockType::getTime(int &hours, int &minutes, int &seconds) const
{
hours = hr;
minutes = min;
seconds = sec;
}
void clockType::printTime() const
{
if (hr
cout
cout
if (min
cout
cout
if (sec
cout
cout
}
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();
}
}
bool clockType::equalTime(const clockType& otherClock) const
{
return(hr == otherClock.hr
&&min == otherClock.min
&&sec == otherClock.sec);
}
image text in transcribed
Lab to turn in: Add the following to the function main. (1) Declare two clockType objects big Ben and grandfather where the defau big Ben and the constructor with parameters sets the initial data members of grandfather to the time 14:35:59. (2) Print the times of both objects, with labels telli Increment the time of grandfather by 1 second and print the time for grandfather after the increment. It constructor is used to initialize the data members of s, with labels telling which is which

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

Transactions On Large Scale Data And Knowledge Centered Systems Xxiv Special Issue On Database And Expert Systems Applications Lncs 9510

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Hendrik Decker ,Lenka Lhotska ,Sebastian Link

1st Edition

366249213X, 978-3662492130

More Books

Students also viewed these Databases questions

Question

d. Who are important leaders and heroes of the group?

Answered: 1 week ago