CSCI 240 - Possible Questions for Quiz 11


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

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

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

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

  4. (2 points) The variables within a class are known as __________.

  5. (2 points) setXXXX and getXXXX methods are also known as __________ methods.

  6. (2 points) True or False: Constructors can have any name that you desire.

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

  8. (2 points) 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. (2 points) Call the printTime method for an instance of the Time class named time1.

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