Review

advertisement
Definition
Class
In C++, the class is the construct primarily used to
create objects.
Definition
OBJECT
Objects are instances of a class.
Definition
Encapsulation
Definition
Constructor
A constructor is a member function that is automatically called when a
class object is created.
Default constructor
A constructor that has no parameters.
Definition
Friend of classes
A friend is a function that is not a member of a class, but has access to
the private members of the class.
Definition
Memberwise Assignment
The = operator may be used to assign one object to another or to
initialize the object with another object’s data. By default, each
member of one object is copied to its counterpart in the other object.
Definition
Copy Constructor
A copy constructor is a special constructor that is called whenever a new
object is created and initialized with the data of another object of the same
class
Ex:
Car (Car a) {
myYear = a.getYear();
myMake = a.getMake();
}
Which of the following shows the correct use
of the scope resolution operator in a member
function definition?
•
InvItem:: void setOnHand (int units)
•
Void InvItem:: setOnHand (int units)
Assuming that soap is an instance of an
Inventory class, which of the following is a
valid call to the setOnHand member function
Inventory soap;
setOnHand(20);
soap::setOnHand(20);
soap.setOnHand(20);
Inventory.setOnHand(20);
A private class member function can be called
by
• Any other function
• Only public functions in the same class
• Only private functions the same class
• Any function in the same class
Assume a map class has a member variable
named position that is an instance of the Location
class. The Location class has a private member
variable named latitude and a public member
function called getLatitude.
How would you return the value stored in latitude
• return Location.latitude();
• return Location.getLatitude();
• return position.latitude();
• return position.latitude();
Assume there is a class named Pet. Write the
prototype for a member of Pet that overloads
the = operator.
Pet Pet :: operator= (Pet);
What is the output for the following:
try {
….
throw (99);
…
} catch (int e) { cout << “The exception caught is : “ << e << endl; }
cout << “ The code ran without exception “ << endl;
What is the output for the following:
try {
….
throw “ Bad input”;
…
} catch (int e)
{ cout << “The exception caught is : “ << e << endl; }
cout << “ The code ran without exception “ << endl;
What is the output for the following:
try {
….
throw “ Bad input”;
…
} catch (int e)
{ cout << “The exception caught is : “ << e << endl; }
catch (string se)
{ cout << The exception caught is “ << se << endl;}
cout << “ The code ran without exception “ << endl;
What is the output for the following:
try {
….
throw (99);
throw “ Bad input”;
…
} catch (int e)
{ cout << “The exception caught is : “ << e << endl; }
catch (string se)
{ cout << The exception caught is “ << se << endl;}
cout << “ The code ran without exception “ << endl;
Complete the following code skeleton to declare a
class called DATE. The class should contain
member variables and functions to store and
retrieve the month, day, and year components of a
date
Class Date
{private:
public:
}
Download