Menu

Hi Came Across C Program Chegg Wanted Practice Following Concepts Class Objects Header Cpp Q43825460

Hi! I came across this c++ program on Chegg, and I wanted topractice with it the following concepts: class, objects, header andcpp file and searching a csv file. Can someone show me how thiscould be broken in a header file, cpp file and drive (main)program. Also, would reading and retrieving the information workdifferently from a regular text file and a csv file? From thesource of the project, the dealt with a regular text file withoutcommas, but I am practicing with a csv file.

————————————————————————————————————————

csv file:

Film,Genre,Lead Studio,Audience score %,Profitability,RottenTomatoes %,Worldwide Gross,Year
Zack and Miri Make a Porno,Romance,The WeinsteinCompany,70,1.747541667,64,$41.94 ,2008
Youth in Revolt,Comedy,The Weinstein Company,52,1.09,68,$19.62,2010
You Will Meet a Tall DarkStranger,Comedy,Independent,35,1.211818182,43,$26.66 ,2010
When in Rome,Comedy,Disney,44,0,15,$43.04 ,2010
What Happens in Vegas,Comedy,Fox,72,6.267647029,28,$219.37,2008
Water For Elephants,Drama,20th CenturyFox,72,3.081421053,60,$117.09 ,2011
WALL-E,Animation,Disney,89,2.896019067,96,$521.28 ,2008
Waitress,Romance,Independent,67,11.0897415,89,$22.18 ,2007
Waiting For Forever,Romance,Independent,53,0.005,6,$0.03,2011
Valentine’s Day,Comedy,Warner Bros.,54,4.184038462,17,$217.57,2010
Tyler Perry’s Why Did I getMarried,Romance,Independent,47,3.7241924,46,$55.86 ,2007
Twilight: BreakingDawn,Romance,Independent,68,6.383363636,26,$702.17 ,2011
Twilight,Romance,Summit,82,10.18002703,49,$376.66 ,2008
The Ugly Truth,Comedy,Independent,68,5.402631579,14,$205.30,2009
The Twilight Saga: New Moon,Drama,Summit,78,14.1964,27,$709.82,2009
The Time Traveler’s Wife,Drama,Paramount,65,2.598205128,38,$101.33,2009
The Proposal,Comedy,Disney,74,7.8675,43,$314.70 ,2009
The Invention of Lying,Comedy,Warner Bros.,47,1.751351351,56,$32.40,2009
The Heartbreak Kid,Comedy,Paramount,41,2.129444167,30,$127.77,2007
The Duchess,Drama,Paramount,68,3.207850222,60,$43.31 ,2008
The Curious Case of Benjamin Button,Fantasy,WarnerBros.,81,1.78394375,73,$285.43 ,2008
The Back-up Plan,Comedy,CBS,47,2.202571429,20,$77.09 ,2010
Tangled,Animation,Disney,88,1.365692308,89,$355.01 ,2010
Something Borrowed,Romance,Independent,48,1.719514286,15,$60.18,2011
She’s Out of My League,Comedy,Paramount,60,2.4405,57,$48.81,2010
Sex and the City Two,Comedy,Warner Bros.,49,2.8835,15,$288.35,2010
Sex and the City 2,Comedy,Warner Bros.,49,2.8835,15,$288.35,2010
Sex and the City,Comedy,Warner Bros.,81,7.221795791,49,$415.25,2008
Remember Me,Drama,Summit,70,3.49125,28,$55.86 ,2010
Rachel Getting Married,Drama,Independent,61,1.384166667,85,$16.61,2008
Penelope,Comedy,Summit,74,1.382799733,52,$20.74 ,2008
P.S. I Love You,Romance,Independent,82,5.103116833,21,$153.09,2007
Over Her Dead Body,Comedy,New Line,47,2.071,15,$20.71 ,2008
Our Family Wedding,Comedy,Independent,49,0,14,$21.37 ,2010
One Day,Romance,Independent,54,3.682733333,37,$55.24 ,2011
Not Easily Broken,Drama,Independent,66,2.14,34,$10.70 ,2009
No Reservations,Comedy,Warner Bros.,64,3.307180357,39,$92.60,2007
Nick and Norah’s InfinitePlaylist,Comedy,Sony,67,3.3527293,73,$33.53 ,2008
New Year’s Eve,Romance,Warner Bros.,48,2.536428571,8,$142.04,2011
My Week with Marilyn,Drama,The Weinstein Company,84,0.8258,83,$8.26,2011
Music and Lyrics,Romance,Warner Bros.,70,3.64741055,63,$145.90,2007
Monte Carlo,Romance,20th Century Fox,50,1.9832,38,$39.66,2011
Miss Pettigrew Lives for aDay,Comedy,Independent,70,0.2528949,78,$15.17 ,2008
Midnight in Paris,Romence,Sony,84,8.744705882,93,$148.66,2011
Marley and Me,Comedy,Fox,77,3.746781818,63,$206.07 ,2008
Mamma Mia!,Comedy,Universal,76,9.234453864,53,$609.47 ,2008
Mamma Mia!,Comedy,Universal,76,9.234453864,53,$609.47 ,2008
Made of Honor,Comdy,Sony,61,2.64906835,13,$105.96 ,2008
Love Happens,Drama,Universal,40,2.004444444,18,$36.08 ,2009
Love & Other Drugs,Comedy,Fox,55,1.817666667,48,$54.53,2010
Life as We Know It,Comedy,Independent,62,2.530526316,28,$96.16,2010
License to Wed,Comedy,Warner Bros.,55,1.9802064,8,$69.31,2007
Letters to Juliet,Comedy,Summit,62,2.639333333,40,$79.18,2010
Leap Year,Comedy,Universal,49,1.715263158,21,$32.59 ,2010
Knocked Up,Comedy,Universal,83,6.636401848,91,$219 ,2007
Killers,Action,Lionsgate,45,1.245333333,11,$93.40 ,2010
Just Wright,Comedy,Fox,58,1.797416667,45,$21.57 ,2010
Jane Eyre,Romance,Universal,77,0,85,$30.15 ,2011
It’s Complicated,Comedy,Universal,63,2.642352941,56,$224.60,2009
I Love You Phillip Morris,Comedy,Independent,57,1.34,71,$20.10,2010
High School Musical 3: SeniorYear,Comedy,Disney,76,22.91313646,65,$252.04 ,2008
He’s Just Not That Into You,Comedy,WarnerBros.,60,7.1536,42,$178.84 ,2009
Good Luck Chuck,Comedy,Lionsgate,61,2.36768512,3,$59.19 ,2007
Going the Distance,Comedy,Warner Bros.,56,1.3140625,53,$42.05,2010
Gnomeo and Juliet,Animation,Disney,52,5.387972222,56,$193.97,2011
Gnomeo and Juliet,Animation,Disney,52,5.387972222,56,$193.97,2011
Ghosts of Girlfriends Past,Comedy,Warner Bros.,47,2.0444,27,$102.22,2009
Four Christmases,Comedy,Warner Bros.,52,2.022925,26,$161.83,2008
Fireproof,Drama,Independent,51,66.934,40,$33.47 ,2008
Enchanted,Comedy,Disney,80,4.005737082,93,$340.49 ,2007
Dear John,Drama,Sony,66,4.5988,29,$114.97 ,2010
Beginners,Comedy,Independent,80,4.471875,84,$14.31 ,2011
Across the Universe,romance,Independent,84,0.652603178,54,$29.37,2007
A Serious Man,Drama,Universal,64,4.382857143,89,$30.68 ,2009
A Dangerous Method,Drama,Independent,89,0.44864475,79,$8.97,2011
27 Dresses,Comedy,Fox,71,5.3436218,40,$160.31 ,2008
(500) Days of Summer,comedy,Fox,81,8.096,87,$60.72 ,2009

