The two types of data members that a class can have...
What is public and private?
Which section is this code:
double area();
int perimeter();
bool right();
Triangle();
Triangle(int a);
What is the public section?
T/F: A mutator function should always return a value
True
True or false - a public member function of a class can only modify the private data members if it is marked const
Declare the accessor function for an int data member, grade.
Int get_grade() const
The _____ section contains member functions. The ____ section contains data members.
What is public? What is private?
Is string an example of a class?
Yes
T/F: Accessor functions go last when defining data members.
False.
True or false - accessor functions are used to modify private data members of a class
False
Write a line of code you would find in the public section and the private section.
Any correct response.
Special member function that initializes the data members of an object.
What is a constructor?
Do you a need a semicolon at the end of a class definition?
T/F: You have to add const after the parameters after defining an accessor member function.
True.
True or false - a const member function cannot change the state of the object it belongs to
True
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
An instance of a class that encapsulates data and functionality pertaining to that data.
What is an object?
In what circumstances can you not write private while defining data members?
When you define it before the public.
T/F: All member functions in a class must be declared as public.
False.
How many accessor functions will be in a code for a rectangle class with data members, length and width?
What is 2?
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)}
}
Hiding the internal details of a class and only exposing a public interface.
What is encapsulation?
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.
T/F: Member functions are defined separately from the class.
True.
When implementing a member function outside of the class, what operator do we use
::
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