Question

Following changes need to be made, and the code for each is provided: (1) Modify newMovieReviewNode(),...

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\n", current_review->review.movie_title);
           printf("%s\n", current_review->review.movie_studio);
           printf("%d\n", current_review->review.year);
           printf("%f\n", current_review->review.BO_total);
           printf("%d\n", current_review->review.score);
           printf("***********************\n");
           }

       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\n", current_review->review.movie_title);
       printf("%s\n", current_review->review.movie_studio);
       printf("%d\n", current_review->review.year);
       printf("%f\n", current_review->review.BO_total);
       printf("%d\n", current_review->review.score);
       printf("***********************\n");

       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;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER-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 = (Score *)calloc(1,sizeof(Score));
   newNode->next = NULL;
   return newNode; // <--- This should change when after you implement your solution
}

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

ANSWER-2

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)
       {
      
        float average = getAverageScore(current_review->review.movie_title,
          current_review->review.movie_studio,
          current_review->review.year,
          current_review);
  
         
       if(average>=min_score)
           {
           printf("%s\n", current_review->review.movie_title);
           printf("%s\n", current_review->review.movie_studio);
           printf("%d\n", current_review->review.year);
           printf("%f\n", current_review->review.BO_total);
           printf("%f\n", average);
           printf("***********************\n");
           }

       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 0;
}

------------------------------------------------------------------------------------------------------------------------------------------------------------------------

ANSWER-3

void printMovieReviews(ReviewNode *head)
{
   ReviewNode *current_review = head;
   while(current_review !=NULL)
       {
       printf("%s\n", current_review->review.movie_title);
       printf("%s\n", current_review->review.movie_studio);
       printf("%d\n", current_review->review.year);
       printf("%f\n", current_review->review.BO_total);
       printf("***********************\n");

       current_review = current_review->next;

       }
}

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

ANSWER-4

typedef struct MovieReview_struct
{
   char movie_title[MAX_STR_LEN];
   char movie_studio[MAX_STR_LEN];
   int year;
   float BO_total;
   Score scores_head;
} MovieReview;

typedef struct ReviewNode_struct
{
   MovieReview review;
   struct ReviewNode_struct *next;
} ReviewNode;

PLEASE DON'T FORGET TO GIVE FEEDBACK.IT HELPS US TO IMPROVE THE ANSWER.

Add a comment
Know the answer?
Add Answer to:
Following changes need to be made, and the code for each is provided: (1) Modify newMovieReviewNode(),...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using the provided Linked List example code, linkedlist.c, as an example Make a node struct that...

    Using the provided Linked List example code, linkedlist.c, as an example Make a node struct that holds ints instead of strings. In your main, insert 25 to 75 random integers with range (0 to 100) into a linked list of your nodes. Use a random to determine how many to make. Write a function int sum(NodePointer current) that returns the sum of the integers in the list by looping through the linked list. Write a function int count(NodePointer current) that...

  • Deleting multiples of a given integer from a linked list: #include <stdio.h> #include <stdlib.h> #include <assert.h>...

    Deleting multiples of a given integer from a linked list: #include <stdio.h> #include <stdlib.h> #include <assert.h> #define MAX 10000 typedef struct node_tag { int v; // data struct node_tag * next; // A pointer to this type of struct } node; // Define a type. Easier to use. node * create_node(int v) { node * p = malloc(sizeof(node)); // Allocate memory assert(p != NULL); // you can be nicer // Set the value in the node. p->v = v; p->next...

  • program in C - Starter code below //In this assignment, we practice call by reference. //Below...

    program in C - Starter code below //In this assignment, we practice call by reference. //Below description of call by reference is from the following link //https://www.tutorialspoint.com/cprogramming/c_function_call_by_reference.htm //The call by reference method of passing arguments to a function copies //the address of an argument into the formal parameter. Inside the function, //the address is used to access the actual argument used in the call. //It means the changes made to the parameter affect the passed argument. //We use an example...

  • C LANGUAGE I just need the void push() function, which inserts new node to the front...

    C LANGUAGE I just need the void push() function, which inserts new node to the front of the list #include<stdio.h> #include<stdlib.h> typedef struct node { int data; struct node *next; } Node; //Creating head a as a global Node* Node *head; /* Given a node prev_node, insert a new node after the given prev_node */ void insertAfter (Node * prev_node, int new_data) { /*1. check if the given prev_node is NULL */ if (prev_node == NULL) { printf ("the given...

  • #include <iostream> using namespace std; struct ListNode { float value; ListNode *next; }; ...

    #include <iostream> using namespace std; struct ListNode { float value; ListNode *next; }; ListNode *head; class LinkedList { public: int insertNode(float num); void deleteNode(float num); void destroyList(); void displayList(); LinkedList(void) {head = NULL;} ~LinkedList(void) {destroyList();} }; int LinkedList::insertNode(float num) { struct ListNode *newNode, *nodePtr = head, *prevNodePtr = NULL; newNode = new ListNode; if(newNode == NULL) { cout << "Error allocating memory for new list member!\n"; return 1; } newNode->value = num; newNode->next = NULL; if(head==NULL) { cout << "List...

  • Enum {FALSE=0, TRUE}; #define MAXBUFF 1024 #define SMALLBUFF 10 /* The LinkNode type is used as a...

    enum {FALSE=0, TRUE}; #define MAXBUFF 1024 #define SMALLBUFF 10 /* The LinkNode type is used as an element of a linked list ** implementation of a stack of tree nodes. */ typedef struct link_t LinkNode; typedef LinkNode *LinkNodePtr; /* The TreeNode type is used as an element of a binary "parse" tree. ** Tree nodes are created while parsing the RPN expression and ** stored on a stack until it's time to place them. */ typedef struct tree_t TreeNode; typedef...

  • Using the provided Linked List template, add the following recursive functions and demonstrate them in a...

    Using the provided Linked List template, add the following recursive functions and demonstrate them in a separate cpp file. Write a recursive function to print the list in order. Write a recursive function to print the list in reverse order. Write a recursive function to print every other node in the list in order. Write a recursive function to return the number of nodes in the list. Write a Boolean function that implements the recursive version of sequential search. THIS...

  • Your task is to complete the following function/functions: 1. Given a position in the linked list,...

    Your task is to complete the following function/functions: 1. Given a position in the linked list, delete the node at that position.(Silver problem - Mandatory ) 2. Print the sum of all negative elements in the linked list.(Gold problem) If you want, you can refer to the the previous recitation manual (which was on Linked Lists) to implement node deletion. #include <iostream> using namespace std; //----------- Define Node --------------------------------------------------- struct Node{ int key; Node *next; }; //----------- Define Linked List...

  • // C code // If you modify any of the given code, the return types, or...

    // C code // If you modify any of the given code, the return types, or the parameters, you risk getting compile error. // Yyou are not allowed to modify main (). // You can use string library functions. #include <stdio.h> #include <stdlib.h> #include <string.h> #pragma warning(disable: 4996) // for Visual Studio #define MAX_NAME 30 // global linked list 'list' contains the list of patients struct patientList {    struct patient *patient;    struct patientList *next; } *list = NULL;  ...

  • Programming in C: I am trying to modify this linked list to be doubly linked list....

    Programming in C: I am trying to modify this linked list to be doubly linked list. I’m also trying to add a print in reverse function. I’m really struggling with how to change the insert function to doubly link the nodes without effecting the alphabetical sorting mechanism. Example of desired output: Enter your choice: 1 to insert an element into the list. 2 to delete an element from the list. 3 to end. ? 1 Enter a character: a The...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT