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

Write a modular program that uses a structure named MovieData to store the follo

ID: 3555460 • Letter: W

Question

Write a modular program that uses a structure named MovieData to store the following information about a movie:

The program should prompt the user for the name of the file containing the movie data. The program should read the movie data into a dynamically allocated array which will hold only the specified number of movies; the first line of the file contains a single integer which indicates the number of movie entries which exist in the file. The remaining lines of the file contain the name of the movie, the name of the director, the year of release and the running time with each separated by a semi-colon (;). The amount of the movie's profit or loss should be determined after reading the movie's cost of production and the amount of revenue it generated.

****HERE IS THE MOVIE DATA I COULDNT ATTACH IT SO I JUST COPIED IT*****

PLEASE INCLUDE COMMENTS SO I WILL KNOW WHATS GOING ON

Explanation / Answer

#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>
#include<sstream>
#include<stdlib.h>
using namespace std;
struct movie
{
string Movie_Title;
string Director;
int Year_Released;
int Running_Time;
float Cost_of_Production;
float Revenue_Generated;
float Profit_or_Loss;
};
int main()
{
movie *array_of_movies;
string file_name;
//The program should prompt the user for the name of the file containing the movie data.
cout <<"Enter file name containing movie data :";
cin >> file_name;
ifstream infile;
infile.open(file_name.c_str());
if(!infile)
{
cout <<"Unable to open file so exiting from progrmam..";
return 0;
}
int no_of_movies;
//the first line of the file contains a single integer which indicates the number of movie entries which exist in the file.
string movie_no;
getline(infile,movie_no);
no_of_movies =atoi(movie_no.c_str());
//The program should read the movie data into a dynamically allocated array which will hold only the specified number of movies;
array_of_movies = new movie[no_of_movies];
// The remaining lines of the file contain the name of the movie, the name of the director,
// the year of release and the running time with each separated by a semi-colon (;).
// The amount of the movie's profit or loss should be determined after reading the movie's cost of production and the amount of revenue it generated.
int count = 0;
    int local = 0;
while(!infile.eof())
{
string movie_d;
getline(infile, movie_d);
    stringstream ss(movie_d);
    string token;
    string array[6];

   while(std::getline(ss, token, ';'))
   {
// cout << token << endl;
   array[local++] = token;
   }
local = 0;
    if(count == no_of_movies) break;
   array_of_movies[count].Movie_Title = array[0];
   array_of_movies[count].Director = array[1];
   array_of_movies[count].Year_Released = atoi(array[2].c_str());
   array_of_movies[count].Running_Time = atoi(array[3].c_str());
   array_of_movies[count].Cost_of_Production =(atof(array[4].c_str()));
   array_of_movies[count].Revenue_Generated = atof(array[5].c_str());
   count++;
}

for(int i=0; i<no_of_movies; i++)
{
cout <<"Movie name is :"<<array_of_movies[i].Movie_Title << endl;
   cout <<"Movie director is :"<<array_of_movies[i].Director<< endl;

cout <<"Movie Year is :"<<array_of_movies[i].Year_Released << endl;
cout <<"Movie Running time is :"<<   array_of_movies[i].Running_Time << endl;
cout << fixed << setprecision(3);
cout <<"Movie Cost of production is :"<<   array_of_movies[i].Cost_of_Production << endl;
   cout <<"Revenue is :"<<array_of_movies[i].Revenue_Generated<< endl;
if(array_of_movies[i].Cost_of_Production < array_of_movies[i].Revenue_Generated)
   cout <<"Profit is :"<<(array_of_movies[i].Revenue_Generated-array_of_movies[i].Cost_of_Production)<< endl;
else if(array_of_movies[i].Cost_of_Production > array_of_movies[i].Revenue_Generated)
   cout <<"Loss is :"<<(array_of_movies[i].Cost_of_Production-array_of_movies[i].Revenue_Generated)<< endl;
   else
cout <<"NO loss of profit." << endl;
}

//system("pause");
return 0;
}




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