Question

BACKGROUND Movie Review sites collect reviews and will often provide some sort of average review to...

BACKGROUND

Movie Review sites collect reviews and will often provide some sort of average review to sort movies by their quality. In this assignment, you will collect a list of movies and then a list of reviews for each movie. You will then take a simple average (total of reviews divided by number of reviews) for each movie and output a sorted list of movies with their average review. Here you are provided the shell of a program and asked to finish the implementation. All the functions you need are already defined, you simply must implement them. Do not remove or rename existing functions, nor add any additional functions!


REQUIREMENTS

1. There will be 2 input files and 1 output file for the program.

2. The first input file will be in the following format: [movie id] [movie name] The value for the movie id will be in sequential order starting at 1. The value for the movie name will start after whitespace and continue to the rest of the line. Note that the movie name may have spaces and punctuation as part of the name.

3. The second input file will be in the following format: [movie id] [rating 1] [rating 2] … [rating n] Where the movie id will correspond to the id from the first input file. There may be 1 or more integer ratings for each movie and the number of ratings may not be the same for all movies (i.e. one movie may have 5 reviews, and another 25).

4. The output file will be in the following format [movie id] [average rating] [movie name] Where the movies are sorted in descending order by average rating (represented by a floatingpoint value truncated to 2 decimal places).

5. The program will not contain any memory leaks.

6. The program will not use any custom loops. For this assignment, you are to use std:: functions only (std::for_each, std::transform, std::copy, etc., from the <algorithm> library, as well as any member functions provided by the std::vector and std::list containers).

7. The only changes will be to the movieratings.h file. 8. The only changes will be where the TODO: // Implement lines appear

MAIN.cpp

#include <iostream>
#include <iterator>
#include <fstream>
#include <sstream>
#include <string>

#include "movieratings.h"


/// The main entry point for the application
/// argc - the number of command line parameters. This will always be at least 1
/// argv - the command line parameters. The first parameter is always the name of the application
int main(int argc, char** argv)
{
   // To run the program, it requires 4 command line parameters:
   // argv[0] - the application name
   // argv[1] - the input file for the movie list
   // argv[2] - the input file for the movie ratings
   // argv[3] - the output file for the results
   if (argc != 4)
   {
       std::cout << "Usage: assignment01 [movie input file] [ratings input file] [output file]" << std::endl;
       return 0;
   }

   // Create the input streams
   std::ifstream finMovies(argv[1]);
   std::ifstream finRatings(argv[2]);

   // Create the output stream
   std::ofstream fout(argv[3]);

   // create the begin and end iterators for the input files
   std::istream_iterator<Movie> beginMovies(finMovies);
   std::istream_iterator<Movie> endMovies;
   std::istream_iterator<Rating> beginRatings(finRatings);
   std::istream_iterator<Rating> endRatings;

   // create the Movie Ratings object
   // note that it takes the iterators previously created
   MovieRatings ratings(beginMovies, endMovies, beginRatings, endRatings);
   ratings.GenerateResults(fout);

   return 0;
}

MOVIE.h

#ifndef __MOVIE_H__

#define __MOVIE_H__

#include <iostream>
#include <string>

class Movie
{
private:
   int m_ID;
   std::string m_Name;
public:
   Movie() : m_ID(-1)
   {

   }

   int GetID() const
   {
       return m_ID;
   }

   void SetID(int id)
   {
       m_ID = id;
   }

   std::string GetName() const
   {
       return m_Name;
   }
  
   void SetName(const std::string& name)
   {
       m_Name = name;
   }

   friend std::istream& operator>>(std::istream& is, Movie& g);
   friend std::ostream& operator<<(std::ostream& os, const Movie& g);
};

std::ostream& operator<<(std::ostream& os, const Movie& g)
{
   os << g.m_ID << " " << g.m_Name << std::endl;
   return os;
}

#endif // __MOVIE_H__

RATING.h

#ifndef __RATING_H__
#define __RATING_H__

#include <algorithm>
#include <iostream>
#include <iterator>
#include <list>
#include <numeric>

class Rating
{
private:
   int m_ID;
   std::list<int> m_Ratings;
public:
   Rating()
   {
   }

   int GetID() const
   {
       return m_ID;
   }

   void SetID(int id)
   {
       m_ID = id;
   }

   std::list<int> GetRatings() const
   {
       return m_Ratings;
   }

