Check Your Understanding
Check Your Understanding
Author Note
This paper was prepared for [INSERT COURSE NAME], [INSERT COURSE
ASSIGNMENT] taught by [INSERT INSTRUCTORS NAME].
Directions: Read the questions below and chose the correct answer for each. Indicate your
choice by highlighting or underlining the text.
1.
How many members (data and functions) does the following class have?
class Rational
{
public:
Rational();
Rational(int numer, int denom);
Rational(int whole);
int getNumerator();
int getDenominator();
friend void display(ostream& out, const Rational& value);
private:
int numerator;
int denominator;
};
a. 2
b. 6
c. 5
d. 7
2.
3.
Why should you generally pass an object of the class to a friend function as a reference
parameter?
a. If the friend function changes the values of the data member(s)
b. If the friend function will not change the values of the data member(s)
c. It is more efficient to pass the object by reference
d. If the friend function changes the values of the data member(s) and it is more
efficient to pass the object by reference
4.
What is wrong with the following member function definition given the class below?
class Rational
{
public:
Rational();
Rational(int numer, int denom);
Rational(int whole);
int getNumerator() const;
int getDenominator() const;
To overload functions with symbolic names (like + - / <<), you must use the keyword
__________ before the symbolic name.
a. const
b. operator
c. reference
d. void
6.
7.
Which of the following would be an appropriate function declaration to add two rational
numbers?
a. void friend operator+( const Rational &left, const Rational &right);
b. void operator+( const Rational &left, const Rational &right);
c. friend Rational operator+( const Rational &left, const Rational &right);
d. Rational operator+( const Rational &left, const Rational &right);
8.
9.
What member functions do you need to allow the compiler to perform automatic type
conversions from a type different than the class to the class?
a. Overloaded constructors
b. Converters
c. This cannot be done
d. This already happens automatically
11.
12.
13.
Given the following class and array declaration, how would you print out the age of the 10 th
person in the array?
class personClass
{
public:
void setAge(int newAge);
void setGender( char newGender);
void setSalary(float newSalary);
int getAge();
char getGender();
float getSalary();
private:
int age;
char gender;
float salary;
};
personClass people[100];
a. cout << people[10];
b. cout << people[9];
c. cout << people[9].age;
d. cout << people[9].getAge();
15.
16.
When a dynamic array with a class for a base type is declared, which constructor is called?
a. Copy constructor
b. Destructor
c. Default constructor
d. Explicit constructor
17.
18.
19.
20.
Which of the following are valid declarations for an assignment operator for a class named
myClass?
a. void friend operator = (myClass& left, const myClass& source);
b. void operator = (myClass& left, const myClass& source);
c. void friend operator = (const myClass& source);
d. void operator = (const myClass& source);
22.
23.
If you have mutators and accessors, you should not have friend functions also.
a. True
b. False
24.
Friend functions may directly modify or access the private data members.
a. True
b. False
25.
26.
Functions that are constant member functions may call the class mutator functions.
a. True
b. False
27.
Functions that are constant member functions may call constant class accessor functions.
a. True
b. False
28.
29.
30.