15 Homework - Files, Part 2
15 Homework - Files, Part 2
Function Requirements
Your code must use these functions, using these names (in addition to main):
1. addMovie
2. deleteMovie
3. displayMenu
4. displayMovieInfo
5. openFile
6. updateMovie
Structure Requirements
The structure requirements are the same as homework 13 & 14:
The information for a movie must be stored in a structure containing the title of the movie (a string of
size 25 + 1 position for the null character) and the number of downloads. Be sure to use the
appropriate data type for the number of downloads.
Requirements for main:
1. Call the openFile function.
2. Call the displayMenu function. Use the return value to determine if the loop in step 3 should
execute.
3. Using a loop that executes until the user chooses to exit:
a. Use a selection structure to determine which function to call:
i. If the user chose 1, call addMovie
ii. If the user chose 2, call deleteMovie
iii. If the user chose 3, call updateMovie
iv. If the user chose 4, call displayMovieInfo
v. If the user chose 5, exit the loop.
vi. If the user chose an invalid option, display an error message.
b. Call the displayMenu function.
4. After the loop, close the file.
Requirements for the openFile Function
Purpose: This function creates a binary file, closes it, and then opens it for updating.
Parameters: None
Algorithm: 1. Open a binary file called “movies.dat” for writing, using the file mode “wb”. Be sure
to check that the file opened successfully.
2. Create a movie structure with default values and use this structure to initialize the
file with 10 blank records.
3. Close the file.
4. Open the same file for reading and writing, using the file mode “rb+”. Be sure to
check that the file opened successfully.
5. Return the file pointer as a return value.
Return value: The file pointer
1. Add a movie
2. Delete a movie
3. Update a movie
4. Display all movies
5. Exit
Your choice:
Return value: Integer indicating user’s choice
1. Add a movie
2. Delete a movie
3. Update a movie
4. Display all movies
5. Exit
Your choice: 1
1. Add a movie
2. Delete a movie
3. Update a movie
4. Display all movies
5. Exit
Your choice: 1
Title of movie (max 25 chars): Star Wars: Episode VII - The Force
Awakens
Title exceeds 25 characters and will be truncated
Number of downloads: 3000000
Movie added successfully
1. Add a movie
2. Delete a movie
3. Update a movie
4. Display all movies
5. Exit
Your choice: 4
Number Title Downloads
===== ===== =========
1 Oppenheimer 10000000
2 Star Wars: Episode V 3000000
1. Add a movie
2. Delete a movie
3. Update a movie
4. Display all movies
5. Exit
Your choice: 3
Movie to update: 2
1. Add a movie
2. Delete a movie
3. Update a movie
4. Display all movies
5. Exit
Your choice: 4
1. Add a movie
2. Delete a movie
3. Update a movie
4. Display all movies
5. Exit
Your choice: 2
Movie to delete: 2
Movie deleted successfully
1. Add a movie
2. Delete a movie
3. Update a movie
4. Display all movies
5. Exit
Your choice: 2
Movie to delete: 2
That movie does not exist
1. Add a movie
2. Delete a movie
3. Update a movie
4. Display all movies
5. Exit
Your choice: 5