You are on page 1of 3

Course: CSC122-002 Page 1 of 3

Semester: Spring 2020


Instructor: Jin Guo, updated: 05/14/202020

Final Test Score n/100:

Student Name: _____________________

Time/Date Issued: Noon Thursday, 5/14/2020


Time/Date Due: Mid-night Friday, 5/15/2020

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.

(2 points each, total 30. Circle your answer.)


1. The growth rate of a function is its derivative. True or false?
2. Every algorithm will grow in time over increasing size of input data. True or false?
3. For ordered data, binary searching has the same average big-O as linear searching. True or false?
4. Binary search can be applied to an int vector either sorted or in random. True or false?
5. If written properly, bubble-sort can stop early when the data become already sorted. True or false?
6. If f(n) = O(g(n)), we can say that f(n) doesn’t grow faster than g(n). True or false?
7. An operator is essentially a function in a special format. True or false?
8. The return type of function is part of function overloading. True or false?
9. A static data member of a class has its instance in every objects of this class. True or false?
10. In a private inheritance, a public member function in parent-class cannot be used by an object
of its child-class. True or false?
11. In a public inheritance, a new member function in child-class can directly access a private
member in its parent-class. True or false?
12. A friend function can only access the public and protected members of the class of which it’s a
friend. True or false?
13. A child-class pointer can take the address of its parent-class object. True or false?
14. Polymorphism is used for dynamic function binding. True or false?
15. An overridden function in a parent-class and its child-classes must have the same function
prototype. True or false?

(2 points each, total 10.)


16. What’s the keyword to implement polymorphism? _____________

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

20. Which big-O grows faster, O(n2) or O(n∙log(n))

(3 points each, total 30.)


21. What’s the worst case big-O for linear search on a sorted vector A of size n?

22. What is the big-O for function f(n) = 7n2 + 2n + 1;

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.

((3 points each, total 30.)


31. Construct an istringstream object with string “11 33”, then read 11 and 33 into int variables k, m.

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);

Student *pt = &s1;


pt->printInfo();
pt = &fs;
cout << pt->getEnglishScore();
ForeignStudent *p2 = &fs;
p2 = &s1;

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:

39. Define a recursive function to evaluate f(x) = xn, where x > 0, n = 0, 1, 2, 3, ….


x is a positive real number and n is positive integer. Here is the function prototype:
double power(double x, size_t n);

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

You might also like