Test II, CSCI 230, Fall 2020


  1. Arrays
    1. [3 points] What are arrays? Provide a high level definition.
    2. [2 points] State the syntax (not an example) for declaring an array in c++.
    3. [4 points] State two conditions which suggest to a programmer that an array is needed.
    4. [2 points] What is an array index out of bounds error?
    5. [6 points] What happens when an array index out of bounds error occurs? List all possible results.
    6. [5 points each] Describe any errors in the following code segments
      1. size_t size;
        cout << "Enter the array size ";
        cin >> size;
        cout << endl;
        
        int ary[size]; 
      2. const size_t MAX_SIZE =10;
        
        int main() {
            int ary2[MAX_SIZE]{0};
            size_t i;
        
            for(i =0; i <= MAX_SIZE; i++) {
               cout << ary2[i] << " ";
            }
            cout << endl; 
  2. Sorting and Searching
    1. [3 points] Give a high level algorithm for insertion sort (explain what the algorithm does, do NOT supply code or near code pseud-code.)
    2. [5 points] Write a function called CheckArray that takes an array of integers and the size of the array. This function should return true if the array is in increasing order and false otherwise.
      bool CheckArray(const int array[], size_t size) { 
  3. Algorithm Performance and Complexity
    1. [2 points] Name an algorithm that is $O(n)$ and an algorithm that is $O(n^2)$.
    2. [4 points] In terms of data, what does it mean for an algorithm to be $O(n)$ and $O(n^2)$
    3. [4 points] Which algorithm listed in part A does this code behave most like computationally?
      • int Fibonacci(int limit){
            int old = 1;
            int current = 1;
            int sum = 1;
            int i;
        
            for(i = 2; i <= limit; i++) {
                sum = old+current;
                old = current;
                current = sum;
            }
        
            return sum; 
        }
  4. Compiling
    1. [2 points] Name two benefits of breaking a program into multiple files.
    2. [1 point each] Describe the purpose and function of each of the following in the compilation process.
      • C++ preprocessor
      • C++ compiler proper
      • C++ linker.

Submission Instructions