Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ PROGRAMMING ALL 3 PARTS YOU NEED ARE BELOW :-) //clockType.h, the specification file for the class clockType class clockType { public: void setTime(int hours,

C++ PROGRAMMING

image text in transcribed

ALL 3 PARTS YOU NEED ARE BELOW :-)

//clockType.h, the specification file for the class clockType class clockType { public: void setTime(int hours, int minutes, int seconds); //Function to set the time. //The time is set according to the parameters. //Postcondition: hr = hours; min = minutes; // sec = seconds; // The function checks whether the // values of hours, minutes, and seconds // are valid. If a value is invalid, the // default value 0 is assigned. void getTime(int& hours, int& minutes, int& seconds) const; //Function to return the time. //Postcondition: hours = hr; minutes = min; // seconds = sec; void printTime() const; //Function to print the time. //Postcondition: The time is printed in the form // hh:mm:ss. void incrementSeconds(); //Function to increment the time by one second. //Postcondition: The time is incremented by one second. // If the before-increment time is // 23:59:59, the time is reset to 00:00:00. void incrementMinutes(); //Function to increment the time by one minute. //Postcondition: The time is incremented by one minute. // If the before-increment time is // 23:59:53, the time is reset to 00:00:53. void incrementHours(); //Function to increment the time by one hour. //Postcondition: The time is incremented by one hour. // If the before-increment time is // 23:45:53, the time is reset to 00:45:53. bool equalTime(const clockType& otherClock) const; //Function to compare the two times. //Postcondition: Returns true if this time is equal to // otherClock; otherwise, returns false. clockType(int hours, int minutes, int seconds); //Constructor with parameters //The time is set according to the parameters. //Postcondition: hr = hours; min = minutes; // sec = seconds; // The constructor checks whether the // values of hours, minutes, and seconds // are valid. If a value is invalid, the // default value 0 is assigned. clockType(); //Default constructor //The time is set to 00:00:00. //Postcondition: hr = 0; min = 0; sec = 0; private: int hr; //variable to store the hours int min; //variable to store the minutes int sec; //variable to store the seconds }; 
//Implementation File for the class clockType #include  #include "clockType.h" using namespace std; void clockType::setTime(int hours, int minutes, int seconds) { if (0  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  
//The user program that uses the class clockType #include  #include "clockType.h" using namespace std; int main() { clockType myClock; clockType yourClock; int hours; int minutes; int seconds; //Set the time of myClock myClock.setTime(5, 4, 30); //Line 1 cout > hours >> minutes >> seconds; //Line 17 cout   Question 1: Chapter 10 defines class clockType to implement time in a program. The class includes functions named "set Time (int hours, int minutes, int seconds)" and "getTime(int& hours, int& minutes, int& seconds) const" in order to set and get clock time, respectively. Modify the class by adding six additional functions (set Hours, setMinutes, setSeconds, getHours, getMinutes, and getSeconds) so that the users can set/get hours, minutes, or seconds separately. Make sure your code provides the same output as follows WIND Current clock (hr: min :sec) 05:04:30 Update hours 06 Current clock (hr:min 06:04 Update minutes 35 Current clock min: sec) 35:30 Update seconds 59 Current clock (hr:min sec): 06:35:59 Press any key to continue

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

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

More Books

Students also viewed these Databases questions