Professional Documents
Culture Documents
Instructions:
This is a taken-home final for this special stay-at-home semester. I cannot control what resources or
methods you will use. You may refer to assignments, textbook, class notes on Bb, sample programs on
ares/Unix and search on Internet. But I want you to keep academic honesty here for one thing: Do this
test all by yourself.
Please use blue color for your answers. I will use red color for grading with comments. Submit your
finished final doc on Bb. Rename this file with your login as you did with your program assignments.
Like Written Homework #2, I will grade your submission and attach a graded copy.
17. What library is needed in order to use setprecision() for cout? __________________
18. What class is needed in order to open a file for read-only? __________________
19. If a function is very short and we want to avoid overhead of function calling, we make this
function to be _________________.
Course: CSC122-002 Page 2 of 3
Semester: Spring 2020
Instructor: Jin Guo, updated: 05/14/202020
23. List the four factors which affects the running time of a sorting algorithm:
24. The following code adds two Point objects. Use a pointer variable to do the same.
Point p1(1.3, 3.4), p2(2.3, 4.5);
p1.add(p2);
25. Given an 8-bits CPU, what would be the result of the following?
unsinged char k = 0x0F, m = 0xA9;
k ^ m =
26. Call the function below to print out the max of int variables a1, a2 and a3.
int maxOf3Ints(int* i, int* j, int* k);
27. What’s the mechanism in a .h file to avoid this file to be included more than once?
28. Use the new operator to allocate 10 bytes to a char pointer variable, then copy “Hello!” to this
pointer.
29. cin is standard input (usually means keyboard). What class does this object belong to?
30. Create a vector of 10 Student objects using the default constructor of Student class.
32. For the given two function prototypes, write a function template to replace these two functions.
int minOfThree(int i, int j, int k);
doubt minOfThree(dobule i, double j, double k);
33. Please check which of the following function(s) can be used to swap two integers.
(1) void swap1(int a, int b);
(2) void swap2(int& a, int& b);
(3) void swap3(int* a, int* b);
(4) void swap4(const int& a, const int& b);
34. Please check which three of the following for function add(..) are overloaded versions.
(1) double add(int n, double x);
(2) void add(int n, double x);
(3) double add(int n, char c);
(4) string add(string s1, string s2);
35. Given a class Date, we use operator + to mean a date plus some days, e.g., July 20 + 5 is July 25.
Please write down the prototype (no function body!) of overloading of operator + applied to class
Date and an integer. (Notes: this operator+ overloading is not a member but a friend function of
Date.)
Course: CSC122-002 Page 3 of 3
Semester: Spring 2020
Instructor: Jin Guo, updated: 05/14/202020
36. Declare function fun(..) which takes an integer parameter passing by reference, a double
parameter passing by value with default value of 10.0, an integer vector passing by constant
reference and return a boolean value.
37. Points out which statements are wrong in the following code and explain why (Refer to
Assignment 11).
Student s1("David", "Smith", 3.3);
ForeignStudent fs("Lisa", "Lin", “Italy”, 350);
38. Please give average case big-O’s for the following (Refer to CSC121 Class Note 5 on Bb)
select-sort for ordered data:
merge-sort for random data:
bubble-sort for random data:
binary-search for ordered data:
40. The following function has the same definition as the overloaded operator “<<” for Point class
(Refer to Assignment 5). Please use it to write only one statement to print out two Point objects
p1 and p2 in order on screen. Don’t worry about spaces between the two.
ostream& outputPoint(ostream &output, const Point &p); // a friend of Point