Midterm Exam, CSCI 330, Fall 2017


  1. [10 points] Draw a diagram that represents the compilation of a multi-file program. Label the parts. Draw a rectangle around all processes and an oval around all files. Please include the following items (items may be used multiple times):
    compilerexecutable linker object code
    preprocessor source code system header file system library
    temporary source codeuser header file

  2. Namespaces
    1. [3 points] Give the code required to declare the function prototype: void PrintWonder(WonderT w); in a namespace called GameDebugging.
    2. [2 points] Give the code required to call the function defined in the previous question. Assume that no using statement has been executed.
    3. [5 points] Why should using namespace std; be avoided in header files?

  3. [5 points] Compare and contrast a standard array in C and a C++ STL array class array.

  4. References
    1. [2 points] What happens when a reference variable is assigned the first time?
    2. [2 points] What happens on subsequent assignments to a reference variable?
    3. [6 points] Draw a diagram that represents the memory and contents of memory after the following code is executed.
      int x = 5;
      int & y = x;
      y = 7;
      

  5. [5 points] A class which allocates dynamic memory should provide a copy constructor. What problems can occur is a copy constructor is not supplied?

  6. Given the following code
    int x = 0;
    try {
        x++;
        AFunctionCall();
        x++;
    } 
    catch (int y) {
        x+=y
    }
    
    Assume that no other catch statements are executed and that somewhere in the call sequence starting at AFunctionCall the statement throw 10; is executed.
    1. [6 points] Describe the flow of control for the above code.
    2. [2 points] What is the value of x when the above code is executed?
    3. [2 points] What would be the result if the call sequence executed the statement throw 1.0; instead of throw 10;?