SlideShare a Scribd company logo
1 of 11
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

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

struct Movie stdstring title Movie.pdf
struct Movie      stdstring title               Movie.pdfstruct Movie      stdstring title               Movie.pdf
struct Movie stdstring title Movie.pdf
kiraan007
 
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdfIfgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
fazilfootsteps
 
openFrameworks 007 - graphics
openFrameworks 007 - graphicsopenFrameworks 007 - graphics
openFrameworks 007 - graphics
roxlu
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdf
archanaemporium
 
Filmstrip testing
Filmstrip testingFilmstrip testing
Filmstrip testing
ClarkTony
 
Can you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdfCan you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdf
aksachdevahosymills
 

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

FP in JS-Land
FP in JS-LandFP in JS-Land
FP in JS-Land
 
Building a Native Camera Access Library - Part V.pdf
Building a Native Camera Access Library - Part V.pdfBuilding a Native Camera Access Library - Part V.pdf
Building a Native Camera Access Library - Part V.pdf
 
struct Movie stdstring title Movie.pdf
struct Movie      stdstring title               Movie.pdfstruct Movie      stdstring title               Movie.pdf
struct Movie stdstring title Movie.pdf
 
Nasamatic NewHaven.IO 2014 05-21
Nasamatic NewHaven.IO 2014 05-21Nasamatic NewHaven.IO 2014 05-21
Nasamatic NewHaven.IO 2014 05-21
 
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdfIfgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
 
Refactoring Example
Refactoring ExampleRefactoring Example
Refactoring Example
 
openFrameworks 007 - graphics
openFrameworks 007 - graphicsopenFrameworks 007 - graphics
openFrameworks 007 - graphics
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdf
 
การทำหิมะตกใน Flash
การทำหิมะตกใน Flashการทำหิมะตกใน Flash
การทำหิมะตกใน Flash
 
Continuous Innovation @ Gilt Groupe
Continuous Innovation @ Gilt GroupeContinuous Innovation @ Gilt Groupe
Continuous Innovation @ Gilt Groupe
 
Open Cv Tutorial Ii
Open Cv Tutorial IiOpen Cv Tutorial Ii
Open Cv Tutorial Ii
 
Open Cv Tutorial Ii
Open Cv Tutorial IiOpen Cv Tutorial Ii
Open Cv Tutorial Ii
 
betterCode() Go: Einstieg in Go, Standard-Library und Ökosystem
betterCode() Go: Einstieg in Go, Standard-Library und ÖkosystembetterCode() Go: Einstieg in Go, Standard-Library und Ökosystem
betterCode() Go: Einstieg in Go, Standard-Library und Ökosystem
 
CPP Quiz
CPP QuizCPP Quiz
CPP Quiz
 
JavaForum Nord 2021: Java to Go - Google Go für Java-Entwickler
JavaForum Nord 2021: Java to Go - Google Go für Java-EntwicklerJavaForum Nord 2021: Java to Go - Google Go für Java-Entwickler
JavaForum Nord 2021: Java to Go - Google Go für Java-Entwickler
 
Filmstrip testing
Filmstrip testingFilmstrip testing
Filmstrip testing
 
New Tools for a More Functional C++
New Tools for a More Functional C++New Tools for a More Functional C++
New Tools for a More Functional C++
 
Imdb import presentation
Imdb import presentationImdb import presentation
Imdb import presentation
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
Can you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdfCan you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdf
 

More from adelaidefarmer322

Must be done within 4 hoursAnswer the following Discussion each wi.docx
Must be done within 4 hoursAnswer the following Discussion each wi.docxMust be done within 4 hoursAnswer the following Discussion each wi.docx
Must be done within 4 hoursAnswer the following Discussion each wi.docx
adelaidefarmer322
 
Must be in APA format, and answer must be from Peak, K. J. (2012.docx
Must be in APA format, and answer must be from Peak, K. J. (2012.docxMust be in APA format, and answer must be from Peak, K. J. (2012.docx
Must be in APA format, and answer must be from Peak, K. J. (2012.docx
adelaidefarmer322
 
Must be in APA format Times New Roman, 12-point font, double spac.docx
Must be in APA format Times New Roman, 12-point font, double spac.docxMust be in APA format Times New Roman, 12-point font, double spac.docx
Must be in APA format Times New Roman, 12-point font, double spac.docx
adelaidefarmer322
 
MUSIC THE MIDDLE AGES AND THE RENAISSANCE1.In musical languag.docx
MUSIC THE MIDDLE AGES AND THE RENAISSANCE1.In musical languag.docxMUSIC THE MIDDLE AGES AND THE RENAISSANCE1.In musical languag.docx
MUSIC THE MIDDLE AGES AND THE RENAISSANCE1.In musical languag.docx
adelaidefarmer322
 
Multiple Choice Read each question and select the.docx
Multiple Choice Read each question and select the.docxMultiple Choice Read each question and select the.docx
Multiple Choice Read each question and select the.docx
adelaidefarmer322
 
Multiple Question test pick a. b. c. or d. is timed and I have 23 ho.docx
Multiple Question test pick a. b. c. or d. is timed and I have 23 ho.docxMultiple Question test pick a. b. c. or d. is timed and I have 23 ho.docx
Multiple Question test pick a. b. c. or d. is timed and I have 23 ho.docx
adelaidefarmer322
 

More from adelaidefarmer322 (20)

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

Recently uploaded

會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 

Recently uploaded (20)

AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.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; }