class LoanClass
{
public:
void printRate();
float payoff();
void schedule();
void LoanSettings(char t, float r, int m);
private:
char type;
float rate;
int months;
float simplePayment();
float compoundPayment();
};
the main function of the program can make a call to simplePayment() for any
LoanClass instance.
Exercise 2
A. A constructor must have the same name as the ___________.
B. What is the type of a constructor?
A. There is no type
B. void
C. Bool because it returns true or false based on whether or not the
initialization was successful.
D. The type is dependent upon the actual class.
C. Given the following class specification, write the code necessary to
declare and initialize an object "Loan" of LoanClass such that "Loan" is
a simple loan ('S') with
a .0675 rate and 36 months.
class LoanClass
{
public:
LoanClass(char t, float r, int m);
void printRate();
float payoff();
void schedule();
private:
char type;
float rate;
int months;
float simplePayment();
float compoundPayment();
};
Exercise 3
{ Script }
Exercise 4
A.P The constructor is normally a __________________.
A. public member function
B. private member function
C. public data member
D. private data member
B.P A constructor is used to ________________ an object when the object
is declared.
Exercise 5
A. (T/F) The following is an example of the use of an overloaded function.
int a = 10, b = 6;
int x[4] = {5, 6, 7, 8};
cout << sum(a, b) << endl;
cout << sum(x, 4) << endl;
B. Which of the following determines which definition of an overloaded
function is intended based on the context?
A. The user
B. The compiler
C. The linker
D. The processor
C. Which of the following represent situations where function
overloading could be used?
A. The program must add 3 numbers. It must also add 3 arrays.
B. The program must multiply two arrays. It must also add two arrays.
C. A and B
D. None of the above
Exercise 6
{ Script }
Exercise 7
A.P Overloading is an example of ___________________, a term derived from
a Greek work meaning "many forms".
B.P (T/F) The meaning of a function that is overloaded is completely determined
by the context (i.e., what statements are around the function call).
Exercise 8
A. A constructor with no arguments is called a
__________________ constructor.
B. (T/F) A class must explicitly define a constructor in order for
objects of that type to be declared.
C. Write the function heading for a default
constructor for the "Book" class.
Exercise 9
{ Script }
Exercise 10
A.P (T/F) It is possible to have two default constructors
in a class definition.
B.P Define a default constructor for the "Book" class (as it
appears in the implementation file) that
leaves all data values uninitialized.
Exercise 11
A. (T/F) C++ provides overloaded definitions for the =
operator.
B. (T/F) It is possible to change the meaning of the +
operator for variables of type float.
C. Write the function heading of an overloaded
* operator that multiplies two objects of the myArray class (the usage
would be lhs * rhs) and returns a value of type myArray.
Exercise 12
{ Script }
Exercise 13
A.P Write the heading of the function
operator == for the Clock class (the usage is lhs == rhs).
B.P (T/F) We can overload the + operator to add three
user defined matrices.
----- End of Lab 7 - C++ Classes Continued-----
Complete the Exercises on the Answer Sheet.
Turn in the Answer Sheet
and the printouts required by the exercises.