Classes
Data Members
Member Functions
Constructors
Miscellaneous
100

What is a class?

a set of objects with the same behavior

100

What analogy is used to show how objects of a class can all have their data members set to different values?

Clock analogy

100

Member functions are ________separately, _______ the class definition

defined, after

100

What does a constructor do? 

Initializes the data members of an object 


100

What is object-oriented programming?

Programming style in which tasks are solved by collaborating objects


200

What is stored in the private interface?

Data members

200

In a class named CashRegister, does CashRegister object has a separate copy of each data member true or false?

True

200

The definition of a class declares its member function where?

In the public interface

200

How are constructors named?

Same name as the class.

200

How many constructors can a class have?

Multiple!

300

What is stored in the public interface?

Member functions

300

What are the two sections within the class definition? What goes inside each section?

The Data Members section contains variables that define the object's state or characteristics. The Member Functions section contains methods that define the object's behavior and how it interacts with its data.

300

Where are member functions implemented?

Outside the class definition, using the : : operator.

300

Where are constructors declared and defined?

Declared inside the class definition; defined after the class.

300

What is encapsulation? 

Common programming practice of making data members private so they cannot be changed directly by the user.

400

What does const do to a member function?

The data members in the function cannot be modified. 


400

When defining data members, what are the steps?

  • need to decide which data each object needs to store,

  • Go through all member functions and consider their requirements 

  • Start with your accessor functions

  • DEFINE!! 

400

If you are given a class called Book, how would you correctly define a member function called open_book() outside the class?

Void Car::open_book() { cout << “Book opened!”; }


400

Are constructors declared as void?

No, but they don't return a value.

400

What type of member function, often starting with the word "get," is used to return the value of a private data member without changing it?

Accessor Function

500

In C++, what is the difference between an Object and a Class?

A class is the blueprint, while an object is the actual entity created in memory based on that blueprint.

500

Where are data members defined, and give an example using this template using variables total_price and item_count specifically?

private:

    int item_count;

    double total_price;

};

500

Detect the error:

#include <iostream>
using namespace std;

class Student {
    public:
        void setName(string n);
        void display();
};

void setName(string n) {
    name = n;
}

void Student::display() {
    cout << "Student Name: " << name << endl;
}

int main() {
    Student s1;
    s1.setName("Alice");
    s1.display();
    return 0;
}

 Private: {string name;}; &  void student:: SetName(string n) {name = n;}

500

What is a default constructor?

A constructor with no parameters.

500

How many parameters do default constructors have?

0!

M
e
n
u