Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that will do the following: 1. It must be adequately commented.

ID: 3712096 • Letter: W

Question

Write a program that will do the following: 1. It must be adequately commented. 2. It must have variables that are appropriately named. 3. It must have a function to adequately prompt the user to perform the following action by printing the following menu. a. Add a new movie b. Print the director, movie length, theater release date, dvd release date, production cost, and first year revenue for a single title (search by title) c. Print the entire movie information listing d. Quit 4. It must have a function to a. Read a small library collection file stored in myMovies.dat b. Store the library collection data in an array called movieLibrary c. Add a movie (it must be added to array and appended to the data file d. Print (to common input) the director, movie length, theater release date, dvd release date, production cost, and first year revenue for a single title specified by the user. 5. It must make use of at least one other additional functions not specified above to perform necessary steps within the program. You could do search by another category or make use of “helper” functions to do the other tasks. Hints: 1. Each movie is stored as a struct movieType which includes the following information: title: string director: string length: int theaterReleaseDate: dateType dvdReleaseDate: dateType productionCost: double firstYearRevenue: double 2. The struct called dateType given in the above struct bookType is represented as follows: month: int day: int year: int 3. Review the information provided in the data file myMovies.dat to understand how the data is arranged so you can program the function for reading in the data correctly. 4. The movieLibrary is an array of movieType struct.

Explanation / Answer

Solution:

code:

#include<iostream>

#include<fstream>

using namespace std;

typedef struct{

int month;

int day;

int year;

}dateType;

typedef struct{

string title;

string director;

int length;

dateType *theatreReleaseDate;

dateType *dvdReleaseDate;

double productionCost;

double firstYearRevenue;

}movieType;

//global array declarations

movieType* movieLibrary[100];

int index=0;

ofstream output;

ifstream input;

//declarations of functions

void userMenu();

void addAMovie();

void printMovie(movieType *mv);

void printAllListing();

void storeMovie(movieType *mv);

void readLibrary();

void initialiseFileStreams();

void printSpecificMovie(string title);

int main()

{

initialiseFileStreams();;//initialise the ifstream and ofsteam

readLibrary();//read the movies from the file

userMenu(); //user menu print

cin.get();//hold the console screen

return 0;

}

//additional method to initialise the streams

void initialiseFileStreams()

{

input.open("myMovies.dat");//initialise the input file stream

output.open("myMovies.dat", std::ios_base::app);//initialise the output file stream

}

//read the movies from the file

void readLibrary()

{

//variables to hold the data

string title, director;

int length;

int trd_day, trd_month, trd_year, drd_day, drd_year, drd_month;

double prodCost, revenue;

//while the file has data

while(!input.eof())

{

//read the data

input>>title>>director>>length

>>trd_day>>trd_month>>trd_year

>>drd_day>>drd_year>>drd_month

>>prodCost>>revenue;

//create a new movieType object

movieType *mv=new movieType();

mv->director=director;

mv->length=length;

mv->productionCost=prodCost;

mv->title=title;

mv->firstYearRevenue=revenue;

mv->dvdReleaseDate=new dateType();

mv->dvdReleaseDate->day=drd_day;

mv->dvdReleaseDate->month=drd_month;

mv->dvdReleaseDate->year=drd_year;

mv->theatreReleaseDate=new dateType();

mv->theatreReleaseDate->day=trd_day;

mv->theatreReleaseDate->month=trd_month;

mv->theatreReleaseDate->year=trd_year;

//add to library

storeMovie(mv);

}

}

//store the movie object into the library array

void storeMovie(movieType *mv)

{

movieLibrary[index++]=mv; //assign the index position with mv

}

//print the library

void printAllListing()

{

//for each record in library

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

{

//print the record

printMovie(movieLibrary[i]);

}

}

//print a single movie object

void printMovie(movieType *mv)

{

cout<<endl<<endl;

cout<<"Title: "<<mv->title<<endl;

cout<<"Director: "<<mv->director<<endl;

cout<<"Length: "<<mv->length<<endl;

cout<<"Theatre release date: "<<mv->theatreReleaseDate->day<<" / "<<mv->theatreReleaseDate->month<<" / "<<mv->theatreReleaseDate->year<<endl;

cout<<"Dvd release date: "<<mv->dvdReleaseDate->day<<" / "<<mv->dvdReleaseDate->month<<" / "<<mv->dvdReleaseDate->year<<endl;

cout<<"Production cost: "<<mv->productionCost<<endl;

cout<<"First year revenue: "<<mv->firstYearRevenue<<endl<<endl;

}

//print movie having a specific title

void printSpecificMovie(string title)

{

bool flag=false;

//search in library

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

{

//if found the title

if(movieLibrary[i]->title == title)

{

flag=true;

//print the movie

printMovie(movieLibrary[i]);

}

}

if(!flag)//no movie with title found

cout<<"No such movie exists!"<<endl;

}

//function to add a movie

void addAMovie()

{

  

string title, director;

int length;

int trd_day, trd_month, trd_year, drd_day, drd_year, drd_month;

double prodCost, revenue;

cout<<endl<<"Title: ";

cin>>title;

cout<<" Director: ";

cin>>director;

cout<<" Length: ";

cin>>length;

cout<<" theatreReleaseDate (day/month/year): ";

cin>>trd_day>>trd_month>>trd_year;

cout<<" dvdReleaseDate (day/month/year): ";

cin>>drd_day>>drd_month>>drd_year;

cout<<" productionCost: ";

cin>>prodCost;

cout<<" firstYearRevenue: ";

cin>>revenue;

  

//create a new movieType object

movieType *mv=new movieType();

mv->director=director;

mv->length=length;

mv->productionCost=prodCost;

mv->title=title;

mv->firstYearRevenue=revenue;

mv->dvdReleaseDate=new dateType();

mv->dvdReleaseDate->day=drd_day;

mv->dvdReleaseDate->month=drd_month;

mv->dvdReleaseDate->year=drd_year;

mv->theatreReleaseDate=new dateType();

mv->theatreReleaseDate->day=trd_day;

mv->theatreReleaseDate->month=trd_month;

mv->theatreReleaseDate->year=trd_year;

//add to library

storeMovie(mv);

//append to file

output<<endl<<title<<" "<<director<<" "<<length<<" "<<trd_day<<" "<<trd_month<<" "<<trd_year<<" "

<<drd_day<<" "<<drd_month<<" "<<drd_year<<" "<<prodCost<<" "<<revenue;

}

void userMenu()

{

//user menu

char choice=' ';

string title;

do{

switch(choice)

{

case 'a': addAMovie();break;

case 'b': cout<<"Enter the title"<<endl;

cin>>title;

printSpecificMovie(title);break;

case 'c': printAllListing();break;   

}

cout<<" a. Add a new movie."<<endl;

cout<<"b. Print the movie information for a single title (search by title)."<<endl;

cout<<"c. Print the entire movie listing."<<endl;

cout<<"d. Quit"<<endl;

cin>>choice;

}while(choice!='d');

}

I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote