Test I, CSCI 230, Spring 2020


  1. Algorithm
    1. [3 points] Give the definition for an algorithm
    2. [2 points] Your friend proposes the following to sort an array. Is it an algorithm? Why or why not?
      LuckySort   
      Input: an array ary and the size of the array  size
         while ary is not in order    // assume you have a function to test this 
            let i be a random integer between 0 and size-1
            let j be a random integer between 0 and size-1
            swap(ary[i],ary[j])
      

  2. Arrays
    1. [2 points] Give the syntax for declaring an array. (Do not give code)
    2. [2 points] Give example code which declares an array.
    3. [2 points] Name two characteristics of an array.
    4. [2 points] List two different types of operations that can be performed on integers but not arrays.
    5. [2 points] List two different types of operations that do not behave as expected when performed on arrays.

  3. Passing arrays to functions
    1. [2 points] Why are arrays passed by reference by default?
    2. [2 points] What alternative method is there to passing an array by reference? (the next two questions refer to this method)
    3. [3 points] Give the function prototype for a Find function which is passed an array with the method described in the previous question.
    4. [3 points] Describe what happens if an array, passed using the previous method, is modified in a function.

  4. Modular Compilation Usage
    1. [3 points] Give three benefits that can be derived from placing code in different files.
    2. [3 points] Given an example of a guard which should be placed in a header file?
    3. [2 points] Why should a guard be placed in a header file?
    4. [2 points] What type of code should be placed in a header file?

    Over Please

  5. Modular Compilation Process
      A program is split between three files. A main routine in main.c , a header file utils.h, and an implantation file utils.C.
    1. [7 points] Draw a diagram showing the process where these files will be compiled into a single executable. Place the files listed above, along with the following terms in your diagram where appropriate.
      • System Header Files
      • System Library Files
      • Intermediate Source Code
      • Object file
      • Executable
    2. [3 points] Label your diagram, in all applicable locations, with the following processes:
      • Preprocessor
      • Compiler Proper
      • Linker

  6. [5 points] Provide the full source code for a function which takes a string and returns a copy of that string with all non-alphabetic characters removed. (Do not provide code for the entire program, just a function).