Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Two-dimensional array operations: Movie Ratings program ** You have recently collected reviews from four movie reviewers where the reviewers are numbered 1- 4. Each reviewer

Two-dimensional array operations: Movie Ratings program**

You have recently collected reviews from four movie reviewers where the reviewers are numbered 1- 4. Each reviewer has rated six movies where the movies are numbered 100 -105. The ratings range from 1 (terrible) to 5 (excellent).

Note: To store the sample data below in a 2D array the reviewer numbers must be mapped to 0-3 (row subscript or index) and the movie IDs must be mapped to 0-5 (column subscript or index). The movie rating does not include data for unrated movies and only includes values related to the rating range provided. A sample data set with movie review ratings are shown in the following table:

100 101 102 103 104 105
1 3 1 5 2 1 5
2 4 2 1 4 2 4
3 3 1 2 4 4 1
4 5 1 4 2 4 2

Based on this information your program should allow the user a menu of 6 options. The options are:

Display current movie ratings.

Show the average rating for each movie.

Show a reviewers highest rated movie. (enter reviewer# 1-4)*

Show a movies lowest rating. (enter movie# 100-105)

Enter new ratings (1-5) for movie# 100-105 for four reviewers.

Exit the program.

*If a reviewer has rated multiple movies with the same highest rating, display all the movie numbers with the same highest rating in your output (this maybe on a single line or on multiple lines and would depend on how you have written the procedure in the function that is called for option#3). Points will not be deducted if it does not match the sample output below, but I must see all the movie numbers listed if there are multiple movies with the same highest rating.

The size or dimensions of the array should be declared as two global constants. In the main function you must first set-up, initialize or store the sample reviewer rating data (see table above) in a two dimensional array. This is to ensure that valid data exists in the 2-D array in case the user chooses options 1 - 4 before exiting the program.

Each option in the menu must call a function. Each function must at minimum pass in a two dimensional array and the parameter type must contain a size declarator for the number of columns (see Gaddis text Chapter#8, page 549).

Important Note.......

(1) When a multidimensional array parameter is passed through a function declaration (prototype) and corresponding function heading (definition), the size of the first dimension is not given, but the remaining dimension sizes must be given in square brackets. The assumption here is that the array dimension sizes (integer values) have been declared either globally or locally.

(2) Arrays passed in function declaration (prototype) or function heading (definition) parameter lists are reference parameters by default. Depending on the algorithm and purpose of an array processing related function you may choose to add the keyword const to any function related array parameter to prevent any accidental writing to the originial array from within the function definition. The following are two examples of function declarations or prototypes with a two-dimensional array parameter someArray, const int NUM_ROWS=4,NUM_COLS=6; // global constants for array size declarations //function prototypes or declarations void getRatings(int someArray [][NUM_COLS]); //the array is passed by reference to the function with read/write access void showRatings(const int someArray [][NUM_COLS]); //the array is passed by reference to the function but with read only access * note: since NUM_ROWS (the first dimension) is delcared as a global constant, a second int parameter to pass number of rows to each of the above functions is not needed.

You may use the partial program framework provided below as an initial set-up guide to begin writing your own algorithms or you may start entirely with your own approach and implement the necessary interface to this programming project. The requirement is that I see well-documented seperate function procedures that are called when menu options 1-5 are selected and that the function algorithms process the 2-D array data correctly.

The program run-time output shown below is based on compiling the program to test each menu option. Use this as a guide while you write and test your programs interface and calls to specific function procedures.

Use meaningful identifiers and include function documentation (see syllabus) particularly in the function header and elsewhere in the function body where appropriate. Credit is provided only for those function procedures that correctly process the array data based on the option selected.

Prior to submission make sure that you compile and test each option in your program to ensure that the output is similar to the sample program ouput shown below. There will be no redo on this project.

INPUT VALIDATION: Prevent out of bound array access. For example with menu option#3 limit the user input to reviewer#1-4 and similarly with menu option#4 limit the user input to movie# 100-105. With menu option#5 limit the data entry for ratings to 1-5.

//Student_Name & description and purpose of program /*The partial program framework below is provided as an initial set-up guide to begin writing your own function procedures or algorithms to process array data. No further details regarding this partial framework will be provided. On the other hand you may find it more rewarding if you design, develop and implement your own program structure and logic routines. Either way, remember that the requirement is that I see well-documented seperate function procedures that are called when menu options 1-5 are selected and that the function algorithms process the 2-D array data correctly. */ #include  #include  using namespace std; const int NUM_REVIEWERS = 4; //Number of rows in reviews array const int NUM_MOVIES = 6; //Number of columns in reviews array //I have listed below a few sample function prototypes you may choose to begin writing functon definitions for or create your own //Note: Since NUM_ROWS (the first dimension) is declared as a global constant, a second int parameter to pass number of rows to each of the functions is not needed. 
void initialRatings(int [][NUM_MOVIES]); //a function to set all data elements in the 2-D array to the sample data provided in table above void getNewRatings(int [][NUM_MOVIES]); //a function to set new reviewer rating values in the 2-D array void displayRatings(const int [][NUM_MOVIES]); //a function to display current values in the in the 2-D array void showAverageRatings(const int [][NUM_MOVIES]); //a function that calculates the average for each column in the 2-D array ..may also be a value-returning function void showReviewersHighestRating(const int [][NUM_MOVIES], int); //a function that finds the highest value for a row in the 2-D array ..may also be a value-returning function int main() { // Variable declarations int someArray[NUM_REVIEWERS][NUM_MOVIES]; // Ratings for reviewers int choice; initialRatings(someArray); //function call with actual argument passing in the array and the number of rows do { //program interface with menu options cout<<"---------------------------------------------------"<>choice; //include validation routine to check data input switch (choice) { //call to various functions in each case } }while(choice!=6); return 0; } 
//All function definitions should go below the main function ..NO INLINE FUNCTIONS //Include appropriate function documentation in the function header and elswhere in the function body. ...... --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- **Although not required, Windows system users may include the following syntax, system("CLS"); //This command is used to clear the screen between menu option displays but you must add the following directive 
#include

Here is a sample run of the program that you may use as a guide in helping set-up the interface and also provides a few check figures...

--------------------------------------------------- 2-D ARRAY PROCESSING MENU OPTIONS --------------------------------------------------- 1. Display current movie ratings 2. Show the average rating for each movie. 3. Show a reviewers highest rated movie. (enter reviewer# 1-4) 4. Show a movies lowest rating. (enter movie# 100-105) 5. Enter new ratings (1-5) for movie# 100-105 for four reviewers 6. Quit program Enter your choice:1 ********************* MOVIE RATINGS **************** REVIEWER| MV#100 MV#101 MV#102 MV#103 MV#104 MV#105 **************************************************** #1 3 1 5 2 1 5 #2 4 2 1 4 2 4 #3 3 1 2 4 4 1 #4 5 1 4 2 4 2 --------------------------------------------------- 2-D ARRAY PROCESSING MENU OPTIONS --------------------------------------------------- 1. Display current movie ratings 2. Show the average rating for each movie. 3. Show a reviewers highest rated movie. (enter reviewer# 1-4) 4. Show a movies lowest rating. (enter movie# 100-105) 5. Enter new ratings (1-5) for movie# 100-105 for four reviewers 6. Quit program Enter your choice:2 ********************* MOVIE RATINGS **************** REVIEWER| MV#100 MV#101 MV#102 MV#103 MV#104 MV#105 **************************************************** #1 3 1 5 2 1 5 #2 4 2 1 4 2 4 #3 3 1 2 4 4 1 #4 5 1 4 2 4 2 **************************************************** Average Rating for each movie: Movie#100: 3.75 Movie#101: 1.25 Movie#102: 3 Movie#103: 3 Movie#104: 2.75 Movie#105: 3 --------------------------------------------------- 2-D ARRAY PROCESSING MENU OPTIONS --------------------------------------------------- 1. Display current movie ratings 2. Show the average rating for each movie. 3. Show a reviewers highest rated movie. (enter reviewer# 1-4) 4. Show a movies lowest rating. (enter movie# 100-105) 5. Enter new ratings (1-5) for movie# 100-105 for four reviewers 6. Quit program Enter your choice:3 ********************* MOVIE RATINGS **************** REVIEWER| MV#100 MV#101 MV#102 MV#103 MV#104 MV#105 **************************************************** #1 3 1 5 2 1 5 #2 4 2 1 4 2 4 #3 3 1 2 4 4 1 #4 5 1 4 2 4 2 Enter a reviewer number (1-4), to find the Movie they rated the highest:6 That is an invalid reviewer number. Enter a reviewer number (1-4), to find the Movie they rated the highest:1 Reviewer#1 rated Movie#102 and 105 as the highest (*for display format please see my note above) --------------------------------------------------- 2-D ARRAY PROCESSING MENU OPTIONS --------------------------------------------------- 1. Display current movie ratings 2. Show the average rating for each movie. 3. Show a reviewers highest rated movie. (enter reviewer# 1-4) 4. Show a movies lowest rating. (enter movie# 100-105) 5. Enter new ratings (1-5) for movie# 100-105 for four reviewers 6. Quit program Enter your choice:4 ********************* MOVIE RATINGS **************** REVIEWER| MV#100 MV#101 MV#102 MV#103 MV#104 MV#105 **************************************************** #1 3 1 5 2 1 5 #2 4 2 1 4 2 4 #3 3 1 2 4 4 1 #4 5 1 4 2 4 2 Enter a movie number (100-105), to find the lowest rating:107 That is an invalid movie number. Enter a movie number (100-105), to find the lowest rating:103 Movie#103 lowest rating is 2. --------------------------------------------------- 2-D ARRAY PROCESSING MENU OPTIONS --------------------------------------------------- 1. Display current movie ratings 2. Show the average rating for each movie. 3. Show a reviewers highest rated movie. (enter reviewer# 1-4) 4. Show a movies lowest rating. (enter movie# 100-105) 5. Enter new ratings (1-5) for movie# 100-105 for four reviewers 6. Quit program Enter your choice:5 ********DATA ENTRY FOR NEW MOVIE RATINGS *********** **************************************************** REVIEWER# 1: **************************************************** Enter rating (1-5) for movie#100: 1 Enter rating (1-5) for movie#101: 2 Enter rating (1-5) for movie#102: 3 Enter rating (1-5) for movie#103: 4 Enter rating (1-5) for movie#104: 5 Enter rating (1-5) for movie#105: 6 Invalid rating. It must be from 1-5. Enter rating (1-5) for movie#105: 1 **************************************************** REVIEWER# 2: **************************************************** Enter rating (1-5) for movie#100: 5 Enter rating (1-5) for movie#101: 4 Enter rating (1-5) for movie#102: 3 Enter rating (1-5) for movie#103: 2 Enter rating (1-5) for movie#104: 1 Enter rating (1-5) for movie#105: 5 **************************************************** REVIEWER# 3: **************************************************** Enter rating (1-5) for movie#100: 2 Enter rating (1-5) for movie#101: 3 Enter rating (1-5) for movie#102: 4 Enter rating (1-5) for movie#103: 5 Enter rating (1-5) for movie#104: 1 Enter rating (1-5) for movie#105: 2 **************************************************** REVIEWER# 4: **************************************************** Enter rating (1-5) for movie#100: 3 Enter rating (1-5) for movie#101: 4 Enter rating (1-5) for movie#102: 5 Enter rating (1-5) for movie#103: 1 Enter rating (1-5) for movie#104: 2 Enter rating (1-5) for movie#105: 3 --------------------------------------------------- 2-D ARRAY PROCESSING MENU OPTIONS --------------------------------------------------- 1. Display current movie ratings 2. Show the average rating for each movie. 3. Show a reviewers highest rated movie. (enter reviewer# 1-4) 4. Show a movies lowest rating. (enter movie# 100-105) 5. Enter new ratings (1-5) for movie# 100-105 for four reviewers 6. Quit program Enter your choice:1 ********************* MOVIE RATINGS **************** REVIEWER| MV#100 MV#101 MV#102 MV#103 MV#104 MV#105 **************************************************** #1 1 2 3 4 5 1 #2 5 4 3 2 1 5 #3 2 3 4 5 1 2 #4 3 4 5 1 2 3 --------------------------------------------------- 2-D ARRAY PROCESSING MENU OPTIONS --------------------------------------------------- 1. Display current movie ratings 2. Show the average rating for each movie. 3. Show a reviewers highest rated movie. (enter reviewer# 1-4) 4. Show a movies lowest rating. (enter movie# 100-105) 5. Enter new ratings (1-5) for movie# 100-105 for four reviewers 6. Quit program Enter your choice:8 INVALID CHOICE ...please retype --------------------------------------------------- 2-D ARRAY PROCESSING MENU OPTIONS --------------------------------------------------- 1. Display current movie ratings 2. Show the average rating for each movie. 3. Show a reviewers highest rated movie. (enter reviewer# 1-4) 4. Show a movies lowest rating. (enter movie# 100-105) 5. Enter new ratings (1-5) for movie# 100-105 for four reviewers 6. Quit program Enter your choice:6 Array processing test now concluded. Exiting program ..... Process returned 0 (0x0) execution time : 408.257 s Press any key to continue. 

If your program does not compile, it will not be graded. HINT: I am thinking six to seven two dimensional array processing functions with procedures or algorithms that address the menu choice should be adequate. When working with the array processing in your functions watch for "Off-By-One Errors". Use a do while loop with a switch statement as shown above. You should call the relevant functions from each case. Compile your code often. Only write a small portion of code, let's say a single function for a specific menu option, check that it still compiles before moving on. This way when you get a syntax error, you can be fairly certain the error is in the part you just wrote.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Datalog Engines In Databases

Authors: Bas Ketsman ,Paraschos Koutris

1st Edition

1638280428, 978-1638280422

More Books

Students also viewed these Databases questions

Question

Identify Freuds developmental stages.

Answered: 1 week ago

Question

explain the concept of strategy formulation

Answered: 1 week ago