This assignment involves the use of a struct and a random access binary file. You will create the user interface which lets the user store and retrieve records. Each record in the file has the following fields:
Implement the following pseudocode:
Define a struct that matches the description of the record above.
main:
Declare any needed local variables.
Create a variable to store one record.
// The complicated logic in this section takes care of the
// case when the file does not initially exist.
open the file "rafile.bin" for binary input and output
if it did not open then
// File did not exist so create it
open the file "rafile.bin" for binary output
if the file opened then
// File exists now, so reopen for input and output
close the file
open the file "rafile.bin" for binary input and output
otherwise
// File still does not exist, so end the program
display an error message (file could not be opened)
exit with an error status
find out how many records are in the file and store that in numRecs
display the number of records that are in the file
do the following
display a menu as shown in the sample runs provided with this assignment
get the user's choice and convert it to lowercase
if the user chose to read a record then
ask for a record number
if that record number does not exist then
display an error message
otherwise
read that record and display it (with 2 decimals for price)
otherwise if the user chose to append a record then
get an id, price, and quantity from the user and store it in a record
write that record to the end of the file
increase the numRecs variable
display which record number was written to the file
otherwise if the user chose to quit then
do nothing
otherwise
display an error message for invalid option chosen
while the user has not chosen to quit
close the file
exit with a success status
There are 0 records in the file r) read a record a) append a record q) quit Enter your choice: d Invalid choice. Try again. r) read a record a) append a record q) quit Enter your choice: r Record number to read: 0 Error: Invalid record number. r) read a record a) append a record q) quit Enter your choice: r Record number to read: 1 Error: Invalid record number. r) read a record a) append a record q) quit Enter your choice: a Enter an ID: 33 Enter a price: 13.1 Enter a quantity: 2 Record 1 written to file r) read a record a) append a record q) quit Enter your choice: 7778 Invalid choice. Try again. r) read a record a) append a record q) quit Enter your choice: Invalid choice. Try again. r) read a record a) append a record q) quit Enter your choice: Invalid choice. Try again. r) read a record a) append a record q) quit Enter your choice: Invalid choice. Try again. r) read a record a) append a record q) quit Enter your choice: a Enter an ID: 7778 Enter a price: 45.626 Enter a quantity: 1 Record 2 written to file r) read a record a) append a record q) quit Enter your choice: r Record number to read: 1 33: $13.10 (2) r) read a record a) append a record q) quit Enter your choice: r Record number to read: 2 7778: $45.63 (1) r) read a record a) append a record q) quit Enter your choice: q