Final Exam Programming Questions

Random Number Guessing Game

Write a program that generates a random number in the range of 1 through 100, and asks the user to guess what the number is. If the user's guess is higher than the random number, display "Too high, try again." If the user's guess is too low, display "Too low, try again." In both cases, let the user continue guessing until they get it right. If the user guesses the number, the application should congratulate the user and then generate a new random number so the game can start over.

Be sure to validate the user's input. The user should be asked again whenever they enter invalid input.

Positive Values

Write a PositiveValues class. This class stores a collection of positive numbers and must support the operations shown below. Be sure to address all data aggregation security concerns.

Reading from a file

Write a program that reads values from a file. You may assume there is one value per line. For each value:

Once the file is read, print out the total.

Use exception handling to determine the type of value read in.

Triangle

Write a Triangle class that represents a triangle by its three sides. Allow the user of the class to set each side of the triangle and get the length of each side. Define the appropriate equality special method and define equal triangles as congruent triangles. Congruent triangles are triangles where each side of triangle A is exactly the same as the corresponding side of triangle B.

Define the appropriate string special method to convert the triangle object into a string (containing the length of each side).

Allow the user of the class to get the area of the triangle (using Heron's formula).

Be sure to validate all input and use exception handling when appropriate.

Capital Quiz

Write a program that creates a dictionary containing the US states as keys and their capitals as values in a dictionary. The program should then randomly quiz the user by displaying the name of a state and asking the user to enter the state's capital. The program should keep track of how many correct and incorrect responses the user enters. Once the quiz is over, display the percent correct.