Use the following class definition to answer questions 810 c

Use the following class definition to answer questions 8-10:

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. An instance of a class is known as a/an __________.

2. A function is to a standard C++ program as a __________ is to an object oriented program.

3. True or False: Items within a class default to public if the keywords public and private are not include within the class definition.

4. The variables within a class are known as __________.

5. setXXXX and getXXXX methods are also known as __________ methods.

6. True or False: Constructors can have any name that you desire.

7. True or False: There can be one and only one constructor within a class definition.

8. 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.

9. Call the printTime method for an instance of the Time class named time1.

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

Solution

Use the following class definition to answer questions 8-10:
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;
};
  
Based on the above code we are answering the questions 8-10

8. 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.
Ans-
   Time time1(10,3,28);//calls the constructor and assign the value hour-10, minute-3, second-28

9. Call the printTime method for an instance of the Time class named time1.
   time1.printTime();//calls the method printTime() for the instance time1

10. Write a single line of C++ code that will display/print only the hour value for an instance of the Time class named time1.
   time1.getHour();// calls the getHour() method using the instance time1 to get the hour value.

//Note: We are not implementing the whole class.feel free to ask any doubt/queries.God bless you!!

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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site