Question: I have completed the entire program, but I need someone to run the program and fix the errors. I have included a picture of the

I have completed the entire program, but I need someone to run the program and fix the errors. I have included a picture of the expected output, and the entire code. Thank you!!!

Expected Output:

Code:

#include #include #include

#define MAX_STR_LEN 1024

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; 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; //

ReviewNode *findMovieReview(char title[MAX_STR_LEN], char studio[MAX_STR_LEN], int year, ReviewNode *head) { ReviewNode *cur = head; while (cur != NULL) { if (strcmp(title, cur->movie_title) == 0 && strcmp(studio, cur->movie_studio)== 0 && year == cur->year) { return cur; } cur = cur->next; } return NULL; //

ReviewNode *insertMovieReview(char title[MAX_STR_LEN], char studio[MAX_STR_LEN], int year, float BO_total, int score, ReviewNode *head) { ReviewNode *cur = head, *newNode; if (head == NULL) { //insert at head newNode = newMovieReviewNode(); strcpy(newNode->movie_title, title); strcpy(newNode->movie_studio, studio); newNode->year = year; newNode->score = score; newNode->BO_total = BO_total; newNode->next = NULL; head = newNode; return head; } //check if movie is already in list , if not then insert, CHEGGEA if (findMovieReview(title, studio, year, head) != NULL) { return cur; } while (cur->next != NULL) cur = cur->next; newNode = newMovieReviewNode(); strcpy(newNode->movie_title, title); strcpy(newNode->movie_studio, studio); newNode->year = year; newNode->score = score; newNode->BO_total = BO_total; newNode->next = NULL; cur->next = newNode; return head; //

int countReviews(ReviewNode *head) { /* * This function returns the length of the current linked list. This requires * list traversal. */ int count = 0; // Count Variable ReviewNode *cur = head; // Iterate through the node and count the length. while (cur != NULL) { count++; cur = cur->next; } return count; //

void updateMovieReview(char title[MAX_STR_LEN], char studio[MAX_STR_LEN], int year, float BO_total, int score, ReviewNode *head) { /* * This function looks for a review matching the input query [title, studio, year]. * If such a review is found, then the function updates the Box-office total, and the score. * If no such review is found, the function prints out * "Sorry, no such movie exists at this point" */ ReviewNode *cur;

// Find the current node cur = findMovieReview(title, studio, year, head); // Update the current node values if found, else print the message if ( cur != NULL) { cur->BO_total = BO_total; cur->score = score; } else { printf("Sorry, no such movie exists at this point"); } }

ReviewNode *deleteMovieReview(char title[MAX_STR_LEN], char studio[MAX_STR_LEN],int year, ReviewNode *head) { /* * This function removes a review matching the input query from the linked list. If no such review can * be found, it does nothing. * * The function returns a pointer to the head of the linked list (which may have changed as a result * of the deletion process) prev -> Holds the previous node cur -> Holds the current node */ ReviewNode *prev, *cur;

// Initialize the nodes cur = head; prev = head;

// Iterate though the node to find the matching node and delete the current node while (cur != NULL) { if (strcmp(title, cur->movie_title) == 0 && strcmp(studio, cur->movie_studio) == 0 && year == cur->year) { // If current node is the head node, that is, if it is first node in the list if (cur == head) { cur = cur->next; return cur; } // If not first node, assign the previous node to next node of current node prev->next = cur->next; cur->next = NULL; // Delink current node from the list return head; } prev = cur; // Hold the current node as previous node cur = cur->next; // Traverse to next node }

return head; //

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;

} }

void queryReviewsByStudio(char studio[MAX_STR_LEN], ReviewNode *head) { /* * This function looks for reviews whose studio matches the input query. * 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 = head; while(current_review !=NULL){

if(strcmp(current_review->review.movie_studio, studio) ==0){

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;

}

}

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;

} }

ReviewNode *deleteReviewList(ReviewNode *head) { /* * This function deletes the linked list of movie reviews, releasing all the * memory allocated to the nodes in the linked list. * * Returns a NULL pointer so that the head of the list can be set to NULL * after deletion. */ ReviewNode *current_review = NULL; ReviewNode *q = NULL; current_review = head;

while (current_review != NULL) { q = current_review->next; free(current_review); current_review = q; } return NULL; //

ReviewNode *sortReviewsByTitle(ReviewNode *head) { /* * This function sorts the list of movie reviews in ascending order of movie * title. If duplicate movie titles exist, the order is arbitrary (i.e. you * can choose which one goes first). * * However you implement this function, it must return a pointer to the head * node of the sorted list. */ int swapped, i; ReviewNode *current; ReviewNode *next = NULL; /* Checking for empty list */ if (head == NULL) return; do { swapped = 0; current = head; while (current->next != next) { if (strcmp(current->movie_title,current->next->movie_title) > 0) { swap(current, current->next); swapped = 1; } current = current->next; } next = current; } while (swapped);

return head; //

void swap(ReviewNode *a, ReviewNode *b) { String tempMovieTitle = a->movie_title; a->movie_title = b->movie_title; b->movie_title = tempMovieTitle; String tempMovieStudio = a->movie_studio; a->movie_studio = b->movie_studio; b->movie_studio = tempMovieStudio; int tempYear = a->year; a->year = b->year; b->year = tempYear; float tempBOTotal = a->BO_total; a->BO_total = b->BO_total; b->BO_total = tempBOTotal; int tempScore = a->score; a->score = b->score; b->score = tempScore; }

Passed Test #1 Passed Test #2 Passed Test #3 Passed,Test #4 Sorry, that move atready existsPassed Test #s Passed test #6 Passed test #7 Passed Test #8 Passed Test #9 Passed Test #10 Passed Test #11 Back to the Future Universal Studios 1985 Passed Test #13

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!