CIS 260 - Reading binary file data
The objectives of this assignment are:
- read binary data from a file
- store data as records in an array
- validate input
- use a loop to control program execution
- 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.
- Load all of the data from the binary file inflation.bin
into an array. Each record consists of the following fields:
- year: an int value
- monthlyRate: a float array of twelve elements
- averageRate: a float containing the average rate for the year
- 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.
- 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.
- 7 pts: style conventions followed (no tabs, proper indentation, documentation comments)
- 10 pts: input data is properly validated
- 10 pts: program produces correct results properly formatted with one
digit of precision after the decimal point
- 15 pts: binary data is properly read and stored in an array
- 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