Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You have collected reviews from four movie reviewers where the reviewers are num

ID: 3686561 • Letter: Y

Question

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

The reviews are shown in the following table:

100

101

102

103

104

105

0

3

1

5

2

1

5

1

4

2

1

4

2

4

2

3

1

2

4

4

1

3

5

1

4

2

4

2

Write a program that stores this data using a 2D array. Based on this information your program should allow the user to enter ratings for any three movies. The program should then find the reviewer whose ratings most closely match the ratings input by the user. It should then predict the user’s interest in the other movies by outputting the ratings by the reviewer for the movies that were not rated by the user. Use the Cartesian distance as the metric to determine how close the reviewer’s movie ratings are to the ratings input by the user. This technique is a simple version of the nearest neighbor classification algorithm.

For example, if the user inputs a rating of 5 for movie 102, 2 for movie 104, and 5 for movie 105, then the closest match is reviewer 0 with a distance of sqrt((5-5)^2 + (2-1)^2 + (5-5)^2) = 1.   The program would then predict a rating of 3 for movie 100, a rating of 1 for movie 101, and a rating of 2 for movie 103.

Note: To store the data in a 2D array the movie ID’s must be mapped to 0-5.

Here is the sample runs:

Enter a movie to rate (100-105). Enter 0 to exit and get recommendations.

101

Enter rating (1-5) for this movie.

4

Enter a movie to rate (100-105). Enter 0 to exit and get recommendations.

105

Enter rating (1-5) for this movie.

3

Enter a movie to rate (100-105). Enter 0 to exit and get recommendations.

0

The closest reviewer is number 1

Predictions for movies you have not yet seen:

Movie 100 : Predicted Rating = 4

Movie 102 : Predicted Rating = 1

Movie 103 : Predicted Rating = 4

Movie 104 : Predicted Rating = 2

Have the code in Java just need this code in C++ language:

import java.util.Scanner;

public class MovieReviewer {
  
   public static void main(String[] args) {
  
   int[][] reviews={{3,1,5,2,1,5},{4,2,1,4,2,4},{3,1,2,4,4,1},{5,1,4,2,4,2}};
   int[] user_rate=new int[6];
   Scanner sc=new Scanner(System.in);{
   for(int i=0;i<6;i++)
   user_rate[i]=0;
   int mov=1;
  
   while(true)
   {
   System.out.println("Enter a movie to rate (100-105). Enter 0 to exit and get recommendations.");
   mov=sc.nextInt();
   if(mov==0)break;
   System.out.println("Enter rating 1-5 for the movie");
   user_rate[mov%10]=sc.nextInt();
   }
   double min_car=1000,temp=0;
   int q=0;
   for(int i=0;i<4;i++)
   {
   for(int j=0;j<6;j++)
   {
   if(user_rate[j]!=0)
   {
   temp=temp+((reviews[i][j]-user_rate[j])*(reviews[i][j]-user_rate[j]));
   }
   }
   temp=Math.sqrt(temp);
   if(temp    {
   min_car=temp;
   q=i;
   }
   temp=0;
   }
   System.out.println("closest reviewer is "+q);
  
   System.out.println("Reviews of the movies by the same reviewer that you have not seen");
  
   for(int i=0;i<6;i++)
   {
   if(user_rate[i]==0)
   System.out.println("movie "+""+(100+i)+" "+reviews[q][i]);
   }
  
   }
}
}

100

101

102

103

104

105

0

3

1

5

2

1

5

1

4

2

1

4

2

4

2

3

1

2

4

4

1

3

5

1

4

2

4

2

Explanation / Answer


#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int main()
{
  
  
int reviews[4][6]={{3,1,5,2,1,5},{4,2,1,4,2,4},{3,1,2,4,4,1},{5,1,4,2,4,2}};
int user_rate[6];

for(int i=0;i<6;i++)
user_rate[i]=0;

int mov=1;
  
while(true)
{
cout << "Enter a movie to rate (100-105). Enter 0 to exit and get recommendations."<<endl;;
cin >> mov;
if(mov==0)break;
cout << "Enter rating 1-5 for the movie" << endl;
cin >> user_rate[mov%10];
}

double min_car=1000,temp=0;
int q=0;
for(int i=0;i<4;i++)
{
for(int j=0;j<6;j++)
{
if(user_rate[j]!=0)
{
temp=temp+((reviews[i][j]-user_rate[j])*(reviews[i][j]-user_rate[j]));
}
}
temp=sqrt(temp);
if(temp)
{
min_car=temp;
q=i;
}
temp=0;
}
cout << "closest reviewer is " << q << endl;
  
cout << "Reviews of the movies by the same reviewer that you have not seen" << endl;
  
for(int i=0;i<6;i++)
{
if(user_rate[i]==0)
cout << "movie " << (100+i) << " " << reviews[q][i] << endl;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote