CIS 260 - Reading binary file data

The objectives of this assignment are:

  1. read binary data from a file
  2. store data as records in an array
  3. validate input
  4. use a loop to control program execution
  5. format output to match sample output

Assignment

Your task is to write a program that reads a file of binary data into an array of records (using an object to hold a record). The user then gets to choose which field of data they want to see and your program displays that data.

  1. Load all of the data from the binary file inflation.bin into an array. Each record consists of the following fields:
  2. Create a loop that asks the user what year and month they wish to view data for. Validate all user input and reprompt when there is invalid data. Show the average rate for the year if the user enters 0 for the month.
  3. The loop should continue until the user chooses to exit. See the sample output for details.

Grading rubric

Note: Program must be able to be compiled and run.

  1. 7 pts: style conventions followed (no tabs, proper indentation, documentation comments)
  2. 10 pts: input data is properly validated
  3. 10 pts: program produces correct results properly formatted with one digit of precision after the decimal point
  4. 15 pts: binary data is properly read and stored in an array
  5. 8 pts: loop works properly to let user choose another rate to display or to quit

Sample output

Enter year you wish to view (1914-2010): hello
Error: Invalid integer
Enter year you wish to view (1914-2010): 08
Error: Integer below minimum value (1914)
Enter year you wish to view (1914-2010): 2008
Enter month (0 for annual average): -9
Error: Integer below minimum value (0)
Enter month (0 for annual average): 8
Monthly rate for August 2008 was 5.4
View another rate? (Y/N) y
Enter year you wish to view (1914-2010): 2008
Enter month (0 for annual average): 0
Annual average for 2008 was 3.8
View another rate? (Y/N) Hello
Invalid choice
View another rate? (Y/N) d
Invalid choice
View another rate? (Y/N) n