Question: Make the following changes to the code in C: (1) Implement a new compound data type that defines a node for a linked list of
Make the following changes to the code in C:
(1) Implement a new compound data type that defines a node for a linked list of integers. This list will be used to hold multiple scores for a movie.
(2) Implement a function to insert a new integer value into a linked list of integers. This will also require you to implement a function to allocate and initialize a new integer list node.
(3) Expand the compound data type for 'MovieReview' so that now it contains: movie_title - A string with length 1024 movie_studio - A string with length 1024 year - An int in 1920-2999 BO_total - (the Box Office total) A float value scores_head - Head pointer to a linked list of scores for this movie -> NEED TO DO THIS
typedef struct MovieReview_struct { char movie_title[MAX_STR_LEN]; char movie_studio[MAX_STR_LEN]; int year; float BO_total; } MovieReview;
typedef struct ReviewNode_struct { MovieReview review; struct ReviewNode_struct *next; } ReviewNode;
(4) Modify newMovieReviewNode(), this time the newly allocated review should get an empty linked list of scores.
ReviewNode *newMovieReviewNode() { /* * This function allocates a new, empty ReviewNode, and initializes the * contents of the MovieReview for this node to empty values. * The fields in the MovieReview should be set to: * movie_title="" * movie_studio="" * year = -1 * BO_total = -1 * score = -1 * * The *next pointer for the new node MUST be set to NULL * * The function must return a pointer to the newly allocated and initialized * node. If something goes wrong, the function returns NULL */ ReviewNode *newNode = NULL; newNode = (ReviewNode *)calloc(1, sizeof(ReviewNode)); strcpy(newNode->review.movie_title, ""); strcpy(newNode->review.movie_studio, ""); newNode->review.year = -1; newNode->review.BO_total = -1; newNode->review.score = -1; newNode->next = NULL; return newNode; // <--- This should change when after you implement your solution }
(5) [5 marks] Modify insertMovieReview(), this time, the function will - If this is the first review for this movie * create a new movie review linked list node, fill-in the review information, and insert the score as the first entry in the review's linked list of scores - If the review already exists * Add a new score to the review's linked list of scores
ReviewNode *insertMovieReview(char title[MAX_STR_LEN], char studio[MAX_STR_LEN], int year, float BO_total, int score, ReviewNode *head) { ReviewNode *p = NULL; ReviewNode *one_review = NULL; if (year<1920 || year>2999 || score < 0 || score > 100){ return head; } p = findMovieReview(title, studio, year, head);
if (p==NULL){ one_review = newMovieReviewNode(); strcpy(one_review->review.movie_title, title); strcpy(one_review->review.movie_studio, studio); one_review->review.year=year; one_review->review.BO_total=BO_total; one_review->review.score=score; one_review->next=head; return one_review; } printf("Sorry, that movie already exists "); return head; // <--- This should change when after you implement your solution }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
