Constructors & Classes
Public Interface
Data Members
Member Functions
OOP
100

What is the definition of a class?

A blueprint that describes a set of objects with the same behavior.

100

True or false: You put data members in the public interface.

False: You want to protect the data members in the private interface.

100

Where are variables declared?

Private section

100

Which is constant, a mutator or an accessor?

An accessor 

100

What class would Phoebe and Chives (Mrs. Diaz's pets) belong to?

a) Dog

b) getName();

c) Cat

d) int age;

c) Cat

200

True or false: The name of the constructor can be anything

False: Has to have the same name as the class

200

What are other names for mutators and accessors?

Mutators: setters

Accessors: getters

200

True or false: Each object has a separate copy of the data members. 

True

200

Which syntax is correct?

a) void Clock. reset()

b) void Clock: reset();

c) void Clock:: reset()

d) void Clock:: reset();

d) void Clock:: reset();

200

What does OOP stand for?

Object Oriented Programming

300

What is encapsulation?

The process of providing a public interface while hiding implementation details. 

300

What are the mutator and accessor in the given member functions?

double get_total() const;

void set_total();

void print_welcome();

Accessor: double get_total() const;

Mutator: void set_total();

300

Why are data members private?

To protect the state of the data members.

300

True or False: You can call member functions within member functions.

True

300

Which of the following is an attribute of Clock class?

a) Hour

b) Move hand

c) Reset clock

d) Page count

a) Hour

400

A constructor is a special ______ function that initializes the _____  ________ of an object.

member; data members

400

Spot and correct ALL mistakes:

class Clock{

public:

     void set_hours() const;

     void set_minutes() const;

     void set_seconds(int s);

private:

      int hours;

      int seconds;

      int minutes;

}

voids cannot be constants:

void set_hours (int h);

void set_minutes(int m);

Missing semicolon after }




400

What does const do?

States that the member variables will not change

400

Which is the implicit and explicit parameter?

person.set_age(13);

Implicit: person

Explicit: 13

400

Where have we seen Object Oriented Programming before the introduction of classes?

In string objects, cin, and cout

500

What is wrong with this program?

class Box

{

    //code

};

Box(int length, double width)

{//code};

Box(int length, double width)
{//code};

You cannot have two constructors with the same number, type, and order of parameters.

500

What is the difference between a class and a structure?

A class by default has an interface with public and private section while a structure does not.

500

Find the error:

class Cat

{

    private:

       void set_age();

       int get_age() const;

    public:

       int age;

       double height;

};


Switch the private and public section.

500

Order the following code segments:


a) 

int main()

{

      Cat chives;

      chives.climb();

}


b)

#include "util.h"


c) 

class Cat

{

     public:

          void climb();

     private:

           int age;

};


d)

void Cat::climb()

{

   cout << "Keep climbing!" << endl;

}




b, c, d, a

500

For a Cat class, what are two functions that could be used in the public interface?

meow();

purr();

walk();

scratch();

etc, more behaviors...