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

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

package reservation; import java.util.; For Scanner Class .pdf
 package reservation; import java.util.; For Scanner Class .pdf package reservation; import java.util.; For Scanner Class .pdf
package reservation; import java.util.; For Scanner Class .pdf
anitasahani11
 
Python 03-parameters-graphics.pptx
Python 03-parameters-graphics.pptxPython 03-parameters-graphics.pptx
Python 03-parameters-graphics.pptx
TseChris
 
FP in JS-Land
FP in JS-LandFP in JS-Land
FP in JS-Land
Robert Pearce
 
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
ShaiAlmog1
 
Write a Java program that mimics the framework for an online movie i.pdf
Write a Java program that mimics the framework for an online movie i.pdfWrite a Java program that mimics the framework for an online movie i.pdf
Write a Java program that mimics the framework for an online movie i.pdf
mohdjakirfb
 
Nasamatic NewHaven.IO 2014 05-21
Nasamatic NewHaven.IO 2014 05-21Nasamatic NewHaven.IO 2014 05-21
Nasamatic NewHaven.IO 2014 05-21
Prasanna Gautam
 
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
 
I am having a hard time with this problem, can you help me #5. .pdf
I am having a hard time with this problem, can you help me #5. .pdfI am having a hard time with this problem, can you help me #5. .pdf
I am having a hard time with this problem, can you help me #5. .pdf
aroramobiles1
 
Refactoring Example
Refactoring ExampleRefactoring Example
Refactoring Example
liufabin 66688
 
Term 2 CS Practical File 2021-22.pdf
Term 2 CS Practical File 2021-22.pdfTerm 2 CS Practical File 2021-22.pdf
Term 2 CS Practical File 2021-22.pdf
KiranKumari204016
 
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
 
Fact, Fiction, and FP
Fact, Fiction, and FPFact, Fiction, and FP
Fact, Fiction, and FP
Brian Lonsdorf
 
DBMS Case Study B3.pptx
DBMS Case Study B3.pptxDBMS Case Study B3.pptx
DBMS Case Study B3.pptx
sahithisammeta
 
Dependency Injection in PHP
Dependency Injection in PHPDependency Injection in PHP
Dependency Injection in PHP
Kacper Gunia
 
SQL Training in Ambala ! Batra Computer Centre
SQL Training in Ambala ! Batra Computer CentreSQL Training in Ambala ! Batra Computer Centre
SQL Training in Ambala ! Batra Computer Centre
jatin batra
 
XML-Free Programming
XML-Free ProgrammingXML-Free Programming
XML-Free Programming
Stephen Chin
 
การทำหิมะตกใน Flash
การทำหิมะตกใน Flashการทำหิมะตกใน Flash
การทำหิมะตกใน Flash
ลูกแก้ว กนกวรรณ
 
Continuous Innovation @ Gilt Groupe
Continuous Innovation @ Gilt GroupeContinuous Innovation @ Gilt Groupe
Continuous Innovation @ Gilt Groupe
Eric Bowman
 
Graph Databases
Graph DatabasesGraph Databases
Graph Databases
Josh Adell
 

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

package reservation; import java.util.; For Scanner Class .pdf
 package reservation; import java.util.; For Scanner Class .pdf package reservation; import java.util.; For Scanner Class .pdf
package reservation; import java.util.; For Scanner Class .pdf
 
Python 03-parameters-graphics.pptx
Python 03-parameters-graphics.pptxPython 03-parameters-graphics.pptx
Python 03-parameters-graphics.pptx
 
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
 
Write a Java program that mimics the framework for an online movie i.pdf
Write a Java program that mimics the framework for an online movie i.pdfWrite a Java program that mimics the framework for an online movie i.pdf
Write a Java program that mimics the framework for an online movie i.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
 
I am having a hard time with this problem, can you help me #5. .pdf
I am having a hard time with this problem, can you help me #5. .pdfI am having a hard time with this problem, can you help me #5. .pdf
I am having a hard time with this problem, can you help me #5. .pdf
 
Refactoring Example
Refactoring ExampleRefactoring Example
Refactoring Example
 
Term 2 CS Practical File 2021-22.pdf
Term 2 CS Practical File 2021-22.pdfTerm 2 CS Practical File 2021-22.pdf
Term 2 CS Practical File 2021-22.pdf
 
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
 
Fact, Fiction, and FP
Fact, Fiction, and FPFact, Fiction, and FP
Fact, Fiction, and FP
 
DBMS Case Study B3.pptx
DBMS Case Study B3.pptxDBMS Case Study B3.pptx
DBMS Case Study B3.pptx
 
Dependency Injection in PHP
Dependency Injection in PHPDependency Injection in PHP
Dependency Injection in PHP
 
SQL Training in Ambala ! Batra Computer Centre
SQL Training in Ambala ! Batra Computer CentreSQL Training in Ambala ! Batra Computer Centre
SQL Training in Ambala ! Batra Computer Centre
 
XML-Free Programming
XML-Free ProgrammingXML-Free Programming
XML-Free Programming
 
การทำหิมะตกใน Flash
การทำหิมะตกใน Flashการทำหิมะตกใน Flash
การทำหิมะตกใน Flash
 
Continuous Innovation @ Gilt Groupe
Continuous Innovation @ Gilt GroupeContinuous Innovation @ Gilt Groupe
Continuous Innovation @ Gilt Groupe
 
Graph Databases
Graph DatabasesGraph Databases
Graph Databases
 

More from adelaidefarmer322

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
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 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
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
 
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
adelaidefarmer322
 
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
adelaidefarmer322
 
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
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
 
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
adelaidefarmer322
 
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
adelaidefarmer322
 
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
adelaidefarmer322
 
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
adelaidefarmer322
 
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
adelaidefarmer322
 
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
adelaidefarmer322
 
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
adelaidefarmer322
 
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
adelaidefarmer322
 
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
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

Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 

Recently uploaded (20)

Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 

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; }