What is the definition of a class?
A blueprint that describes a set of objects with the same behavior.
True or false: You put data members in the public interface.
False: You want to protect the data members in the private interface.
Where are variables declared?
Private section
Which is constant, a mutator or an accessor?
An accessor
What class would Phoebe and Chives (Mrs. Diaz's pets) belong to?
a) Dog
b) getName();
c) Cat
d) int age;
c) Cat
True or false: The name of the constructor can be anything
False: Has to have the same name as the class
What are other names for mutators and accessors?
Mutators: setters
Accessors: getters
True or false: Each object has a separate copy of the data members.
True
Which syntax is correct?
a) void Clock. reset()
b) void Clock: reset();
c) void Clock:: reset()
d) void Clock:: reset();
d) void Clock:: reset();
What does OOP stand for?
Object Oriented Programming
What is encapsulation?
The process of providing a public interface while hiding implementation details.
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();
Why are data members private?
To protect the state of the data members.
True or False: You can call member functions within member functions.
True
Which of the following is an attribute of Clock class?
a) Hour
b) Move hand
c) Reset clock
d) Page count
a) Hour
A constructor is a special ______ function that initializes the _____ ________ of an object.
member; data members
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 }
What does const do?
States that the member variables will not change
Which is the implicit and explicit parameter?
person.set_age(13);
Implicit: person
Explicit: 13
Where have we seen Object Oriented Programming before the introduction of classes?
In string objects, cin, and cout
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.
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.
Find the error:
class Cat
{
private:
void set_age();
int get_age() const;
public:
int age;
double height;
};
Switch the private and public section.
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
For a Cat class, what are two functions that could be used in the public interface?
meow();
purr();
walk();
scratch();
etc, more behaviors...