   void SetRatings(const std::list<int>& ratings)
   {
       m_Ratings = ratings;
   }

   float GetAverageRating() const
   {
       int totalRatings = std::accumulate(m_Ratings.begin(), m_Ratings.end(), 0);
       int count = m_Ratings.size();
       float result = static_cast<float>(totalRatings) / static_cast<float>(count);
       return result;
   }

   bool operator> (const Rating& rhs) const
   {
       float l = GetAverageRating();
       float r = rhs.GetAverageRating();
       return l > r;
   }

   friend std::istream& operator>>(std::istream& is, Rating& r);
   friend std::ostream& operator<<(std::ostream& os, const Rating& r);
};

std::ostream& operator<<(std::ostream& os, const Rating& r)
{
   os << r.m_ID << " ";
   std::copy(r.m_Ratings.begin(), r.m_Ratings.end(), std::ostream_iterator<int>(os, " "));
   os << std::endl;
   return os;
}

#endif // __RATING_H__

MOVIERATINGS.h (Only file to edit)

#ifndef __MOVIE_RATINGS_H__
#define __MOVIE_RATINGS_H__

#include <algorithm>
#include <iomanip>
#include <iterator>
#include <list>
#include <vector>

#include "movie.h"
#include "rating.h"

class MovieRatings
{
private:
   std::vector<Movie> m_Movies;
   std::vector<Rating> m_Ratings;

public:
   template<class MovieInputIterator, class RatingInputIterator>
   MovieRatings(MovieInputIterator movieBegin, MovieInputIterator movieEnd, RatingInputIterator ratingBegin, RatingInputIterator ratingEnd)
   {
       // TODO: Implement the constructor to load the m_Movies and m_Ratings containers
   }

   void GenerateResults(std::ostream& os) const
   {
       // TODO: Implement the GenerateResults function to output the movie id, average rating, and movie name in descending order by average rating
       // NOTE: do not modify the m_Movies or m_Ratings objects in this function!
   }
};

std::istream& operator>>(std::istream& is, Movie& g)
{
   // TODO: Read in the movie id and movie name for a single movie
}
  
std::istream& operator>>(std::istream& is, Rating& r)
{
   // TODO: Read in the movie id and list of movie ratings for a single movie
}

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

// TODO: Implement the constructor to load the m_Movies and m_Ratings containers

To implement the above case run a for_each loop to iterate from beginning to end as the beginning and end values are given as the input parameters.

movieBegin, - Beginning for movie list

movieEnd, - End for movie list

ratingBegin, -Beginning for rating list.

ratingEnd - End for rating list

===============================================================================================

===============================================================================================

// TODO: Implement the GenerateResults function to output the movie id, average rating, and movie name in descending order by average rating
// NOTE: do not modify the m_Movies or m_Ratings objects in this function!

To implement create copy of M_Ratings and group the rating based on movie id and find the average and place in a list object with key as movie id.

Sort the list in descending order, to get the order of the movie ids now print them with their corresponding name and average rating.

==============================================================================================

==============================================================================================

// TODO: Read in the movie id and movie name for a single movie

To implement store the movie id as the key and movie name as the value for the key in the movie list object.

==============================================================================================

==============================================================================================

// TODO: Read in the movie id and list of movie ratings for a single movie

To implement store the movie id as the key and movie ratings array as the value for the key in the ratings list object.

