COP 3330 Final Prep Questions and
Answers Graded A+
1. ________ is the flag that instructs g++ to give a specified name to an executable
after linking.
a. -g
b. -c
c. -o
d. -e - ANSWER-C
1. ___________ represents a "has a" relationship between two classes in object-
oriented programming.
a. Interface
b. Inheritance
c. Aggregation
d. CRUD - ANSWER-C
1. (10 points) The definition of an operator overload for the "==" operator that compares
the ticks of two Timer instances and returns if they are equal implemented as a friend
function. - ANSWER-bool operator==(const Timer& t1, const Timer& t2) {
if(t1.ticks == t2.ticks) {
return true;
} else {
Return false;
}
}
1. (5 points) The declaration of a friend function that subtracts the ticks of one Timer
from another Timer. - ANSWER-friend Timer subtract(const Timer& t1, const Timer&
t2);
1. (5 points) The declaration of an operator overload for the "++" operator that adds 1
tick to the Timer implemented as a member function. - ANSWER-Timer operator++();
1. (5 points) The declaration of an operator overload for the "==" operator that compares
the ticks of two Timer instances and returns if they are equal implemented as a friend
function. - ANSWER-friend bool operator==(const Timer& t1, const Timer& t2);
1. (5 points) The definition of a friend function that subtracts the ticks of one Timer from
another Timer. - ANSWER-Timer subtract(const Timer& t1, const Timer& t2) {
Timer t;
t.ticks = t1.ticks - t2.ticks;
return t;
, }
1. (5 points) The definition of a member function that allows the timer to increment an
arbitrary number of ticks. - ANSWER-void Timer::Increment(int _ticks) {
ticks += _ticks;
}
1. (5 points) The definition of an operator overload for the "++" operator that adds 1 tick
to the Timer implemented as a member function. - ANSWER-Timer Timer::operator++(){
Timer t;
t.ticks = t + 1;
return t;
}
1. ++ is a(n) ________ operator.
a. Tertiary
b. Binary
c. Unary
d. *this is the wrong answer* - ANSWER-C
1. A class can have an arbitrary number of constructors. - ANSWER-T
1. A copy constructor should be implemented when a class uses DMA. - ANSWER-T
1. A copy constructor should take in two parameters by value. - ANSWER-F
1. A data structure intended to abstract the concept of dynamic memory allocation away
from an application engineer is referred to as a __________ class.
a. Container
b. God
c. Multiplicative
d. Dynamic - ANSWER-A
1. A driver program cannot access private data or function members. - ANSWER-T
1. A setter should always be marked const. - ANSWER-F
1. A(n) _______ function has access to both public and private members of a class but
is NOT a member function.
a. explicit
b. protected
c. static
d. friend - ANSWER-d. friend
1. A(n) ________ is used to set constant data members of a class:
a. Initialization list
Answers Graded A+
1. ________ is the flag that instructs g++ to give a specified name to an executable
after linking.
a. -g
b. -c
c. -o
d. -e - ANSWER-C
1. ___________ represents a "has a" relationship between two classes in object-
oriented programming.
a. Interface
b. Inheritance
c. Aggregation
d. CRUD - ANSWER-C
1. (10 points) The definition of an operator overload for the "==" operator that compares
the ticks of two Timer instances and returns if they are equal implemented as a friend
function. - ANSWER-bool operator==(const Timer& t1, const Timer& t2) {
if(t1.ticks == t2.ticks) {
return true;
} else {
Return false;
}
}
1. (5 points) The declaration of a friend function that subtracts the ticks of one Timer
from another Timer. - ANSWER-friend Timer subtract(const Timer& t1, const Timer&
t2);
1. (5 points) The declaration of an operator overload for the "++" operator that adds 1
tick to the Timer implemented as a member function. - ANSWER-Timer operator++();
1. (5 points) The declaration of an operator overload for the "==" operator that compares
the ticks of two Timer instances and returns if they are equal implemented as a friend
function. - ANSWER-friend bool operator==(const Timer& t1, const Timer& t2);
1. (5 points) The definition of a friend function that subtracts the ticks of one Timer from
another Timer. - ANSWER-Timer subtract(const Timer& t1, const Timer& t2) {
Timer t;
t.ticks = t1.ticks - t2.ticks;
return t;
, }
1. (5 points) The definition of a member function that allows the timer to increment an
arbitrary number of ticks. - ANSWER-void Timer::Increment(int _ticks) {
ticks += _ticks;
}
1. (5 points) The definition of an operator overload for the "++" operator that adds 1 tick
to the Timer implemented as a member function. - ANSWER-Timer Timer::operator++(){
Timer t;
t.ticks = t + 1;
return t;
}
1. ++ is a(n) ________ operator.
a. Tertiary
b. Binary
c. Unary
d. *this is the wrong answer* - ANSWER-C
1. A class can have an arbitrary number of constructors. - ANSWER-T
1. A copy constructor should be implemented when a class uses DMA. - ANSWER-T
1. A copy constructor should take in two parameters by value. - ANSWER-F
1. A data structure intended to abstract the concept of dynamic memory allocation away
from an application engineer is referred to as a __________ class.
a. Container
b. God
c. Multiplicative
d. Dynamic - ANSWER-A
1. A driver program cannot access private data or function members. - ANSWER-T
1. A setter should always be marked const. - ANSWER-F
1. A(n) _______ function has access to both public and private members of a class but
is NOT a member function.
a. explicit
b. protected
c. static
d. friend - ANSWER-d. friend
1. A(n) ________ is used to set constant data members of a class:
a. Initialization list