————————————————————————————————

//program to retrieve information from a csv file

#include<iostream>

#include<stdio.h>

#include<string>

#include<fstream>

using namespace std;

struct MovieData

{

string FilmTitle;

string Genre;

string Studio;

int AudienceScore;

int Probabibility;

int RottenTomatoScore;

double TotalGross;

int Year;

};

class Movie

{

public:

//Declare the essential methods

char describe();

void sortRankReport();

void sortTitleReport();

};

//Class Menu displays all the methods used

//to display menu

class Menu

{

public:

//Declare the essential methods

char getmenu();

char getReport();

char getSearch();

void setReport(char ch);

void setSearch(char ch);

};

//Class FilmDatabase contains all the methods

//to search in the class

class FilmDatabase

{

public:

//Declare the essential methods

void searchTitle();

void searchKeyword();

void searchStudio();

struct MovieData fileOpen();

};

//This is a method to open the file and store the values in thevariables

struct MovieData FilmDatabase::fileOpen()

{

struct MovieData movie[80];

ifstream file;

//open the file and prompt if an error occurs

file.open(“movies.csv”);

//display error when file fails to open

if(file.fail())

{

cout << “Error occured when trying to open file” <<endl;

}

//read from the file

for(int i = 0; i < 80; i++)

{

if(file.is_open())

{

file >> movie[i].FilmTitle;

file >> movie[i].Genre;

file >> movie[i].Studio;

file >> movie[i].AudienceScore;

file >> movie[i].Probabibility;

file >> movie[i].RottenTomatoScore;

file >> movie[i].TotalGross;

file >> movie[i].Year;

return movie[i];

}

}

file.close();

}

