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.
-
Write a complete C++ program that would display your name on the screen.
-
Declare the variables I and J as integer, Alpha and Beta as character,
Apple as a real value, and Name as a string.
-
Write a statement that would multiply the values of I and J and assign
the result to I.
-
Write a statement that would increment the variable Count by one if the
value of Alpha is less than 100.
-
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.
-
Write a sequence that would read exactly 5 numbers from the keyboard and
multiply them.
-
Write a function that would return the area of a rectangle when its length
and width are given as parameters.
-
Write a sequence of statements that would prompt the user for his name
and read his name from the keyboard.
-
Declare RandomArray as an integer array containing 10,000 elements.
-
Write a procedure (void function) that would fill an integer array with
N random numbers.
-
Write a statement that would declare a text file variable.
-
Write a statement that would open a text file for output.
-
Write a statement that would write element J of the array RandomArray to
the opened text file then write an end of line character.
-
Write a statement that would close a text file.
-
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.
-
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.
-
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?
-
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.
-
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?