0% found this document useful (0 votes)
6 views8 pages

15 Homework - Files, Part 2

The document outlines an assignment for CIS 236 that requires students to create a movie tracking system using a binary file in C. It specifies the functions that must be implemented, such as adding, deleting, and updating movie records, as well as displaying a menu for user interaction. Extra credit is available for adding genre information to the movie structure, and the document includes detailed requirements for each function and the overall project submission guidelines.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views8 pages

15 Homework - Files, Part 2

The document outlines an assignment for CIS 236 that requires students to create a movie tracking system using a binary file in C. It specifies the functions that must be implemented, such as adding, deleting, and updating movie records, as well as displaying a menu for user interaction. Extra credit is available for adding genre information to the movie structure, and the document includes detailed requirements for each function and the overall project submission guidelines.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

CIS 236 – Programming in C

15 Homework – Files, Part 2


25 points
Description
Write a movie tracking system that handles information about movies, using a binary file.
This assignment is a continuation of Homework Week 13 and Homework Week 14. If you have not
finished those assignments, do that first.
You must use functions as described in the requirements below.
Extra credit is available for this assignment.
Learning Objectives
 Create a binary file
 Write to a binary file
 Read a binary file sequentially
 Update a record in a binary file randomly
 Display a menu until the user chooses to exit

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

Requirements for the addMovie Function


Purpose: This function prompts the user for movie information and adds this information to the
file.
Parameters: File pointer as an input parameter
Algorithm: 1. Create a structure to store the data the user provides.
2. Prompt the user for the name of the movie as a string which may include spaces.
Display a message if the length of the movie title exceeds 25 characters. Always set
the last element in the string (a char array of size 26) to the null character,
regardless of the length.
3. Prompt the user for the number of downloads of this movie.
4. Use repetition to locate the first available empty record in the file and write the
structure to that location.
5. Display a message confirming the addition of the movie.
6. Display an error message if there are no openings in the file. Do not add to the end
of the file!
Return value: None

Requirements for the deleteMovie Function


Purpose: This function prompts the user for the record number of the movie to delete, and then
replaces that record with a blank record.
Parameters: File pointer as an input parameter
Algorithm: 1. Create a movie structure with default values.
2. Prompt the user for the record number of the movie to delete. Validate that the
number is between 1 and 10. Continue prompting if necessary, until the user types
in a number between 1 and 10.
3. Delete the appropriate record from the file by replacing it with the blank structure.
Remember that record numbers in a binary file are similar to the indexes to an array.
4. Display a message confirming the delete.
Return value: None

Requirements for the updateMovie Function


Purpose: This function prompts the user for the record number of the movie to update, prompts
the user for new information, and then replaces that record with updated values.
Parameters: File pointer as an input parameter
Algorithm: 1. Prompt the user for the record number of the movie to update. Validate that the
number is between 1 and 10. Continue prompting if necessary, until the user types
in a number between 1 and 10.
2. Locate the appropriate record from the file and read it into a structure. Remember
that record numbers in a binary file are similar to the indexes to an array.
3. Display the current values of the record.
4. Prompt the user for the updated name of the movie as a string which may include
spaces. Display a message if the length of the movie title exceeds 25 characters.
Always set the last element in the string to the null character, regardless of the
length.
5. Prompt the user for the updated number of downloads of this movie.
6. Write the updated structure back to its original location.
7. Display a message confirming the update.
Return value: None

Requirements for the displayMovieInfo Function


Purpose: This function displays the contents of the file.
Parameter: File pointer as an input parameter
Algorithm: Use a loop to read each record in the file and display it neatly to the screen. Do not
display empty records. Display a record number for each movie (starting at 1).
Remember that record numbers in a binary file are similar to the indexes to an array.
Return value: None

Requirements for the displayMenu Function


Purpose: This function displays a menu of options to the user. It reads the option typed by the
user and returns that value to main.
Parameters: None
Algorithm: Display the following menu and prompt to the user:

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

Extra Credit 1 – Add Genre to the Movie Information


Max points 10 – If you have not added this extra credit to both of the previous homework
assignments.
Max points 5 – If you have added this extra credit to either one of the previous homework
assignments.
Add information about genre to the movie information data.
The genre is stored as an enumerated type in the structure, using these enumeration constants, in this
order: action, animation, drama, sci-fi, superhero.
Prompt for the genre (as a number) in addMovie and updateMovie. This function must also check that
the value entered for the genre is within the correct range for the enum values (as noted above). Your
code must continue to ask the user for a valid genre, as in the sample run. The check must use the
enum constants, not the numbers represented by the enum constants.
The displayMovieInfo must use a selection statement to determine which genre text to print.
Remember, the genre for each movie is stored as an enum value, not as a string. Your output should
display actual words, like Action or Drama.
Sample Run – Required
NOTE – The heading “Movie Information System” is bolded in the sample
run, just for clarity. You do not have to make this text bold.

Movie Information System

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): Oppenheimer


Number of downloads: 10000000
Movie added successfully

Movie Information System

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

Movie Information System

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

Movie Information System

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

Current title: Star Wars: Episode V


Current downloads: 3000000
Updated title: The Little Mermaid
Updated downloads: 3000
Movie updated successfully

Movie Information System

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 The Little Mermaid 3000

Movie Information System

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

Movie Information System

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

Movie Information System

1. Add a movie
2. Delete a movie
3. Update a movie
4. Display all movies
5. Exit

Your choice: 5

Requirements for Full Credit on This Project


1) COMPLETE AND ACCURATE
Your program must include all required components and techniques as noted above. It must
compile, execute, and give accurate output.
2) FOLLOW ALL REQUIREMENTS ACCORDING TO THE INSTRUCTIONS.
Follow the instructions as written for completing this project, even if you [think you] know a
“better” way to do something.
3) COMMENTS
There must be a comment at the top of your source code file that includes your name, the
assignment number, and a short description of the program. Additionally, every function, control
structure, executable statement and variable declaration must be described with a comment. This
does not include whitespace or lines that contain only curly braces.
4) BEST PRACTICES
Follow best practices in C programming. These include, but are not limited to, the following:
 Appropriate use of white space and alignment
 Meaningful variable names and appropriate naming conventions
Points will be deducted for sloppy code that is hard to read, even if it works, so pay attention to
these details.
5) SUBMIT ALL FILES BEFORE THE DUE DATE
See the due date for this assignment on the course calendar in Canvas and review the submission
requirements below.
6) ALL SUBMISSIONS MUST BE YOUR OWN WORK
Review the syllabus regarding plagiarism and the Joliet Junior College Academic Honor Code.
BY SUBMITTING ANY ASSIGNMENT, YOU ARE STATING THAT YOUR SUBMISSION IS YOUR OWN WORK
AND IS NOT PLAGIARIZED IN ANY FORM.
SUBMISSION
Submit your C source code file with the .c file extension to the drop box.
I will not accept links to online storage. You must submit the actual file. Do not submit an entire IDE
project.

Remember – do not ask time-sensitive questions as a comment in the drop


box. If you need help, contact me directly before the assignment is due.

You might also like