C++ homework

Modify Assignment 5 to:Replace the formatted output method (toString) with an overloaded output/insertion operator, and modify the driver to use the overloaded operator.Incorporate the capability to access movies by the movie number or by a search string, if this wasn’t part of your Assignment 5.Replace the getMovie(int) [or your solution equivalent] with an overloaded subscript operator ([ ]), which takes an integer and returns a Movie (or Movie reference).Account for an invalid movie number.HEADER FILE // Movie.h#ifndef MOVIE_H#define MOVIE_H#include using namespace std; class Movie { // data is private by default    string title, studio; long long boxOffice[3]; // World, US, non-US short rank[3], releaseYear; // World, US, non-US enum unit {WORLD, US, NON_US}; public: Movie(); Movie(string);  string getTitle() const;  string getStudio() const;    long long getWorldBoxOffice() const;    long long getUSBoxOffice() const;    long long getNonUSBoxOffice() const;    int getWorldRank() const;    int getUSRank() const;    int getNonUSRank() const;    int getReleaseYear() const;  string toString() const;private: Movie(const Movie &); // private copy constructor blocks invocation};#endif HEADER FILE // Movies.h#ifndef MOVIES_H#define MOVIES_H#include “Movie.h” // include Movie class definition#include using namespace std; class Movies { // data is private by default static const int MAX_MOVIES = 1000; Movie *movies; short movieCnt; public: Movies(string); int getMovieCount() const; const Movie * getMovie(string, int&) const; const Movie * getMovie(int) const; ~Movies(); private: void loadMovies(string); string myToLower(string) const; void reSize();};#endif CPP FILE // MovieInfoApp.cpp#include “Movie.h” // include Movie class definition#include “Movies.h” // include Movies class definition#include #include #include #include using namespace std; void main() { Movies movies(“Box Office Mojo.txt”); if(movies.getMovieCount() > 0) { string movieCode; cout << “Please enter the movie search string,nentering a leading # to retrieve by movie number” << “n or a ^ to get the next movie (press Enter to exit): “; getline(cin, movieCode); if (movieCode.length() > 0) { int mn = 0; const Movie * m; do { if(movieCode[0] != ‘#’ && movieCode[0] != ‘^’) m = movies.getMovie(movieCode, mn); else if(movieCode[0] == ‘#’){ // get by number mn = stoi(movieCode.substr(1)); m = movies.getMovie(mn); } else if(movieCode[0] == ‘^’) // get next movie m = movies.getMovie(++mn); if(m != nullptr) { cout << m->toString() << “n”; if(m->getWorldBoxOffice() > 0) cout << setprecision(1) << fixed << “ntNon-US to World Ratio:t” << (m->getNonUSBoxOffice() * 100.0) /  m->getWorldBoxOffice() << “%n” << endl; else cout << “No ratio due to zero World Box Officen”; } else { cout << “n Movie not found!nn” << endl; mn = 0; } cout << “Please

💡 Buy the answer for only $12 Get it now →

enter the movie search string,nentering a leading # to retrieve by movie number” << “n or a ^ to get the next movie (press Enter to exit): “; getline(cin, movieCode); } while (movieCode.length() > 0); } }} CPP FILE // Movie.cpp#include “Movie.h” // include Movie class definition#include using namespace std; Movie::Movie() { title = studio = “”; boxOffice[WORLD] = boxOffice[US] = boxOffice[NON_US] =  rank[WORLD] = rank[US] = rank[NON_US] = releaseYear = 0;} Movie::Movie(string temp) { istringstream iS(temp); getline(iS, title, ‘t’); getline(iS, studio, ‘t’); iS >> releaseYear >> boxOffice[WORLD] >> boxOffice[US] >> boxOffice[NON_US] >> rank[WORLD] >> rank[US] >> rank[NON_US];} string Movie::getTitle() const {return title;}string Movie::getStudio() const {return studio;}long long Movie::getUSBoxOffice() const {return boxOffice[US];}long long Movie::getNonUSBoxOffice() const {return boxOffice[NON_US];}long long Movie::getWorldBoxOffice() const {return boxOffice[WORLD];}int Movie::getUSRank() const {return rank[US];}int Movie::getNonUSRank() const {return rank[NON_US];}int Movie::getWorldRank() const {return rank[WORLD];}int Movie::getReleaseYear() const {return releaseYear;} string Movie::toString() const { ostringstream oS; oS << “nn====================== Movie Informationn” << “n             Movie Title:t” << title << ”  (” << releaseYear << “)” << “n    US Rank & Box Office:t” << rank[US] << “t$” << boxOffice[US] << “nNon-US Rank & Box Office:t” << rank[NON_US] << “t$” << boxOffice[NON_US] << “n World Rank & Box Office:t” << rank[WORLD] << “t$” << boxOffice[WORLD] << “n”; return oS.str();} Movie::Movie(const Movie &mP) { // copy constructor this->title = mP.title; this->studio = mP.studio; this->releaseYear = mP.releaseYear; this->rank[US] = mP.rank[US]; this->rank[NON_US] = mP.rank[NON_US]; this->rank[WORLD] = mP.rank[WORLD]; this->boxOffice[US] = mP.boxOffice[US]; this->boxOffice[NON_US] = mP.boxOffice[NON_US]; this->boxOffice[WORLD] = mP.boxOffice[WORLD];} CPP FILE // Movies.cpp#include “Movie.h” // include Movie class definition#include “Movies.h” // include Movies class definition#include using namespace std; Movies::Movies(string fn){loadMovies(fn);} int Movies::getMovieCount() const {return movieCnt;} const Movie * Movies::getMovie(string mc, int& mn) const { if(mc.length()==0) return nullptr; // not found else { mc = myToLower(mc); int ndx=0; for(;ndx 0 && mc <= movieCnt)?&movies[mc-1]:nullptr;} Movies::~Movies() { delete[] movies; movies = nullptr;} void Movies::loadMovies(string fn) { ifstream iS(fn); string s; getline(iS, s); // skip heading getline(iS, s); movieCnt=0; movies = new Movie[MAX_MOVIES]; while(!iS.eof()) { movies[movieCnt++] = Movie(s); getline(iS, s); } iS.close(); reSize();} void Movies::reSize() { Movie * m = movies; movies = new Movie[movieCnt]; for(int i=0;i

💡 Buy the answer for only $12 Get it now →