char Menu::getmenu()

{

char choice;

cout << “nMain Menu:n”;

cout << “D – Describe the Program :n”;

cout << “R – Reports : n”;

cout << “S – Search the Database :n”;

cout << “X – Exit the Program : n”;

cout << “Enter Selection -> “;

cin >> choice;

return choice;

}

char Menu::getReport()

{

char choice;

cout << “nREPORTS MENU:n”;

cout << “T – Order by Film Title reportn”;

cout << “R – Order by Rank reportn”;

cout << “X – Return to main menun”;

cout << “Enter Selection -> “;

cin >> choice;

return choice;

}

void Menu::setReport(char ch)

{

//extentiate the Movie class

Movie film;

switch(ch)

{

case ‘T’:

film.sortTitleReport();

break;

case ‘R’:

film.sortRankReport();

break;

case ‘X’:

break;

default:

cout << “nEnter choice correctly : “;

}

}

void Movie::sortRankReport(){

struct MovieData movie[80];

FilmDatabase film;

for(int i = 0; i < 80; i++){

movie[i] = film.fileOpen();

}

//declare required variables

int temp, i, j;

//for loops used sorting

for(i = 0; i <= 10; i++){

for(j = 0; j <= 10; j++){

if(movie[j].AudienceScore > movie[j + 1].AudienceScore)

{

temp = movie[j].AudienceScore;

movie[j].AudienceScore = movie[j + 1].AudienceScore;

movie[j + 1].AudienceScore = temp;

}

}

}

cout << “nRanks after sorting:nn”;

cout << “RanktMovieTitletttStudiottTotal Gross”

“tTotalTheaterstOpening GrosstOpening Theaters”

“tOpening Date” << “n”;

//Display after sorting

for(int j = 0; j < 10; j++)

{

cout << movie[j].FilmTitle << “t”;

cout << movie[j].Genre << “ttt”;

cout << movie[j].Studio << “tt”;

cout << movie[j].AudienceScore << “tt”;

cout << movie[j].Probabibility << “tt”;

cout << movie[j].RottenTomatoScore << “t” <<“t”;

cout << movie[j].TotalGross << “tt”;

cout << movie[j].Year << “n”;

}

}

//Method to display menu for search

char Menu :: getSearch()

{

char choice;

cout << “nSearch MENUn”;

cout << “T – Search by Titlen”;

cout << “S – Search by Studion”;

cout << “X – Return to main menun”;

cout << “Enter Selection -> “;

cin >> choice;

return choice;

}

//Method for switch case to apply search operation

void Menu::setSearch(char ch)

{

FilmDatabase data;

switch (ch){

case ‘T’:

data.searchTitle();

break;

case ‘S’:

data.searchStudio();

break;

case ‘X’:

break;

default:

cout << “Enter choice correctly : “;

}

}

//Method to search according to title

void FilmDatabase::searchTitle()

{

struct MovieData movie[80];

FilmDatabase film;

for(int i = 0; i < 80; i++){

movie[i] = film.fileOpen();

}

string title;

cout << “nEnter the movie Title to be searched: “;

cin >> title;

for(int i = 0; i < 80; i++){

if(title == movie[i].FilmTitle){

cout << “nHi “<<title<<” present in the top”

“80 movie list. It is at the “<<i<<” rank.n”;

break;

}

}

}

//Method to search by studio names

void FilmDatabase::searchStudio(){

struct MovieData movie[80];

FilmDatabase film;

for (int i = 0; i < 100; i++)

{

movie[i] = film.fileOpen();

}

string st;

cout << “nEnter the Studio name to be searched: “;

cin >> st;

for (int i = 0; i < 100; i++)

{

if (st == movie[i].Studio)

{

cout << “nHi ” << st << ” present in the top100″

” movie list. It is at the ” << i << ” rankn”;

}

}

}

int main()

{

Movie film;

FilmDatabase data;

Menu opt;

struct MovieData movie[80];

char menu, choice;

//starts do-while loop

do{

//Accepts the meny to display the choices to the user

char ch = opt.getmenu();

//starts switch case

switch(ch){

case ‘S’:

do{

//method to display choice while searching

menu = opt.getSearch();

//Method to start switch case

opt.setSearch(menu);

//display messay to continue do-while loop

cout << “nDo you want to continue (Y/N) : “;

cin >> choice;

} while(choice != ‘N’);

break;

case ‘X’:

//exit(1);

break;

default:

cout << “Enter choice correctly : “;

}

//Display message to continue do-while loop

cout << “nDo you want to continue (Y/N) : “;

cin >> choice;

} while (choice != ‘N’);

return 0;

}

Expert Answer


Answer to Hi! I came across this c++ program on Chegg, and I wanted to practice with it the following concepts: class, objects, he…

OR