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
  • 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...

  • #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...

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

  • 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...

  • 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...

  • Using the provided table interface table.h and the sample linked list code linkedList.c, complete an implementation...

    Using the provided table interface table.h and the sample linked list code linkedList.c, complete an implementation of the Table ADT. Make sure that you apply the concepts of design by contract (DbC) to your implementation. Once you have fully implemented the table, create a main.c file that implements a testing framework for your table. Your table implementation must ensure that values inserted are unique, and internally sorted within a linked list. table.h #ifndef _TABLE_H #define _TABLE_H //----------------------------------------------------------------------------- // CONSTANTS AND...

  • C programming A linked list is a linear data structure that allows us to add and remove items fro...

    c programming A linked list is a linear data structure that allows us to add and remove items from the list very quickly, by simply changing a few pointers. There are many different variations of linked lists. We have studied the doubly-linked, circular, with a dummy-header-node version of a linked list. In the class notes we studied several functions to manipulate a Linked List. For this assignment you must write the code for the following additional linked list functions: addFirst,...

  • Hi, I need to make a program in C that reads the type of currency and...

    Hi, I need to make a program in C that reads the type of currency and organizes them into stacks based on currency which can be read back. This is what I have so far, can I get help finishing it? #include <stdio.h> #include <stdlib.h> const float POUND = 1.31; const float YEN = 0.0091; const float RUPEE = 0.014; const float EURO = 1.11; char c; int currValue; float exchangeValue; float finValue; int printValue; struct node {    int...

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
ADVERTISEMENT