Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use the following class definition to answer the questions class Time { public: Time( int, int, int ); //Initializes a Time object void setHour( int

Use the following class definition to answer the questions

class Time { public: Time( int, int, int ); //Initializes a Time object void setHour( int ); //Set hour data member to a value between 1 and 12 void setMinute( int ); //Set minute data member to a value between 0 and 59 void setSecond( int ); //Set second data member to a value between 0 and 59 int getHour(); //Returns the contents of the hour data member int getMinute(); //Returns the contents of the minute data member int getSecond(); //Returns the contents of the second data member void printTime(); //Prints the contents of a Time object (hour:minute:second) private: int hour, minute, second; }; 

(1) Write the constructor for the Time class. It takes three integer arguments: the potential hour, minute, and second values for the Time object. The constructor should pass the individual arguments to the setHour, setMinute, and setSecond methods to initialize the data members.

(2) Write the setHour method for the Time class. It takes an integer argument that will potentially be used to initialize the hour data member. If the passed in value is not between 1 and 12, inclusive, then initialize the hour data member to 12. Otherwise, use the passed in value to initialize the hour data member.

(3) Write the getSecond method for the Time class. It takes no arguments and returns an integer. This method should simply return the contents of the second data member.

(4) Write the printTime method for the Time class. It takes no arguments and returns nothing. This method should print the time in the format hour:minute:second. For minutes and seconds, if the value is less than 10, display a leading 0.

(5) Create an instance of the Time class called time1. It should have an initial time with the hour value of 10, minute value of 3, and second value of 28.

(6) Call the printTime method for an instance of the Time class named time1.

(7) Write a single line of C++ code that will display/print only the hour value for an instance of the Time class named time1.

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

Managing Your Information How To Design And Create A Textual Database On Your Microcomputer

Authors: Tenopir, Carol, Lundeen, Gerald

1st Edition

1555700233, 9781555700232

More Books

Students also viewed these Databases questions