What is a class that is pre-defined in C++
String
What does a constructor do?
Defines a default variable of a class
What does it mean if there is a void in front of a function?
The function does not return anything.
How would someone call the function "add_item" in the "cashier" class where the value of the variable is (15)
cashier.add_item(15);
What is the error in the following code?
void cashier::get_total() const;
There shouldn't be a void before the function.
Why would we use a class?
For code where we could need multiple variables with special properties.
What does a getter do?
Returns the value of a variable in a class.
What type of function is this:
void teacher::add_grade(letter_grade)
A setter.
How would someone call the function below?
void cat::sleep(){
time_slept++
}
cat.sleep();
What is the error in the following code?
class cashier{
public:
double money;
cashier();
private:
double total;
}
The data member "money" was defined in the public section.
What are the two sections in the public interface?
the public and the private sections.
What does a setter do?
Sets the value of a variable in a class.
What type of function is this:
string teacher::get_name() const;
How would someone call the function "set_price" in the "cashier" class where the value of the variable is (26)
cashier.set_price(26);
What is the error in the following code?
void cashier::set_total(total){
total = price - money;
return total;
}
there can not be a return in a void function.
What does a class do?
Defines a new type of variable with properties and functions
Why do we need to define a blank constructor?
So that there is a variable to change later.
What do the member functions do?
They can set and return values for variables inside of a class.
How would someone call the function below?
string cat::set_name(new_name){
name = new_name;
}
cat.set_name("Cat");
What is the error in the following code?
void cashier.set_total(total){
total = total - money;
}
the cashier.set_total should be cashier::set_total
What makes up the public interface of a class
member functions, data members, and constructors
What would the function calling look like for a function named add_grade() in the class teacher.
teacher.add_grade()
What would a getter function in the class "teacher" called count_students look like?
int teacher::count_students() const;
How would someone call the function below?
string teacher::set_subject(new_subject){
subject = new_subject;
}
teacher.set_subject("coding");
What is the error in the following code?
int cashier::give_change(change_owed){
change_owed = change - change_owed
}
The function does not return any value.