Sample Examination I
Data Structures

The first major data structures examination will be given on February 8th.  The following is a sample of what the examination might be like.  Most of the questions on the examination will be similar to these questions.
  1. Write a complete C++ program that would display your name on the screen.
  2. Declare the variables I and J as integer, Alpha and Beta as character, Apple as a real value, and Name as a string.
  3. Write a statement that would multiply the values of  I and J and assign the result to I.
  4. Write a statement that would increment the variable Count by one if the value of Alpha is less than 100.
  5. Using a while loop, write a sequence of statements that would read the value of Alpha from the keyboard and add its value to SUM.  Exit the loop when the value entered for Alpha is zero.  Be sure that Alpha and SUM have proper values whenever they are used.
  6. Write a sequence that would read exactly 5 numbers from the keyboard and multiply them.
  7. Write a function that would return the area of a rectangle when its length and width are given as parameters.
  8. Write a sequence of statements that would prompt the user for his name and read his name from the keyboard.
  9. Declare RandomArray as an integer array containing 10,000 elements.
  10. Write a procedure (void function) that would fill an integer array with N random numbers.
  11. Write a statement that would declare a text file variable.
  12. Write a statement that would open a text file for output.
  13. Write a statement that would write element J of the array RandomArray to the opened text file then write an end of line character.
  14. Write a statement that would close a text file.
  15. Write a procedure that would write N elements of a real array to a text file.  The parameters of the procedure are the name of the file (a string), the real array, and the number of ellements to be written.
  16. Consider the following list of numbers: 23, 34, 56, 12, 18, 24, 78, 41
    This array is to be sorted from largest to smallest using the bubble sort.  Give the array after each of the first four passes.
  17. Write a procedure that would sort a real array of N elements from smallest to largest using the bubble sort.  What would have to be changed in your procedure to sort from largest to smallest?
  18. Consider the following list of numbers: 23, 34, 56, 12, 18, 24, 78, 41
    This array is to be sorted from largest to smallest using the insert sort.  Give the array after each of the first four passes.
  19. Write a procedure that would sort a real array of N elements from largest to smallest using the insert sort.  What would have to be changed in your procedure to sort from smallest to largest?