SlideShare a Scribd company logo
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 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
(myToLower(movies[ndx].getTitle()).find(mc)==
string::npos);ndx++);
mn = ndx
return ndx
}
}
const Movie * Movies::getMovie(int mc) const {
return (mc > 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
movies[i] = m[i];
delete[] m; // null assignment not needed; end of method
}
string Movies::myToLower(string s) const {
int n = s.length();
string t(s);
for(int i=0;i
t[i] = tolower(s[i]);
return t;
}

More Related Content

DOCX
Objectives The main objective of this assignment is checking .docx
DOCX
Objectives The main objective of this assignment is checking .docx
PDF
Can you convert this code into a C++ code.pdf
PDF
struct Movie stdstring title Movie.pdf
PDF
#include stdafx.h#include iostream#include Stringusing.pdf
DOCX
C++ project
DOCX
Lab Assignment #6, part 3 Time ConversionProgram Name lab.docx
PPTX
Chapter1.pptx
Objectives The main objective of this assignment is checking .docx
Objectives The main objective of this assignment is checking .docx
Can you convert this code into a C++ code.pdf
struct Movie stdstring title Movie.pdf
#include stdafx.h#include iostream#include Stringusing.pdf
C++ project
Lab Assignment #6, part 3 Time ConversionProgram Name lab.docx
Chapter1.pptx

Similar to Modify Assignment 5 toReplace the formatted output method (toStri.docx (20)

PDF
Write a Java program that mimics the framework for an online movie i.pdf
PDF
File yuan.h#include iostream#include fstream#include .pdf
PDF
Answer main.cpp.pdf
PDF
Basic c++ 11/14 for python programmers
DOCX
computer science project on movie booking system
PDF
C++11 Idioms @ Silicon Valley Code Camp 2012
PDF
fully comments for my program, thank you will thumb up#include io.pdf
PDF
C++ Programming (Please help me!! Thank you!!)Problem A Win SimU.pdf
DOCX
C++ assignment
PDF
GECon 2017: C++ - a Monster that no one likes but that will outlast them all
PDF
GECon2017_Cpp a monster that no one likes but that will outlast them all _Ya...
PDF
Help with the following code1. Rewrite to be contained in a vecto.pdf
DOCX
Library Managment System - C++ Program
PPTX
Chp 3 C++ for newbies, learn fast and earn fast
DOCX
Programming homework
PDF
LAB (100-) The Numbers Module Your task for this lab is to complete.pdf
PDF
[Cntt] all c++ functions
PPTX
25 лет истории C++, пролетевшей на моих глазах
PPTX
C++ Programming Homework Help
PDF
To write a program that implements the following C++ concepts 1. Dat.pdf
Write a Java program that mimics the framework for an online movie i.pdf
File yuan.h#include iostream#include fstream#include .pdf
Answer main.cpp.pdf
Basic c++ 11/14 for python programmers
computer science project on movie booking system
C++11 Idioms @ Silicon Valley Code Camp 2012
fully comments for my program, thank you will thumb up#include io.pdf
C++ Programming (Please help me!! Thank you!!)Problem A Win SimU.pdf
C++ assignment
GECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon2017_Cpp a monster that no one likes but that will outlast them all _Ya...
Help with the following code1. Rewrite to be contained in a vecto.pdf
Library Managment System - C++ Program
Chp 3 C++ for newbies, learn fast and earn fast
Programming homework
LAB (100-) The Numbers Module Your task for this lab is to complete.pdf
[Cntt] all c++ functions
25 лет истории C++, пролетевшей на моих глазах
C++ Programming Homework Help
To write a program that implements the following C++ concepts 1. Dat.pdf

More from adelaidefarmer322 (20)

DOCX
Must be in APA format (12 point font, Times New Roman, double spaced.docx
DOCX
Must be done within 4 hoursAnswer the following Discussion each wi.docx
DOCX
Must be in APA format, and answer must be from Peak, K. J. (2012.docx
DOCX
MUST BE DONE IN EXCELThe Effect of Leverage on Firm Earn.docx
DOCX
Must be in APA format Times New Roman, 12-point font, double spac.docx
DOCX
Must be cited in APA format to include siting references.You.docx
DOCX
Must be 250 word countDiscuss the motivatorsrewards that encour.docx
DOCX
Must be 200 to 250 words. Due by 92713What is reliability and va.docx
DOCX
MUSIC THE MIDDLE AGES AND THE RENAISSANCE1.In musical languag.docx
DOCX
Must be 200-250 words. Due on 92713What is reliability and val.docx
DOCX
Must be 300 words.What are the stages of therapy  Describe .docx
DOCX
Must be 400 wordsuse my referencesReferencesAshford University.docx
DOCX
Munch Printing Inc. began printing operations on August 1. Jobs 10 a.docx
DOCX
music history on the british invasion MLA formatEach paper shoul.docx
DOCX
Multistage health survey A researcher wants to studyregional diffe.docx
DOCX
Music and SoundscapesUsing the video clips, below,.docx
DOCX
Multiples analysis Turner Corp. has debt of $230 million and gene.docx
DOCX
Must be 200-250 words. Due on 92513If you were a researcher who .docx
DOCX
Multiple Choice Read each question and select the.docx
DOCX
Multiple Question test pick a. b. c. or d. is timed and I have 23 ho.docx
Must be in APA format (12 point font, Times New Roman, double spaced.docx
Must be done within 4 hoursAnswer the following Discussion each wi.docx
Must be in APA format, and answer must be from Peak, K. J. (2012.docx
MUST BE DONE IN EXCELThe Effect of Leverage on Firm Earn.docx
Must be in APA format Times New Roman, 12-point font, double spac.docx
Must be cited in APA format to include siting references.You.docx
Must be 250 word countDiscuss the motivatorsrewards that encour.docx
Must be 200 to 250 words. Due by 92713What is reliability and va.docx
MUSIC THE MIDDLE AGES AND THE RENAISSANCE1.In musical languag.docx
Must be 200-250 words. Due on 92713What is reliability and val.docx
Must be 300 words.What are the stages of therapy  Describe .docx
Must be 400 wordsuse my referencesReferencesAshford University.docx
Munch Printing Inc. began printing operations on August 1. Jobs 10 a.docx
music history on the british invasion MLA formatEach paper shoul.docx
Multistage health survey A researcher wants to studyregional diffe.docx
Music and SoundscapesUsing the video clips, below,.docx
Multiples analysis Turner Corp. has debt of $230 million and gene.docx
Must be 200-250 words. Due on 92513If you were a researcher who .docx
Multiple Choice Read each question and select the.docx
Multiple Question test pick a. b. c. or d. is timed and I have 23 ho.docx

Recently uploaded (20)

PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
Institutional Correction lecture only . . .
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Lesson notes of climatology university.
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Sports Quiz easy sports quiz sports quiz
Institutional Correction lecture only . . .
human mycosis Human fungal infections are called human mycosis..pptx
Module 4: Burden of Disease Tutorial Slides S2 2025
102 student loan defaulters named and shamed – Is someone you know on the list?
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Basic Mud Logging Guide for educational purpose
Microbial diseases, their pathogenesis and prophylaxis
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Microbial disease of the cardiovascular and lymphatic systems
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
TR - Agricultural Crops Production NC III.pdf
Lesson notes of climatology university.
2.FourierTransform-ShortQuestionswithAnswers.pdf

Modify Assignment 5 toReplace the formatted output method (toStri.docx

  • 1. 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);
  • 2. 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
  • 3. 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
  • 4. #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);
  • 5. } 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 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);
  • 6. } 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];
  • 7. } 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();
  • 8. } 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 {
  • 9. if(mc.length()==0) return nullptr; // not found else { mc = myToLower(mc); int ndx=0; for(;ndx (myToLower(movies[ndx].getTitle()).find(mc)== string::npos);ndx++); mn = ndx return ndx } } const Movie * Movies::getMovie(int mc) const { return (mc > 0 && mc <= movieCnt)?&movies[mc-1]:nullptr; } Movies::~Movies() { delete[] movies; movies = nullptr; }
  • 10. 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 movies[i] = m[i];
  • 11. delete[] m; // null assignment not needed; end of method } string Movies::myToLower(string s) const { int n = s.length(); string t(s); for(int i=0;i t[i] = tolower(s[i]); return t; }