1) What do exceptions allow us to separate? Give an example of when this separation is appropriate.
2) Explain what the idea that main() should tell a story means, particularly in procedural programming.
3) Function swapTwo() below is used by which method: pass by value or pass by reference? Explain what is the main difference between two methods.
void swapTwo(int& a, int& b){
int tmp = a;
a = b;
b = tmp;
}
4) How many types of overloading in C++? Give examples to illustrate.
5) The following code segment fails to initialize the array elements to 1. State the usage of the keyword auto. Rewrite the code segment so that it could work.
int *ptr = new int[7];
for(auto& x : ptr)
x = 1;
6) Show two ways to insert “comments” in C++ code
7) An array name is often considered as a “constant pointer” to an array. Consider the following statements and state whether there is any difference in terms of the byte size of ptr1 and ptr2.
int ptr1[5];
int * const ptr2 = new int[5];
8) What a loop in C++ is used for and when you would use one?
9) What is the role of a makefile? How to produce a makefile?
10) What are the roles of constructors and destructors, related to the lifetime of an object? Give an example header for a constructor and destructor for a class X.
11) How do static and dynamic libraries differ? Give one advantage of using each.
12) What does it mean to provide .h and .o files to a “client”? Why would we do this?
13) State one advantage of smart pointers (not iterators from STL) over regular pointers.
14) Explain the idea of class templates being blueprints of blueprints.
15) Describe a scenario where the use of an STL vectormakes more sense than the use of an STL
deque, STL set or STL map. Justify your answer.
16) Describe advantages of using a container class rather the classical array.