Use as much paper as you wish, but make your answers are legible.
Please label your answers with the question number.
Please answer each question thoughtfully and carefully.
Algorithm
[3 points] Give the definition for an algorithm
[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])
Arrays
[2 points] Give the syntax for declaring an array. (Do not give code)
[2 points] Give example code which declares an array.
[2 points] Name two characteristics of an array.
[2 points] List two different types of operations that can be performed on integers but not arrays.
[2 points] List two different types of operations that do not behave as expected when performed on arrays.
Passing arrays to functions
[2 points] Why are arrays passed by reference by default?
[2 points] What alternative method is there to passing an array by reference? (the next two questions refer to this method)
[3 points] Give the function prototype for a Find function which is passed an array with the method described in the previous question.
[3 points] Describe what happens if an array, passed using the previous method, is modified in a function.
Modular Compilation Usage
[3 points] Give three benefits that can be derived from placing code in different files.
[3 points] Given an example of a guard which should be placed in a header file?
[2 points] Why should a guard be placed in a header file?
[2 points] What type of code should be placed in a header file?
Over Please
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.
[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
[3 points] Label your diagram, in all applicable locations, with the following processes:
Preprocessor
Compiler Proper
Linker
[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).