Question: Following changes need to be made, and the code for each is provided: (1) Modify newMovieReviewNode(), this time the newly allocated review should get an
Following changes need to be made, and the code for each is provided: (1) 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 }
(2) Modify the function queryReviewsByScore(min_score, head). It should now return any movies in the list whose average score is greater than the query value the printing format does not change, it simply replaces the old score with the new (floating point!) average score.
void queryReviewsByScore(int min_score, ReviewNode *head) { /* * This function looks for reviews whose score is greater than, or equal to * the input 'min_score'. * It prints out the contents of all reviews matching the query in exactly * the same format used by the printMovieReviews() function above. */ ReviewNode *current_review = NULL; current_review = head; while(current_review !=NULL) { if(current_review->review.score>=min_score) { printf("%s ", current_review->review.movie_title); printf("%s ", current_review->review.movie_studio); printf("%d ", current_review->review.year); printf("%f ", current_review->review.BO_total); printf("%d ", current_review->review.score); printf("*********************** "); }
current_review=current_review->next;
} }
float getAverageScore(char title[MAX_STR_LEN], char studio[MAX_STR_LEN], int year, ReviewNode *head) { ReviewNode *p = NULL; p=findMovieReview(title, studio, year, head); if (p!=NULL) { float total = 0; int count = 0; int_node *tr =NULL; tr=p->review.scores_head; while(tr!=NULL) { int scores = tr->score; total = total + scores; count ++; tr=tr->next; } float avg = (float)total/(float)count; return (float)avg; } return (float)-1; }
(3) printMovieReview() - Remove the printing of the movie score (since now it's a linked list).
void printMovieReviews(ReviewNode *head) { ReviewNode *current_review = head; while(current_review !=NULL) { printf("%s ", current_review->review.movie_title); printf("%s ", current_review->review.movie_studio); printf("%d ", current_review->review.year); printf("%f ", current_review->review.BO_total); printf("%d ", current_review->review.score); printf("*********************** ");
current_review = current_review->next;
} }
(4) 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
typedef struct MovieReview_struct { char movie_title[MAX_STR_LEN]; char movie_studio[MAX_STR_LEN]; int year; float BO_total; int score; } MovieReview;
typedef struct ReviewNode_struct { MovieReview review; struct ReviewNode_struct *next; } ReviewNode;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