Add a comment
Know the answer?
Add Answer to:
BACKGROUND Movie Review sites collect reviews and will often provide some sort of average review to...
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
  • I need help with the code below. It is a C program, NOT C++. It can...

    I need help with the code below. It is a C program, NOT C++. It can only include '.h' libraries. I believe the program is in C++, but it must be a C program. Please help. // // main.c // float_stack_class_c_9_29 // // /* Given the API for a (fixed size), floating point stack class, write the code to create a stack class (in C). */ #include #include #include #include header file to read and print the output on console...

  • The task is to write Song.cpp to complete the implementation of the Song class, as defined...

    The task is to write Song.cpp to complete the implementation of the Song class, as defined in the provided header file, Song.h, and then to complete a program (called sales) that makes use of the class. As in Project 1, an input data file will be provided containing the song name and other information in the same format as in Program 1: Artist    Song_Title    Year    Sales    Medium As before, the program (sales) which are individual copies, will use this information to compute the gross...

  • C++ Language I have a class named movie which allows a movie object to take the...

    C++ Language I have a class named movie which allows a movie object to take the name, movie and rating of a movie that the user inputs. Everything works fine but when the user enters a space in the movie's name, the next function that is called loops infinetly. I can't find the source of the problem. Down below are my .cpp and .h file for the program. #include <iostream> #include "movie.h" using namespace std; movie::movie() { movieName = "Not...

  • For the LinkedList class, create a getter and setter for the private member 'name', constructing your...

    For the LinkedList class, create a getter and setter for the private member 'name', constructing your definitions based upon the following declarations respectively: std::string get_name() const; and void set_name(std::string); In the Main.cpp file, let's test your getter and setter for the LinkedLIst private member 'name'. In the main function, add the following lines of code: cout << ll.get_name() << endl; ll.make_test_list(); ll.set_name("My List"); cout << ll.get_name() << endl; Output should be: Test List My List Compile and run your code;...

  • C++ project we need to create a class for Book and Warehouse using Book.h and Warehouse.h header ...

    C++ project we need to create a class for Book and Warehouse using Book.h and Warehouse.h header files given. Then make a main program using Book and Warehouse to read data from book.dat and have functions to list and find book by isbn Objectives: Class Association and operator overloading This project is a continuation from Project 1. The program should accept the same input data file and support the same list and find operations. You will change the implementation of...

  • #include <iostream> #include <string> #include "hashT.h" #include "stateData.h" using namespace std; void stateData::setStateInfo(string sName, string sCapital,...

    #include <iostream> #include <string> #include "hashT.h" #include "stateData.h" using namespace std; void stateData::setStateInfo(string sName, string sCapital,    double stArea, int yAdm, int oAdm) {    stateName = sName; stateCapital = sCapital; stArea = stateArea; yAdm = yearOfAdmission; oAdm = orderOfAdmission;       } void stateData::getStateInfo(string& sName, string& sCapital,    double& stArea, int& yAdm, int& oAdm) {    sName = stateName; sCapital = stateCapital; stArea = stateArea; yAdm = yearOfAdmission; oAdm = orderOfAdmission;       } string stateData::getStateName() { return stateName;...

  • Hi guys! I need help for the Data Structure class i need to provide implementation of...

    Hi guys! I need help for the Data Structure class i need to provide implementation of the following methods: Destructor Add Subtract Multiply Derive (extra credit ) Evaluate (extra credit ) ------------------------------------------------------- This is Main file cpp file #include "polynomial.h" #include <iostream> #include <sstream> using std::cout; using std::cin; using std::endl; using std::stringstream; int main(int argc, char* argv[]){    stringstream buffer1;    buffer1.str(        "3 -1 2 0 -2.5"    );    Polynomial p(3);    p.Read(buffer1);    cout << p.ToString()...

  • In this assignment you are required to complete a class for fractions. It stores the numerator...

    In this assignment you are required to complete a class for fractions. It stores the numerator and the denominator, with the lowest terms. It is able to communicate with iostreams by the operator << and >>. For more details, read the header file. //fraction.h #ifndef FRACTION_H #define FRACTION_H #include <iostream> class fraction { private: int _numerator, _denominator; int gcd(const int &, const int &) const; // If you don't need this method, just ignore it. void simp(); // To get...

  • i need to make a simple hash function for an id in my size_t function it...

    i need to make a simple hash function for an id in my size_t function it works it need to print out numeric numbers and it has to be six numbers i think i need a loop here what it print out input.txt bob 4517898 102 tell rd gill 4787456 103 hmm rd output.txt 126990 bob 4517898 102 tell rd 126990 gill 4787456 103 hmm rd #ifndef __CUSTOMER_H__ #define __CUSTOMER_H__ #include #include struct customer {    std::string name;    std::string...

  • /* FILE: ./shapes7/shape.h */ #include <iostream> using std::ostream; class shape{ int x,y; public: shape( ) {...

    /* FILE: ./shapes7/shape.h */ #include <iostream> using std::ostream; class shape{ int x,y; public: shape( ) { x=y=0;} shape(int xvalue, int yvalue); void setShape(int new_x, int new_y); void setX(int new_x); void setY(int new_y); int getX( ) const; int getY( ) const; virtual void move(int x, int y) = 0; virtual void shift(int dx, int dy) = 0; virtual void draw( ) = 0; virtual void rotate(double r) = 0; virtual void print(ostream&)const; friend ostream & operator<<(ostream & os, const shape& s);...

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