Sample exam Part I  (2 hours and 50 minutes)

 

1.     Write a complete C++ program that follows the following specifications.  The program keeps reading in positive integers and storing them in an array called intArray until a negative integer is read in.  You may assume that the total number of positive integers will never be greater than 100.  The program then calls a function called average, which takes intArray  and the number of positive integers read in as arguments and returns the average of the positive integers stored in the array.   The main prints the value returned by average to the screen.  . (JUST WRITE CODE; NO DOCUMENTATION REQUIRED!)

 

2.  You will be given a file called Test.cpp and a header file called IntStack.h.  IntStack.h contains the declarations and definitions for a class called IntStack that implements a stack using a linked list of nodes.  A node contains an integer for data and a pointer to the next node, and is implemented with a struct called NodeType.   The following is defined for the IntStack. 

a constructor

a destructor,

a Push function with an integer parameter ( the given integer is pushed onto the stack )

a Pop function that returns the integer popped from the stack

a boolean isEmpty function that tests if the stack is empty or not

 

Write a file called IntStack.cpp that contains the function definitions (all the implementations) so that the class can be tested using Test.cpp.

 

3.  Add  a Print function to the IntStack class that prints the elements in the stack from the top down.  The stack should remain unchanged.  Make the function recursive.

 

Sample exam Part II ( 2 hours and 50 minutes )

You are given files containing templates for a StackType, a QueueType, and a BinarySearchTreeType.  There is also a file called Record.h that holds the declarations and definitions for a Record class that contains information about a student.  All function bodies are given except for the overloading of the operators “<” and “>”.   Write a well documented main program in a file called sort.cpp that takes a sequential binary file called Student.dat that contains records of the given class, then prints a menu that asks the user to choose among 4 options:  to print out to the screen a list of student information in same order as in Student.dat, to print out the same information ordered by the student ID, and to write out the records sorted by student IDs a binary file called StudentID.dat, and to quit the program.   This will be interactive with the program performing whatever task is chosen, and asking for the next choice until the user chooses to quit.   You may use any, all or none of the templates given to you.   If you use the binary search tree, you will need to write the appropriate code for overloading the two comparison operators.  If you do not wish to use the binary search tree, you can comment out the comparison operators in the Record.h. 

The exam diskette should contain sort.cpp, the revised Record.h, and any other files that may be needed out of those given.