What is the main purpose of a constructor in C++?
To initialize an object
Is a constructor public or private?
Public
If a member function is void, it is a ___.
Setter
What is the error in this code:
void Employee:get_name(){return name;}
There has to be TWO colons.
What does OOP stand for?
Object Oriented Programming
This constructor has NO arguments/parameters
Default Constructor
What is the process of providing a public interface while hiding the implementation details?
Encapsulation
Getters
What is wrong with this piece of code?
Point::p(double x, double y){
x_coord = x;
y_coord = y;
}
It should be Point::Point
What month is Ms. B's birthday in?
March
DOUBLE JEOPARDY
What does a Constructor return?
False
What are the two main types of member functions(formal name)?
Mutators and Accessors
What's wrong with this code?
Point::Point(double x, double y)
{
x_coord = x;
y_coord = y;
}
int main()
{
double x1;
Point p1(x1);
}
In int main, the object only contains one parameter, but the constructor needs two to run.
How many sections were in this unit?
6
Where are constructors declared?
Inside the class definition
What is in the public interface?
All Member Functions
Do you start with accessor or mutator functions when defining a class?
Accessor
What's wrong with this?
class Point
{
private:
double x_coord;
double y_coord;
void set_x_coord(double x);
void set_y_coord(double y);
public:
double get_x_coord() const;
double get_y_coord() const;
};
The setter functions should be in the public part of the class
The class NishantLikesBrownies has a constructor...
What is the best possible name for this constructor?
NishantLikesBrownies
(bonus points if italicized)
Because accessors verify and change the object...
what type of value should they return?
Trick Question.... Acessors dont change the object!
What do you use to mark accessor functions?
CONST
What's wrong with this code?
#include <iostream>
using namespace std;
class Rectangle
{
private: //members
double length;
double width;
public: //functions
void set_length(double l);
void set_width(double w);
double get_length();
double get_width();
}
A semicolon is missing at the very end... similar to struct
DOUBLE JEOPARDY
What was the first example used to model a class?Tally Counter