Class Characteristics
Examples
True/False
MISC.
Writing Code
100

The two types of data members that a class can have...

What is public and private?

100

Which section is this code:

 double area();

   int perimeter();

    bool right();

    Triangle();

    Triangle(int a);

What is the public section?

100

T/F: A mutator function should always return a value

True

100

True or false - a public member function of  a class can only modify the private data members if it is marked const

False
100

Declare the accessor function for an int data member, grade.

Int get_grade() const

200

The _____ section contains member functions. The ____ section contains data members.

What is public? What is private?

200

Is string an example of a class?

Yes

200

T/F: Accessor functions go last when defining data members.

False.

200

True or false - accessor functions are used to modify private data members of a class

False

200

Write a line of code you would find in the public section and the private section.

Any correct response.

300

Special member function that initializes the data members of an object.

What is a constructor?

300

Do you a need a semicolon at the end of a class definition?

Yes
300

T/F: You have to add const after the parameters after defining an accessor member function.

True.

300

True or false - a const member function cannot change the state of the object it belongs to

True

300

Create an object for this class: 

class Rectangle {

    private: 

        double length;

        double width;

    public: 

        Rectangle();

        Rectangle(double l, double w);

        

        void setLength(double l);

        double getLength() const;

        void setWidth(double w);

        double getWidth() const;

        

        double getArea(double l, double w);

        double getPerimeter(double l, double w);

        bool isSquare(double l, double w);

};

Ms B will check for correctness

400

An instance of a class that encapsulates data and functionality pertaining to that data.

What is an object?

400

In what circumstances can you not write private while defining data members?

When you define it before the public.

400

T/F: All member functions in a class must be declared as public.

False.

400

How many accessor functions will be in a code for a rectangle class with data members, length and width?

What is 2?

400

Create a member function called add_items that adds multiple instances of the same item (say you bought 8 bags of chips) in a class called CashRegister.

void CashRegister:: add_items(int quantity, double price){

    for (int i=1; i<=quantity; i++){

        add_item(price)}

}

500

Hiding the internal details of a class and only exposing a public interface.

What is encapsulation?

500

What does the function do?:

void withdraw(double amount) {

        if (amount > 0 && amount <= balance) {

            balance -= amount;

            cout << "Withdrew $" << amount << ". New balance: $" << balance << endl;

        } else {

            cout << "Invalid withdrawal amount or insufficient funds." << endl;

        }

Withdraws money if the amount in the account is positive and has sufficient funds.

500

T/F: Member functions are defined separately from the class.

True.

500

When implementing a member function outside of the class, what operator do we use

::

500

Put the code in the right order:

1: 

#include "util.h"

#include <cmath>

2:

 public:

    // member functions

    double area();

    int perimeter();

    bool right();

    Triangle();

    Triangle(int a);

3:

private:

    int sideA;

    int sideB;

    int sideC;

4: 

class Triangle{

1, 4, 3, 2

M
e
n
u