CSCI 203 Final Exam Review Questions




Most questions for the final exam will be taken from/similar to/based on the following, and on labs and projects from this semester, assigned readings from Mercer (see especially the self-check questions), "Persuasive Programming", and lectures. The final will be cumulative so be sure to study the review sheets from the earlier exams!
 
1. Identify the following:

2. Write a sequential search function that operates on a vector of strings. It should return the position of the first string in the vector which contains more than 5 characters. If there are no such words in the vector, a reasonable value should be returned to indicate that.

3. Declare the enumerated type coinT that consists of the values penny, nickel, dime, and quarter.

4. Write the pre- and postconditions for binary search.

5. Write the C++ code for a binary search function on a vector of integers.

6. What are the function abstractions we used in writing insertion sort (there were 3)? List them, along with the pre- and postconditions for each.

7. In a selection sort one repeatedly traverses the part of the vector not yet sorted looking for the largest value. When that value is found it is swapped with the value at the end of the currently unsorted part. This continues until the unsorted part is of length one.

Write the C++ code for a selection sort function that sorts a vector of doubles. Implement helper functions where appropriate (as done with the insertion sort).

8. Draw the state diagram for a finite state machine that counts the number of words in a file (for the purposes of this problem, a word is a contiguous sequence of non-whitespace characters that is preceded and followed by whitespace characters). Write a program to open a file named wordfile, count the number of words in it, and print out a message giving this number and stating what it is.

9. Draw the state diagram for a finite state machine for the following problem: The purpose of the machine is to detect sequences of three heads in a series of coin flips. The inputs to the machine are coin flips, which are either heads or tails. The machine should detect a sequence of three heads in a row; when such a sequence is detected, it should print out a message "Three heads! You win.", but if a sequence of heads starts and finishes short of 3, the a message "You loose." is printed. Once three head have been detected, the game starts over with a message "New Game!".

10. Write the C++ implementation of the state machine you designed in the preceding problem. You need to supply the enumerated types appropriate for the problem.

11. Why do we want to specify the weakest possible condition as a function's precondition and the strongest possible condition as its postcondition?

12. Review how you used a random number generator to solve various problems in lab and in project 8.

13. Do problems 10E, 10F, 10G in Mercer. OK -- don't actually do them, but look at them and think about the vector algorithm which would be at the heart of the problem.