Final Exam (MC option)
Started: May 22 at 3:12pm
Quiz Instructions
Canvas Support
This test is open book and open notes. You have 6 hours to complete the exam in one sitting.
Once you start the exam, the clock on Canvas will start clicking, so make sure that you allocated
a continuous 6-hour block for the exam.
You may use your textbook, homework, labs, lectures, etc.. Exam is due back via Canvas before
midnight May 27, 2025.
This test is all multiple choice.
Question 1 1 pts
Which of the following hides the implementation details of the data members and member functions
within a class?
Virtualization
Inheritance
Abstraction
Encapsulation
Question 2 1 pts
How can you traverse from one node to another in a list<string> ?
By using a pointer to a list<string> object
By using an integer index
By using an iterator
By using a pointer to a node<string> object
Question 3 1 pts
Given a class Name with member functions get_first and get_last , which of the following functions
overloads < < so that one can print a name as
, stream << name << endl;
void operator<<(ostream& out, const Name& name)
{
out << name.get_first() << " " << name.get_last();
}
Canvas Support
ostream& operator<<(ostream& out, const Name& name)
{
return out << name.get_first() << " " << name.get_last();
}
ostream& operator<<(const Name& name, ostream& out)
{
return out << name.get_first() << " " << name.get_last();
}
ostream& operator<<(ostream& out, const Name& name)
{
return cout << name.get_first() << " " << name.get_last();
}
Question 4 1 pts
What is the correct function prototype to implement an equals comparison operation for a class such as
Time ?
bool operator==(Time a, Time b)
bool ==(Time a, Time b)
void ==(Time a, Time b)
void operator==(Time a, Time b)
Question 5 1 pts
What is the problem with the following code snippet, which is attempting to locate the first element in the
list names ?
list<string> names;
...
string first = names[1];
,You need to first check that the size of names is at least 2.
It is not legal to use the [] operator with a list<string> object.
There is no problem with the code snippet.
Canvas Support
The first element will be located by using names[0] .
Question 6 1 pts
What is the output of the following code snippet?
class Building
{
public:
void set_height(double count);
void get_data() const;
private:
double height;
};
void Building::get_data() const
{
cout << height << endl;
}
void Building::set_height(double count)
{
height = count;
}
int main()
{
Building blg1, blg2;
blg1.set_height(150);
blg2.set_height(100);
blg1.get_data();
blg2.get_data();
return 0;
}
150
100
100
150
, 150
250
Canvas Support
150
150
Question 7 1 pts
What operator must be overloaded if you want to use the standard library sort with a class such as
Time ?
>
==
All of these
<
Question 8 1 pts
How can you locate the ninth node in a doubly-linked list named items ?
Start at the first node and follow pointers to the next node in the list until the ninth node is located.
items[9]
items[10]
items[8]
Question 9 1 pts
Which is true about the following operator < < function intended to read in a Time object as in
Time t; stream >> t;
istream& operator>>(istream& in, Time a)
{
int hours, minutes;
char separator;
in >> hours;
in.get(separator); // Read : character
in >> minutes;
a = Time(hours, minutes);
Started: May 22 at 3:12pm
Quiz Instructions
Canvas Support
This test is open book and open notes. You have 6 hours to complete the exam in one sitting.
Once you start the exam, the clock on Canvas will start clicking, so make sure that you allocated
a continuous 6-hour block for the exam.
You may use your textbook, homework, labs, lectures, etc.. Exam is due back via Canvas before
midnight May 27, 2025.
This test is all multiple choice.
Question 1 1 pts
Which of the following hides the implementation details of the data members and member functions
within a class?
Virtualization
Inheritance
Abstraction
Encapsulation
Question 2 1 pts
How can you traverse from one node to another in a list<string> ?
By using a pointer to a list<string> object
By using an integer index
By using an iterator
By using a pointer to a node<string> object
Question 3 1 pts
Given a class Name with member functions get_first and get_last , which of the following functions
overloads < < so that one can print a name as
, stream << name << endl;
void operator<<(ostream& out, const Name& name)
{
out << name.get_first() << " " << name.get_last();
}
Canvas Support
ostream& operator<<(ostream& out, const Name& name)
{
return out << name.get_first() << " " << name.get_last();
}
ostream& operator<<(const Name& name, ostream& out)
{
return out << name.get_first() << " " << name.get_last();
}
ostream& operator<<(ostream& out, const Name& name)
{
return cout << name.get_first() << " " << name.get_last();
}
Question 4 1 pts
What is the correct function prototype to implement an equals comparison operation for a class such as
Time ?
bool operator==(Time a, Time b)
bool ==(Time a, Time b)
void ==(Time a, Time b)
void operator==(Time a, Time b)
Question 5 1 pts
What is the problem with the following code snippet, which is attempting to locate the first element in the
list names ?
list<string> names;
...
string first = names[1];
,You need to first check that the size of names is at least 2.
It is not legal to use the [] operator with a list<string> object.
There is no problem with the code snippet.
Canvas Support
The first element will be located by using names[0] .
Question 6 1 pts
What is the output of the following code snippet?
class Building
{
public:
void set_height(double count);
void get_data() const;
private:
double height;
};
void Building::get_data() const
{
cout << height << endl;
}
void Building::set_height(double count)
{
height = count;
}
int main()
{
Building blg1, blg2;
blg1.set_height(150);
blg2.set_height(100);
blg1.get_data();
blg2.get_data();
return 0;
}
150
100
100
150
, 150
250
Canvas Support
150
150
Question 7 1 pts
What operator must be overloaded if you want to use the standard library sort with a class such as
Time ?
>
==
All of these
<
Question 8 1 pts
How can you locate the ninth node in a doubly-linked list named items ?
Start at the first node and follow pointers to the next node in the list until the ninth node is located.
items[9]
items[10]
items[8]
Question 9 1 pts
Which is true about the following operator < < function intended to read in a Time object as in
Time t; stream >> t;
istream& operator>>(istream& in, Time a)
{
int hours, minutes;
char separator;
in >> hours;
in.get(separator); // Read : character
in >> minutes;
a = Time(hours, minutes);