CS211 ExamFinal ReviewDoc
CS211 ExamFinal ReviewDoc
The purpose of this document is to assist in reviewing and preparing for the CS 211 Final Exam. The exam covers all
topics from Modules 1-14 of the course.
The list of topics is intended to give an impression of the breadth of concepts that we have covered thus far. It can
be used to get a big picture look at the main ideas of the course and act as an outline for studying. It is not
intended to be a complete set of all course-related subject matters and definitely not a resource for the details
about any of the topics; the zyBook, supplementary resources for lab, lecture slides, lab activities, and projects are
a good set of resources for a full review. Thus, the list of topics below is a starting point for review, that is, a guide
that leads each student’s study toward the areas that need the greatest attention.
The review problems that follow are intended to provide review exercises for preparing for the exam, composed
of the review questions from the three midterm exam review documents. Some of the problems give students an
idea of the question type(s) and/or the content nature of exam problems. This is NOT a sample exam, in that the
number of questions and overall length of the exam does NOT accurately represent the actual exam AND there are
no full code writing exercises on the exam. Instead, these sample questions are helpful as a study tool. You are
strongly encouraged to first work out your solutions/answers. It is then recommended that you test your answers
on the computer (e.g. empty workspace in the zyBook) and to discuss your results with classmates/TAs on the class
Piazza page or with the teaching staff during office hours/help sessions.
o Overloading Operators
o Rule of Three
o Templated Classes
• Inheritance
o Why do we use inheritance?
o Base/parent class vs derived/child class
o What happens when a class inherits another? What are the rules for the way a derived class
accesses the data members of its parent class?
o The protected keyword
o Public vs Protected vs Private inheritance
o Overloading vs Overriding Functions
o How do constructors, destructors, and assignment operator members work with inheritance?
o Composition vs Inheritance
o Inheriting multiple classes
o The Diamond Problem – what is it?
• Polymorphism
o What is polymorphism?
o Compile-time Polymorphism vs Runtime Polymorphism
o Compile-time Polymorphism – function overloading, overloading operators
o Runtime Polymorphism
§ Derived/base class pointer conversion
§ Virtual functions
§ Why do we use the keyword virtual when defining the destructor?
§ The override keyword
§ Pure virtual functions
§ Abstract vs Concrete classes
• Friendship
o The friend keyword
o Friend functions
o Friend classes
• Smart Pointers
o Wrapper class for a pointer
o Motivation: automatic destruction when object goes out of scope
o unique_ptr vs. shared_ptr vs. weak_ptr
o reference counter with use_count() method
o using dynamic_pointer_cast() to determine polymorphic type
• Testing Strategies
o Unit Testing
o Test-Driven Development
o DCBA Method for testing and code development
• Exception Handling
o Try/catch statements for throwing/handling exceptions
o Common exception types
• Code Reviews
o Purpose of code reviews
o Typical components of an effective code review
CS 211 - Programming Practicum
Final Exam - Review Document
1. Assume the program below is run from the command line as follows: ./a.out hello
What is the output?
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
printf("%d%c%c", argc, argv[0][3], argv[1][1]);
return 0;
}
2. Assume that main.c is a program with no errors. What happens when we run the following
command in the terminal?
gcc -g main.c -o main.o
(A) Nothing happens since you cannot run gcc like this.
(B) A file called main.o is created, which we can use to run our program.
(C) The code is compiled, and an executable file called a.out is created.
(D) A debugger is launched, which allows you to run the program with breakpoints.
3. Modify the code by only adding asterisk(s) (*) and ampersand(s) (&) so that the output is 15?
10 void fA(int a) {
11 a = a + 10;
12 }
13 int main() {
14 int x = 5;
15 fA(x);
16 printf("%d", x);
17 return 0;
18 }
4. A run-time error occurs when the following program is executed. Explain and fix the error.
a. What is the printed output of the line labeled with comment (a)?
b. What is the printed output of the line labeled with comment (b)?
c. What is the printed output of the line labeled with comment (c)?
d. What is the printed output of the line labeled with comment (d)?
e. What is the printed output of the line labeled with comment (e)?
f. What is the printed output of the line labeled with comment (f)?
g. What is the printed output of the line labeled with comment (g)?
6. Write the myReallocation() function, which should reallocate the input heap-array *arr with a
new *capacity double the size it had when the function was called, without calling realloc().
void myReallocation(int** arr, int* capacity) {
CS 211 - Programming Practicum
Final Exam - Review Document
For the next four questions, the following keywords may be helpful:
ls, ls -l, ls -a, mv, cp, rm, rm -r, mkdir, cd, pwd, cat, more, man,
gcc -g, gcc -o, file, help, run, break, continue, step, next, watch,
print, backtrace, where, finish, delete, info breakpoints
7. You are working in a UNIX terminal and would like to create a new folder called "Tests" within
the current directory. What would you type?
8. You are working in a UNIX terminal and would like to view the full pathname of the current
directory. What would you type?
9. You are working on a program called main.c, and you would like to be able to debug it using
gdb. What do you type in the terminal to compile the program, before launching gdb?
10. You are debugging your program with gdb, and have set multiple breakpoints. The code has
reached the first breakpoint. What do you now type to proceed to the next breakpoint?
c 5040 'a'
pc 5042 ???
p 5050 862
2. What is the output of the following code? The input is: I love CS 211!
char letters[] = "";
scanf("%s", letters);
fgets(letters, 81, stdin);
printf("%s", letters);
6. Consider using insertion sort to process the following list of numbers into ascending order (smallest to
largest): 3 5 2 4 1
What would be the order of the numbers after making only the first pass through the list?
CS 211 - Programming Practicum
Final Exam - Review Document
9. Which of the following best describes the output of the following code? Assume that funcB() has been
defined above main().
int main() {
time_t startTime;
startTime = time(NULL);
funcB();
printf("%6.1f\n",difftime(startTime, time(NULL)));
return 0;
}
A) The code does not compile.
B) The code compiles, but crashes.
C) It will output the number of seconds that funcB() took to run.
D) It will output the number of seconds that funcB() took to run, but as a negative value.
10. A program is run with gprof to analyze the system timing. The program contains only the following
functions: func1(), func2(), and main(). The function func1() is called twice from inside func2(), which is
called from main() 100,000 times. The program spends about 4x longer inside func1() then it is in func2().
The total runtime of the program is 0.5 seconds. Describe the gprof Flat Profile in as much detail as
possible.
11. Suppose you are working on your local version of a GitHub repository. You have made changes to main.c
and need to update the remote version of the repository with your changes? What commands should be
run to do so?
CS 211 - Programming Practicum
Final Exam - Review Document
12. You have opened a file in vim with the command vim main.c. What should you type to find all of the
instances of a variable named num and change the variable name to val?
clean:
rm max max1.o max2.o
16. Suppose there is a linked list of Nodes where pHead points to the head node. Which of the following
code snippets properly links a new node, pNode, at the head of the list?
A. pNode->pNext = pHead;
pHead = pNode;
B. pNode->pNext = pHead->pNext;
pHead->pNext = pNode;
C. pHead->pNext = pNode;
pNode->pNext = pHead->pNext;
D. pHead = pNode;
pNode->pNext = pHead;
The function appendNode() should append a new node for the input State to the end of the non-
empty linked list associated with head node pHead and tail node pTail. Fill in the code for blanks A, B,
and C to complete the function.
void appendNode(SNode** pHead, SNode** pTail, State* newState) {
SNode* pTemp = A ;
pTemp->pState = B ;
C ;
D ;
*pTail = pTemp;
}
The function deleteList() should delete all BUT THE LAST of the nodes in the non-empty linked list,
which involves freeing the memory for the list of SNodes ONLY, i.e. the heap-allocated States and any
other dynamically-allocated memory does NOT need to be freed here. Upon completion, both pHead
and pTail should point to the only remaining node, which is the LAST node in the original list. Fill in the
code for blanks D and E to complete the function:
void deleteList(SNode** pHead, SNode** pTail) {
SNode* pTemp = *pHead;
while( E ) {
pTemp = *pHead;
*pHead = = F ;
free(pTemp);
}
}
CS 211 - Programming Practicum
Final Exam - Review Document
18. The following code is in development and should read data from a file to set up a two-dimensional array.
#include <stdio.h>
int main() {
FILE *myinput = NULL;
int myArray[3][2];
int *myPtr = &(myArray[0][0]);
myinput = fopen("review1.txt","r");
while (!feof(myinput)) {
fscanf(myinput,"%d",myPtr);
myPtr++;
}
for (int j = 0; j < 2; j++) {
for (int i = 0; i < 3; i++) {
printf("%d ",myArray[i][j]);
}
}
myoutput = fopen("review2.txt","r");
fprintf(myoutput,"%d",myArray[1][1]);
return 0;
}
a. Assume the file review1.txt is in the current folder when the program is executed and contains
5 29 37 18 -3 2, all on one line. Being very careful with formatting, what is the printed output of
the program?
b. How does the printed output of the program change if the data in the file review1.txt is stored in
two rows as follows: 5 29 37
18 -3 2
c. How does the printed output of the program change if the data in the file review1.txt is stored in
two columns as follows: 5 18
29 -3
37 2
d. Now assume the review1.txt is not in the current folder when the program is executed. Where
will myinput point to after the fopen() call?
e. Due to a coding mistake, the code currently does not create the new file review2.txt. How
should the code be modified to fix the error?
f. Even after fixing the mistake in part (e), there are still ERROR(s) when valgrind is run on the
program. What lines of code should be added, and where should they be added, to have no
ERROR(s)?
CS 211 - Programming Practicum
Final Exam - Review Document
19. Code writing review exercise: Write the recursive getSum() function (do not use any loops), which
returns the sum of all the elements of an array of integers. The two inputs are the array and its size. For
example, the printed output is 40 for the following code:
20. Code writing review exercise: There exists an input file named “students.txt” that
contains student NetIDs and GPAs. An example is shown on the right; the format is cobrie 1.98
one student per line, with one or more spaces between the NetID and GPA. Write a malbri 3.43
complete C program that opens this file, inputs the data, and prints the NetID and rmaddo 4.00
GPA of every student with a GPA < 2.0; assume the file will open successfully. User- .
defined functions are not required, and arrays are not necessary because the data .
does not need to be stored for other purposes.
.
#include <stdio.h>
#include <string.h>
int main() {
}
CS 211 - Programming Practicum
Final Exam - Review Document
int main() {
Student student1;
XXX
…
}
a. student1.name = "Harry";
b. myString = student1.name;
c. student1.Display();
d. student1.SetGrade("Harry");
5. Which of the following statements is true about a class’ private helper function?
a. A private helper function can be called from main().
b. A private helper function helps private functions carry out their tasks.
c. A private helper function cannot call other private helper functions.
d. A private helper function helps public functions carry out tasks.
int main() {
Student student1;
student1.SetScore(80);
cout << student1.GetGrade();
return 0;
}
class Number {
public:
int x;
};
int main() {
Number a;
int sum = 0;
a.x = 10;
Number b = a;
sum = a.x + b.x;
cout << sum;
return 0;
}
12. Assuming a class Employee has been defined, which of the following statements is
correct for declaring a vector?
a. vector[Employee] employeeList;
b. vector<Employee> employeeList;
c. vector Employee employeeList;
d. vector (Employee) employeeList;
CS 211 - Programming Practicum
Final Exam - Review Document
int main() {
vector<Student> studentList;
Student currStudent;
int currScore;
string currName;
unsigned int i;
cout << "Type Score + Name." << endl << "To end: -1" << endl;
cin >> currScore;
while (currScore > 0) {
cin >> currName;
currStudent.SetScoreAndName(currScore, currName);
studentList.push_back(currStudent);
totalScore += currScore;
cin >> currScore;
}
cout << "Students: ";
for(i = 0; i < studentList.size(); i++){
cout << studentList.at(3 - i).GetName() << " ";
}
return 0;
}
CS 211 - Programming Practicum
Final Exam - Review Document
14. The Hotel class is defined in two separate files: Hotel.h and Hotel.cpp. Which of the
following statements is true?
a. Hotel.cpp contains the class definition with data members and function
declarations.
b. Hotel.cpp contains member function definitions and includes Hotel.h.
c. Hotel.h contains the class and member function definitions.
d. Hotel.h contains the class definition with only data members.
15. Which of the following is true if a programmer has to create a class Clinic with the
following data members and functions?
class Clinic {
int patientRecNum;
string patientName;
void SetDetails(int num, string name);
string GetDetails();
};
a. Data members should be public items and function declarations should be private
items.
b. Data members should be private items and function declarations should be public
items.
c. The data member patientName should be a private item and all other members
should be public items.
d. The function SetDetails should be a public item and all other members should be
private items.
16. What type of program is used to thoroughly check the functionality of another program
(or portion of a program) through a series of input/output checks.
class TempConvert {
public:
void SetTemp(int tempVal) {
temp = tempVal;
}
int GetTemp() const {
return temp;
}
TempConvert() {
temp = 1;
}
int InFahrenheit() {
return (temp * 1.8) - 32;
}
private:
int temp;
};
int main() {
TempConvert testData;
cout << "Beginning tests." << endl;
if (testData.GetTemp() != 0) {
cout << " FAILED initialize/get temp" << endl;
}
testData.SetTemp(10);
if (testData.GetTemp() != 10) {
cout << " FAILED set/get temp" << endl;
}
else (testData.InFahrenheit() != 50) {
cout << " FAILED InFahrenheit for 10 degrees" << endl;
}
cout << "Tests complete." << endl;
return 0;
}
a. Beginning tests.
FAILED initialize/get temp
FAILED InFahrenheit for 10 degrees
Tests complete.
b. Beginning tests.
Tests complete.
c. Beginning tests.
FAILED initialize/get temp
FAILED set/get temp
FAILED InFahrenheit for 10 degrees
Tests complete.
d. Beginning tests.
FAILED InFahrenheit for 10 degrees
Tests complete.
CS 211 - Programming Practicum
Final Exam - Review Document
int main() {
int amountIn;
string strCurr;
Currency newMoney;
cout << "Enter the amount to convert and currency:";
cin >> amountIn;
cin >> strCurr;
newMoney = newMoney.Convert(amountIn, strCurr);
return 0;
}
22. Which constructor will be called by the statement House myHouse(97373); for
the given code?
class House {
House(); // Constructor A
House(int zip, string street); // Constructor B
House(int zip, int houseNumber); // Constructor C
House(int zip); // Constructor D
};
a. Constructor A
b. Constructor B
c. Constructor C
d. Constructor D
CS 211 - Programming Practicum
Final Exam - Review Document
Arcade:: Arcade() {
arcName = "New";
rating = 1;
}
24. What is the final value of myCity's data members? Answer is in the format cityName,
cityPopulation.
#include <iostream>
#include <string>
using namespace std;
class City {
public:
City(string name = "NoName", int population = 0);
private:
string cityName;
int cityPopulation;
};
int main() {
City myCity;
}
a. NoName, 0
b. City, 0
c. Error: Constructor is not defined correctly
d. Error: myCity is not assigned a value in main()
CS 211 - Programming Practicum
Final Exam - Review Document
SimpleCar::SimpleCar() {
odometer = 0;
}
SimpleCar::SimpleCar(int miles) {
odometer = miles;
}
void SimpleCar::Drive(int miles) {
odometer = odometer + miles;
}
int main() {
SimpleCar fordFusion;
SimpleCar hondaAccord(30);
fordFusion.Drive(100);
fordFusion.Drive(20);
return 0;
}
26. Which XXX complete the class School's member function correctly?
class School {
public:
void SetDetails(int numStudents, string name);
private:
int nStudents;
string schoolName;
};
27. The _______ member access operator is used to access a member using the 'this' pointer.
a. ::
b. ->
c. .
d. :
class Shape {
public:
void Print();
Shape(int x);
private:
int sides;
};
Shape::Shape() {
sides = 4;
}
Shape::Shape(int x) {
this->sides = x;
}
void Shape::Print() {
if(this->sides == 4) {
cout << "It’s a Square!" << endl;
}
else {
cout << "Oops!";
}
}
int main() {
Shape s(7);
s.Print();
return 0;
}
29. The process of redefining the functionality of a built-in operator, such as +, -, and *, to
operate on programmer-defined objects is called operator _____.
a. overriding
b. overloading
c. initializing
d. testing
class Shape {
public:
Shape(int l = 5, int b = 5);
void Print();
Shape operator-(Shape shape2);
private:
int length;
int width;
};
Shape::Shape(int l, int b) {
length = l;
width = b;
}
void Shape::Print() {
cout << "Length = " << length << " and " << "Width = " << width << endl;
}
int main() {
Shape s1(20, 20);
Shape s2;
Shape s3;
s3 = s1 - s2;
s3.Print();
return 0;
}
a. Length = 20 and Width = 20
b. Length = 5 and Width = 5
c. Length = -15 and Width = -15
d. Length = 15 and Width = 15
CS 211 - Programming Practicum
Final Exam - Review Document
31. In the following code, what is the correct return statement for an overloaded + operator?
Game Game::operator+(Game newGame) {
Game myGame;
myGame.score = score + newGame.score;
//Return statement to be written here
}
a. return Game;
b. return myGame;
c. return newGame;
d. return score;
32. A programmer is overloading the equality operator (==) and has created a function
named operator==. What are the return type and arguments of this function?
a. Return type: class type, Arguments: 1 const bool reference
b. Return type: bool, Arguments: 2 const class type references
c. Return type: none, Arguments: 2 const class type references
d. Return type: int, Arguments: 2 const bool references
33. Which of the following is the correct way to overload the >= operator to use School class
type with function GetTotalStudents()?
a. void operator>=(const School& lhs, const School& rhs) {
if(lhs.GetTotalStudents() >= rhs.GetTotalStudents()) {
cout << “Is Greater!”;
}
}
b. void operator>=(School& lhs, School& rhs) {
if(lhs.GetTotalStudents() >= rhs.GetTotalStudents()) {
cout << “Is Greater!”;
}
}
c. bool operator>=(School& lhs, School& rhs) {
return lhs >= rhs;
}
d. bool operator>=(const School& lhs, const School& rhs) {
return lhs.GetTotalStudents() >= rhs.GetTotalStudents();
}
CS 211 - Programming Practicum
Final Exam - Review Document
class Movie {
public:
int rating = 1;
void Print() {
cout << "Rating: " << rating << " stars" << endl;
}
};
int main() {
Movie movie1;
Movie movie2;
int currentRating;
movie1.rating = 4;
movie2.rating = 5;
if (movie1 != movie2) {
movie1.Print();
}
else {
movie2.Print();
}
return 0;
}
CS 211 - Programming Practicum
Final Exam - Review Document
int main() {
String leagueName;
XXX
newPlayer.SetName("Tim Murphy");
newPlayer.SetAge(21);
leagueName = newPlayer.GetLeague();
return 0;
}
a. Player newPlayer;
b. String newPlayer;
c. SoccerPlayer:Player newPlayer;
d. SoccerPlayer newPlayer;
CS 211 - Programming Practicum
Final Exam - Review Document
int main() {
String leagueName;
Player newPlayer;
SoccerPlayer newSoccerPlayer;
newSoccerPlayer.SetName("Tim Murphy");
newSoccerPlayer.SetAge(21);
leagueName = newPlayer.GetLeague();
return 0;
}
a. Player newPlayer; will generate an error as an object of the base class
cannot be created.
b. newSoccerPlayer.SetName("Tim Murphy"); will generate an error
as SetName is not declared in class SoccerPlayer.
c. leagueName = newPlayer.GetLeague(); will generate an error as
GetLeague is not a member of the Player class.
d. SoccerPlayer newSoccerPlayer; will generate an error as an object of
the derived class cannot be created.
39. Declaring a member as ____ in the base class provides access to that member in the
derived classes but not to anyone else.
a. public
b. protected
c. private
d. constant
CS 211 - Programming Practicum
Final Exam - Review Document
int main() {
Car myCar;
string str;
myCar.SetID(45);
str = myCar.GetMiles();
return 0;
}
a. In class Car : Vehicle, the specifier is not mentioned.
b. The function myCar.SetID() is not accessible by main().
c. The function myCar.GetMiles() is not accessible by main().
d. Class Car : Vehicle does not have protected data members declared.
41. Which of the following statements is true for the following code?
class SpaceObject {
public:
double GetMass();
private:
double mass;
...
}
int main() {
string leagueName;
SoccerPlayer newPlayer;
newPlayer.SetName("Jim Allen");
newPlayer.SetAge(21);
leagueName = newPlayer.GetLeague();
return 0;
}
a. leagueName = newPlayer.GetLeague() will generate an error as the
derived class members should not be called by the derived class.
b. newPlayer.SetName("Jim Allen") will generate an error as SetName
is not declared in class SoccerPlayer.
c. newPlayer.SetAge(21) will generate an error as SetAge is a private
member not inherited by the SoccerPlayer class.
d. SoccerPlayer newPlayer will generate an error as an object of a derived
class cannot be created.
43. The _____ operator is used to inherit one class from another.
a. .
b. :
c. ->
d. ::
44. When a derived class defines a member function that has the same name, parameters, and
return type as a base class's function, the member function is said to _____ the base
class's function.
a. overload
b. override
c. inherit
d. copy
CS 211 - Programming Practicum
Final Exam - Review Document
45. Which function has been overridden in the following code snippet?
class Game {
public:
void GameName(string name);
protected:
void SetName();
string name;
private:
string type;
void GameCategory();
};
int main() {
…
}
a. PrintName()
b. GameName()
c. GameCategory()
d. SetName()
CS 211 - Programming Practicum
Final Exam - Review Document
class HomeAppliance {
public:
void SetDetails(string name, string id) {
appName = name;
appID = id;
};
void PrintDetails() {
cout << "Appliance Name: " << appName << endl;
cout << "Appliance ID: " << appID << endl;
};
protected:
string appName;
string appID;
};
void PrintDetails () {
cout << "Appliance Name: " << appName << endl;
cout << "Appliance Price: $" << appPrice << endl;
};
private:
double appPrice;
};
int main() {
Blender newBlender;
newBlender.SetDetails("MyBlender", "VS213");
newBlender.SetPrice(145.50);
newBlender.PrintDetails();
return 0;
}
a. Appliance Name: MyBlender
Appliance ID: VS213
b. Appliance Name: MyBlender
Appliance Price: $145.5
c. Appliance Name: MyBlender
Appliance ID: VS213
Appliance Name: MyBlender
Appliance Price: $145.5
d. Appliance Name: MyBlender
Appliance Price: $145.5
Appliance Name: MyBlender
Appliance ID: VS213
CS 211 - Programming Practicum
Final Exam - Review Document
int main() {
SoccerPlayer newPlayer;
newPlayer.SetName("Jim Allen");
return 0;
}
a. newName.SetName();
b. SetName(newName);
c. Player::SetName(newName);
d. SoccerPlayer::SetName(newName);
int main() {
vector<Player*> soccerTeam;
Player* playerPtr;
Forward* forwardPtr;
soccerTeam.push_back(playerPtr);
soccerTeam.push_back(forwardPtr);
for (int i = 0; i < soccerTeam.size(); ++i) {
PrintInfo(soccerTeam.at(i));
}
}
a. No polymorphism
b. Compile-time
c. Virtual
d. Runtime
CS 211 - Programming Practicum
Final Exam - Review Document
int main() {
Player* newPlayerPtr = new Player();
Player currentPlayer;
newPlayerPtr->name = "Tim";
currentPlayer.substituteWith(newPlayerPtr);
return 0;
}
a. Calling player Tim
b. This player is called at runtime – Tim
c. No player to call!
d. Error: runtime error
51. A(n) ___ guides the design of subclasses but cannot be instantiated as an object.
a. child class
b. base class
c. abstract class
d. derived class
class Computer {
protected:
string brand;
int RAM;
public:
virtual void PrintInfo() = 0;
};
int main() {
Laptop myLaptop;
Computer myComputer;
myLaptop.PrintInfo();
}
a. Laptop myLaptop generates an error as Laptop is an abstract class and cannot be instantiated.
b. myLaptop.PrintInfo() generates an error as PrintInfo is a member of the Computer class.
c. Computer myComputer generates an error as Computer is an abstract class and cannot be
instantiated.
d. virtual void PrintInfo() = 0 generates an error as the method definition is missing in this class.
CS 211 - Programming Practicum
Final Exam - Review Document
class Building {
protected:
string name;
int area;
double cost;
public:
virtual void GetDetails() = 0;
};
int main() {
School mySchool;
Mall myMall;
}
a. The code will compile but not generate output.
b. The code will compile but will generate a runtime error.
c. The code will not compile as the pure virtual function is not overridden in the
derived classes.
d. The code will not compile as the base class Building has not been instantiated.
CS 211 - Programming Practicum
Final Exam - Review Document
class Person {
public:
virtual void PrintInfo() = 0;
void PrintInformation() {
cout << "in base class Person" << endl;
}
protected:
string name;
int age;
};
int main() {
Teacher mathTeacher;
mathTeacher.PrintInfo();
return 0;
}
a. in base class Person
b. in child class Teacher
c. in child class Teacher
in base class Person
d. in base class Person
in child class Teacher
class Teacher {
string name;
int experience;
string forGrades;
};
class School {
vector<Teacher> teachers;
};
a. Student-Grade
b. Teacher-Student
c. School-Teacher
d. School-Student
60. In the following UML class diagram, + CalculateScore(): int depicts a ___.
a.
b.
c.
d.
CS 211 - Programming Practicum
Final Exam - Review Document
62. Which UML diagram best represents the relationship depicted in the following code?
class Person {
protected:
string name;
int age;
public:
virtual void PrintInfo() = 0;
};
a.
b.
c.
d.
CS 211 - Programming Practicum
Final Exam - Review Document
Exception Handling
int main() {
TimeHour(24);
return 0;
}
a. Invalid Hour!
Time Left: 0
b. Oops
Invalid Hour!
c. Oops
Invalid Hour!
Time Left: 0
d. Invalid Hour!
Oops
CS 211 - Programming Practicum
Final Exam - Review Document
try {
while (!value) {
if (weight > 30) {
throw runtime_error("Double Max Weight");
}
if (weight > 15) {
throw runtime_error("Excess Weight");
}
value = true;
cout << "Accepted" << endl;
}
}
int main() {
BaggageWeight(42);
return 0;
}
a. Accepted
b. Double Max Weight
Accepted
c. Double Max Weight
d. Double Max Weight
Excess Weight
int GetDay() {
int inDay;
cout << "Enter Day: ";
cin >> inDay;
int main() {
int userDay;
int userMonth;
try {
userDay = GetDay();
cout << "Valid Date: " << userDay << endl;
}
catch (runtime_error &excpt) {
cout << excpt.what() << endl;
}
return 0;
}
a. throw logic_error("Invalid Day.")
b. throw runtime_error("Invalid Day.")
c. throw variable_error("Invalid Day.")
d. throw range_error("Invalid Day.")
CS 211 - Programming Practicum
Final Exam - Review Document
int main() {
int value = 2;
try {
if(value == 1)
throw 2;
else if(value == 2)
throw '2';
else if(value == 3)
throw 2.0;
}
catch(int a) {
cout << "\n Variable type 1 exception caught.";
}
catch(char ch) {
cout << "\nVariable type 2 exception caught.";
}
catch(double d) {
cout << "\nVariable type 3 exception caught.";
}
cout << "\nEnd of program.";
}
a. Variable type 1 exception caught.
End of program.
b. Variable type 2 exception caught.
End of program.
c. Variable type 3 exception caught.
End of program.
d. End of program.
CS 211 - Programming Practicum
Final Exam - Review Document
69. If an object of type ExcptType2 is thrown, how many catch blocks will execute?
// ... means normal code except for the catch argument
...
try {
...
throw objOfExcptType1;
...
throw objOfExcptType2;
...
throw objOfExcptType3;
...
}
catch (ExcptType1& excptObj) {
// Handle type1
}
catch (ExcptType2& excptObj) {
// Handle type2
}
catch (...) {
// Handle others (e.g., type3)
}
... // Execution continues here
71. Which of the following statements about code review is NOT true?
a. In industry, code reviews are typically required before newly developed code is
put into production.
b. Code reviews are a good way to catch logic errors and missed edge cases.
c. Code reviews check newly developed code for the desired functionality and
proper style.
d. Code review is only an academic exercise; it is not a practice commonly done in
industry.
72. Which of the following is a component of newly developed code that is commonly
reviewed in a code review?
a. Functionality – does code behave as expected/desired?
b. Complexity – could the code be made simpler?
c. Tests – does the code have well-designed automated tests?
d. Style – does the code follow the organization’s style guidelines?
e. All of the above are an important part of a code review.