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

using C++ Your manager wants to be able to add new movies to your top 10 movies

ID: 3668341 • Letter: U

Question

using C++

Your manager wants to be able to add new movies to your top 10 movies array. Assume that the movie array is sorted by audience rating (Problem 2). The catch is that if a new movie has a higher audience rating, it bumps the movie with the lowest audience rating and is inserted into the array at the correct position. The number of movies in the top ten list is always 10. if a new movie has an audience score lower than the lowest Movie in the array, the movie is not inserted. Write the function: void InsertMovie(Movies* movies, int numMovies, const Movie& movie); Test this by using the PrintMovies function from Problem 1. Example by analogy: Assume the following array of ten ratings: Ratings: { 100, 90, 85, 75, 66, 55, 44, 33, 22, 11 }; Adding a new rating of 62 would change the array to: Ratings: { 100, 90, 85, 75, 66, 62, 55, 44, 55, 22 }; Note that 11 has been dropped, and everything from 55 on was shifted to the right by one position.

Explanation / Answer

#include <iostream>
#include <string>
#include <algorithm>
#include "Movie.h"
#include <iomanip>
using namespace std;
#ifndef _Movie_
#define _Movie_
#include <iostream>
struct Movie
{
std::string title;
int criticRating;
int audienceRating;
};
void PrintMovies(Movie*, int);
void SortMoviesByAudienceRating(Movie*, int);
void InsertMovie(Movie*, int, const Movie&);
int main()
{
constexpr auto NumMovies = 10;
Movie* movie = new Movie[NumMovies];
movie[0] = { "Deadpol", 81, 86};
movie[1] = { "Fast and furious", 81, 46};
movie[2] = { "hulk The Force Awakens", 92, 90};
movie[3] = { "zid", 82, 85};
movie[4] = { "fast and furious2", 7, 67};
movie[5] = { "JUngle book", 45, 59};
movie[6] = { "The Finest Hours", 59, 72};
movie[7] = { "Dead sea", 13, 55};
movie[8] = { "The indipendence day", 31, 45};
movie[9] = { "Marvel", 9, 51};
PrintMovies(movie, NumMovies);
SortMoviesByAudienceRating(movie, NumMovies);
PrintMovies(movie, NumMovies);
Movie newMovie = { "The Jungle Book", 84, 80 };
InsertMovie(movie, NumMovies, newMovie);
PrintMovies(movie, NumMovies);
return 0;
}
void InsertMovie(Movie* movies, int numMovies, const Movie& movie)
{
Movie temp1, temp2;
for (int i = 0; i < numMovies; ++i)
{
if (movie.audienceRating >= movies[i].audienceRating)
{
for (int j = numMovies - 1; j >1; --j)
{
movies[j] = movies[j - 1];
}
temp1 = movies[i];
movies[i] = movie;
break;
}
}
}