Question
starter code #include #include #include #include #define MAX_STR_LEN 1024 typedef struct castList_struct { } CastList; // Used to store information about a movie typedef struct
starter code
#include
#define MAX_STR_LEN 1024
typedef struct castList_struct { } CastList;
// Used to store information about a movie typedef struct movieReview_struct {
// IMPLEMENT THIS FIRST - else the code won't compile } MovieReview;
// Used to store a linked list of MovieReview nodes typedef struct reviewNode_struct {
// IMPLEMENT THIS FIRST - else your code won't compile } ReviewNode;
/** * Allocates a new, empty ReviewNode, and initializes its contents with the given values. * * INPUT: * - title: the title of the movie * - studio: the studio where the movie was produced * - year: the year in which the movie was produced * - BO_total: the amount of money this movie grossed at the box office * - score: the average review score given to this movie * * NOTE: - The *next pointer for the new node MUST be set to NULL * * RETURN: * - if something goes wrong, return NULL, * - else: * - the newly allocated node, initialized with: * - node.next
/** * Finds and returns a ReviewNode containing information that matches the input query: * - title * - studio * - year * but if no such ReviewNode exists, returns NULL. * * INPUT: * - title: the title of the movie * - studio: the studio where the movie was produced * - year: the year in which the movie was produced * * RETURN: * - if a review matching the query is found: * the node that contains that review. * - else: * NULL */ ReviewNode *findMovieReview(char *title, char *studio, int year, ReviewNode *head) { return NULL; // Remove this before you implement your solution! }
/** * Inserts a new movie review into the linked list, if it does not exist already. * * INPUT: * - title: the title of the movie * - studio: the studio where the movie was produced * - year: the year in which the movie was produced * - BO_total: the amount of money this movie grossed at the box office * - score: the average review score given to this movie * * OUTPUT: - head: the (potentially new) head of the linked list of reviews * * RETURN: - the (potentially new) head node of the linked list * * NOTE: * - If head == NULL, then the list is still empty * - Inserts the new movie review *at the head* of the linked list * - MUST check that the movie is not already in the list before inserting (there should be no * duplicate entries). If a movie with matching title, studio, and year is already in the list, * nothing is inserted and the function returns the current list head. */ ReviewNode *insertMovieReview(char *title, char *studio, int year, double BO_total, int score, ReviewNode *head) {
return NULL; // Remove this before you implement your solution! }
/** * Returns the length of the linked list that begins at head. * * INPUT: - head: the start of a linked list * * RETURN: - the number of elements in this linked list */ int countReviews(ReviewNode *head) { return 0; // Remove this before you implement your solution }
/** * Updates the review matching the input query: * - title * - studio * - year * with new BO_total and score. * * If no such review is found, the function prints out: "Sorry, no such movie exists at this point" * * INPUT: * - title: the title of the movie * - studio: the studio where the movie was produced * - year: the year in which the movie was produced * - BO_total: the amount of money this movie grossed at the box office * - score: the average review score given to this movie * * OUTPUT: * - head: the (potentially new) head of the linked list of reviews * - error message to the terminal, if no node is found matching given [title, studio, year] query */ void updateMovieReview(char *title, char *studio, int year, double BO_total, int score, ReviewNode *head) { }
/** * Removes a review matching the input query from the linked list, if such review can be found. * * INPUT: * - title: the title of the movie * - studio: the studio where the movie was produced * - year: the year in which the movie was produced * * OUTPUT: - head: the (potentially new) head node of the linked list * RETURN: - the (potentially new) head node of the linked list */ ReviewNode *deleteMovieReview(char *title, char *studio, int year, ReviewNode *head) { return NULL; // Remove this before implementing your solution }
/** * Prints out all the reviews in the linked list and returns the sum of all the box office totals * for all stored movie reviews. * * INPUT: - the head node of the linked list * * RETURN: - the BOX OFFICE TOTAL, for all movies * * NOTE: * - Each field in the review is printed in a separate line, with *no additional text* * - The only thing printed is the value of the corresponding field * - Reviews are separated from each other by a line of "*******************" * whose length is irrelevant, as long as it is >= 2 * - See the Assignment handout for a sample of the output that should be produced by this function */ double printMovieReviews(ReviewNode *head) {
return 0; // Remove this before you implement your solution }
/** * Prints out all the reviews in the linked list which share the production studio given by studio * and then returns the sum of all the box office totals for these such stored movie reviews. * * INPUT: - the head node of the linked list * * RETURN: * - the BOX OFFICE TOTAL, for all the movies that match the query * - the studio attribute of the query: only print and count nodes matching this studio * * NOTE: * - Each field in the review is printed in a separate line, with *no additional text* * - The only thing printed is the value of the corresponding field * - Reviews are separated from each other by a line of "*******************" * whose length is irrelevant, as long as it is >= 2 * - See the Assignment handout for a sample of the output that should be produced by this function */ double queryReviewsByStudio(char *studio, ReviewNode *head) { return 0; // Remove this before you implement your solution }
/** * Prints out the contents of all reviews whose score is greater than, or equal to min_score. * * INPUT: - the head node of the linked list * * RETURN: * - the BOX OFFICE TOTAL, for all the movies that match the query * - the minimum score attribute of the query: only print and count nodes above this score * * NOTE: * - Each field in the review is printed in a separate line, with *no additional text* * - The only thing printed is the value of the corresponding field * - Reviews are separated from each other by a line of "*******************" * whose length is irrelevant, as long as it is >= 2 * - See the Assignment handout for a sample of the output that should be produced by this function */ double queryReviewsByScore(int min_score, ReviewNode *head) { return 0; // Remove this before you implement your solution }
/** * Deletes the linked list of movie reviews, releasing the memory allocated to each node. * * INPUT: - the head node of the linked list * * RETURN: - a NULL pointer (so that the head of the list can be set to NULL after deletion) */ ReviewNode *deleteReviewList(ReviewNode *head) { return head; // Remove this before you implement your solution }
///////////////////////////////////////////////////////////////////////////////////////////// // CRUNCHY SECTION! // Do not work on the functions below until your A1 is working properly and is fully tested! /////////////////////////////////////////////////////////////////////////////////////////////
/** * Sorts the list of movie reviews in ascending order of movie title. * If duplicate movie titles exist, the order is arbitrary (i.e. you choose which one goes first). * * INPUT: - the head of the unsorted list. * OUTPUT: - the head of the sorted list. * RETURN: - the head of the sorted list. */ ReviewNode *sortReviewsByTitle(ReviewNode *head) { return NULL; // Remove this before you implement your solution }
/** * Inserts the name of a cast member into the linked list of cast members, matching the input query: * - title * - studio * - year * if a match is found; else, does nothing. * * INPUT: * - title: the title of the movie * - studio: the studio where the movie was produced * - year: the year in which the movie was produced * - head: the head node of the linked list * - name: the name of the cast member being inserted * * OUTPUT: - the (internally modified) linked list of ReviewNodes, starting at head * * NOTE: * - Duplicate names are allowed - this time! */ void insertCastMember(char *title, char *studio, int year, ReviewNode *head, char *name) { }
/** * Counts how many actors have names containing the input parameter "name". * * INPUT: * - movie: the movie from which the cast is to be searched * - name: the name to be searched for in the cast list of this movie * * RETURN: - number of cast members of this movie that contain the substring "name". * * EXAMPLE: * If the input name is "Joe", and the cast list contains * - Joe Cool * - Notajoe Jones * - OneJoe Smith * - Last Name Joe * then the function will return 3 (actor names 1, 3, and 4 contain 'Joe'). * * NOTE: The case of each character MUST match (the J must be a capital letter in the above example * for the match to count) */ int countNames(MovieReview *movie, char *name) {
return 0; // Remove this when you start working on your solution }
// Prints out names of cast members for this movie - use it to help you debug // UN-COMMENT this function AFTER you've implemented the cast list CDT, or // you will get compiler errors!
// void printNames(ReviewNode *head) // { // if (NULL == head || NULL == head->review.cast) return; // printf("The cast for this movie are: "); // for (CastList *p = head->review.cast; NULL != p; p = p->next) printf("%s ", p->name); // }
4.- What to do for Part 1 Your task for part 1 can be summarized as implementing the compound data structures that will allow you to build a linked list of movie reviews. a) [5 marks] Implement the compound data type that stores one movie review. This compound type will be called 'Movie Review' and will contain the following fields: movie_title movie_studio BO total score cast - A string with length 1024 - A string with length 1024 - An int in 1920-2999 - (the Box Office total) A double floating point value - For part 1 this is just an int in 0-100 (like Rotten Tomatoes scores!) - A pointer to a linked list of cast members who were in the movie (there is an associated data type for this called 'CastList', you'll implement that at the end!). Make sure you have the correct types, and the correct lengths for strings, as well as the correct names for the fields - otherwise your code won't pass the tests. b) (5 marks) Implement the compound data type required to hold a linked list node with one movie review. The type must be called 'ReviewNode' and must contain: review *next -A'Movie Review' variable containing information for one movie - The pointer to the next node in the list c) 15 marks] Implement the newMovie ReviewNode(title, studio, year, BO_total, score) function. This 'function allocates and initializes a new movie review. Your function must return the pointer to the newly allocated, initialized node. d) (10 marks) Implement the function insert Movie Review(title,studio year, BO_total score, head). This function: - Takes as input the information for a movie review. - Takes as input the current head of the linked list of reviews. - Checks that the requested movie is not already in the linked list (if it is in the list, it prints "Sorry, that movie already exists" and returns the current list head pointer. - Obtains a new linked-list node, and fills in the movie information. - Inserts the new node at the head of the linked list. - Returns a pointer to the new head node. Spo, e) [5 marks) Implement the function countReviews(head). The function traverses the list of reviews, and returns the length of the list (the number of movies currently in the review database). [5 marks) Implement the function find Movie Review(title, studio, year, head). This function: - Takes as input a query [title, studio, year), and a pointer to the current head node. - Carries out a list traversal, looking for a review for a movie with matching fields, all three fields must be a match. - If a matching movie review is found, it returns a pointer to the node that contains it, otherwise it returns NULL. Note that one way to implement the insertMovie Review (...) function would be for that function to use find Movie Review(...). So you may want to think about which of these to implement first. g) [10 marks) Implement the function update Movie Reviewtitle, studio, year, BO_total, score, head). This function: - Takes as input a movie's title, studio, year, BO_total, and score. - Takes as input a pointer to the current head node. - Finds a movie with matching title and studio and year (all three must match!) - If such a movie is found, it updates the BO_total and score. h) (10 marks) Implement the function delete Movie Review(title, studio, year, head). This function: - Takes as input a movie's title, studio, and year. - Finds a movie with matching values for these three fields (all three must match!) - If found, it removes the movie review from the list and releases the memory used by the removed review's node. i) (5 marks) Implement the function printMovie Reviews(head). This function prints out the reviews in the order in which appear in the list. The output will look like so (the input was done using the interactive driver, so there are empty lines between the movie name and the studio, and between the studio and the year - these will not show with the automatic tester! - Our auto-tester does not care about the empty lines so don't stress about them) - sample output: This is a Bad Movie Crummy Studio 2017 S , This is a Bad Movie Crummy Studio 2017 1.000000 This is a So-So Movie Not so good studio 2016 1000.000000 * * * ** * * ** This is a Good Movie Marvellous Studio 2015 1000000.000000 Note: The function returns the box office total for all the movies printed (that is the sum of the BO_total field for all the movies in the database) make sure this is returned correctly. 1) 5 marks) Implement the function query ReviewsByStudio(studio, head). This function prints out any reviews whose studio matches the input query. The output format is identical to h). Example: Please enter the name of the studio you want to list movies for: Marvellous Studio This is a Good Movie Marvellous Studio 2015 1000000.000000 * * ** * Note: The function returns the box office total for all the movies printed. k) (5 marks) Implement the function query ReviewsByScore(score, head). This function prints out any reviews whose score is greater than or equal to the input query. Same output format as h). Example: Enter the minimum score to be used to search for movies: This is a So-So Movie Not so good studio 2016 1000.000000 *** **** ** * *** * *** This is a Good Movie Marvellous Studio 2015 1000000.000000 ****** ***** Note: The function returns the box office total for all the movies printed. D) 15 marks) Implement the function delete Review List(head). This function deletes the linked list and SA releases all memory allocated to linked list nodes. m) [10 marks] **Crunchy** Implement the function sortReviewsByTitle(head). This function takes the linked list of reviews and sorts it in ascending order of movie title. You have to come up with some way to sort the linked list. Many different ways to do this exist, and we're interested in seeing how you approach and solve this part of the assignment. n) [10 marks) **Crunchy** Implement the function insertCast Member(title, studio, year, head, name) which adds the name of an actor that worked in the movie to a linked list of cast members. This will require you to complete the compound data type for the cast linked list. This compound data type, called 'Cast List' is very simple and contains only 2 entries: name next - A string with 1024 characters - A pointer to the next CastList node Once you have completed this data type, implement the function that inserts cast members into the linked list for a given movie in any order you want, we don't care). o) [5 marks) Implement the function countNames(movie, name) which counts how many times the input name appears in the cast list for a movie (see the comments at the top of this function). 4.- What to do for Part 1 Your task for part 1 can be summarized as implementing the compound data structures that will allow you to build a linked list of movie reviews. a) [5 marks] Implement the compound data type that stores one movie review. This compound type will be called 'Movie Review' and will contain the following fields: movie_title movie_studio BO total score cast - A string with length 1024 - A string with length 1024 - An int in 1920-2999 - (the Box Office total) A double floating point value - For part 1 this is just an int in 0-100 (like Rotten Tomatoes scores!) - A pointer to a linked list of cast members who were in the movie (there is an associated data type for this called 'CastList', you'll implement that at the end!). Make sure you have the correct types, and the correct lengths for strings, as well as the correct names for the fields - otherwise your code won't pass the tests. b) (5 marks) Implement the compound data type required to hold a linked list node with one movie review. The type must be called 'ReviewNode' and must contain: review *next -A'Movie Review' variable containing information for one movie - The pointer to the next node in the list c) 15 marks] Implement the newMovie ReviewNode(title, studio, year, BO_total, score) function. This 'function allocates and initializes a new movie review. Your function must return the pointer to the newly allocated, initialized node. d) (10 marks) Implement the function insert Movie Review(title,studio year, BO_total score, head). This function: - Takes as input the information for a movie review. - Takes as input the current head of the linked list of reviews. - Checks that the requested movie is not already in the linked list (if it is in the list, it prints "Sorry, that movie already exists" and returns the current list head pointer. - Obtains a new linked-list node, and fills in the movie information. - Inserts the new node at the head of the linked list. - Returns a pointer to the new head node. Spo, e) [5 marks) Implement the function countReviews(head). The function traverses the list of reviews, and returns the length of the list (the number of movies currently in the review database). [5 marks) Implement the function find Movie Review(title, studio, year, head). This function: - Takes as input a query [title, studio, year), and a pointer to the current head node. - Carries out a list traversal, looking for a review for a movie with matching fields, all three fields must be a match. - If a matching movie review is found, it returns a pointer to the node that contains it, otherwise it returns NULL. Note that one way to implement the insertMovie Review (...) function would be for that function to use find Movie Review(...). So you may want to think about which of these to implement first. g) [10 marks) Implement the function update Movie Reviewtitle, studio, year, BO_total, score, head). This function: - Takes as input a movie's title, studio, year, BO_total, and score. - Takes as input a pointer to the current head node. - Finds a movie with matching title and studio and year (all three must match!) - If such a movie is found, it updates the BO_total and score. h) (10 marks) Implement the function delete Movie Review(title, studio, year, head). This function: - Takes as input a movie's title, studio, and year. - Finds a movie with matching values for these three fields (all three must match!) - If found, it removes the movie review from the list and releases the memory used by the removed review's node. i) (5 marks) Implement the function printMovie Reviews(head). This function prints out the reviews in the order in which appear in the list. The output will look like so (the input was done using the interactive driver, so there are empty lines between the movie name and the studio, and between the studio and the year - these will not show with the automatic tester! - Our auto-tester does not care about the empty lines so don't stress about them) - sample output: This is a Bad Movie Crummy Studio 2017 S , This is a Bad Movie Crummy Studio 2017 1.000000 This is a So-So Movie Not so good studio 2016 1000.000000 * * * ** * * ** This is a Good Movie Marvellous Studio 2015 1000000.000000 Note: The function returns the box office total for all the movies printed (that is the sum of the BO_total field for all the movies in the database) make sure this is returned correctly. 1) 5 marks) Implement the function query ReviewsByStudio(studio, head). This function prints out any reviews whose studio matches the input query. The output format is identical to h). Example: Please enter the name of the studio you want to list movies for: Marvellous Studio This is a Good Movie Marvellous Studio 2015 1000000.000000 * * ** * Note: The function returns the box office total for all the movies printed. k) (5 marks) Implement the function query ReviewsByScore(score, head). This function prints out any reviews whose score is greater than or equal to the input query. Same output format as h). Example: Enter the minimum score to be used to search for movies: This is a So-So Movie Not so good studio 2016 1000.000000 *** **** ** * *** * *** This is a Good Movie Marvellous Studio 2015 1000000.000000 ****** ***** Note: The function returns the box office total for all the movies printed. D) 15 marks) Implement the function delete Review List(head). This function deletes the linked list and SA releases all memory allocated to linked list nodes. m) [10 marks] **Crunchy** Implement the function sortReviewsByTitle(head). This function takes the linked list of reviews and sorts it in ascending order of movie title. You have to come up with some way to sort the linked list. Many different ways to do this exist, and we're interested in seeing how you approach and solve this part of the assignment. n) [10 marks) **Crunchy** Implement the function insertCast Member(title, studio, year, head, name) which adds the name of an actor that worked in the movie to a linked list of cast members. This will require you to complete the compound data type for the cast linked list. This compound data type, called 'Cast List' is very simple and contains only 2 entries: name next - A string with 1024 characters - A pointer to the next CastList node Once you have completed this data type, implement the function that inserts cast members into the linked list for a given movie in any order you want, we don't care). o) [5 marks) Implement the function countNames(movie, name) which counts how many times the input name appears in the cast list for a movie (see the comments at the top of this function)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started