카테고리 없음

Exercise 11.1: Structure

07514673 2021. 12. 20. 14:46

Exercise 11.1: Structure

Here is the problem specification:

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

  • Title
  • Director
  • Year
  • Released Running Time (in minutes)
  • production costs
  • first-year revenues

The program should create two MovieData variables, store values in their members, and pass each one, in turn, to a function that displays the the title, director, release year, running time, and first year's profit or loss about the movie in a clearly formatted manner.

 

Sample Run

Title       : War of the Worlds
Director    : Byron Haskin
Released    : 1953
Running Time: 88 minutes
Production cost: $15000000.00
First year revenue: $28000000.00
First year profit: $13000000.00


Title       : War of the Worlds
Director    : Stephen Spielberg
Released    : 2005
Running Time: 118 minutes
Production cost: $22000000.00
First year revenue: $14000000.00
First year loss: $-8000000.00

 

#include <iostream>
#include <iomanip>
using namespace std;
struct MovieData
{
    string Title;
    string Director;
    int Year;
    int ReleasedRunningTime;
    double productioncosts;
    double FYrevenues;
};
void PrintMovieData(MovieData Movie) {
    cout << fixed << setprecision(2) << left;
    cout << setw(25) << "Title:" << Movie.Title << endl;
    cout << setw(25) << "Director:" << Movie.Director << endl;
    cout << setw(25) << "Released:" << Movie.Year << endl;
    cout << setw(25) << "Running Time:" << Movie.ReleasedRunningTime << " minutes" 
<< endl;
    cout << setw(25) << "Production cost:" << "$" << Movie.productioncosts << endl;
    cout << setw(25) << "First year revenues:" << "$" << Movie.FYrevenues << endl;
    double FYprofit = Movie.FYrevenues - Movie.productioncosts;
    if (FYprofit > 0) {
        cout << setw(25) << "First year profit:" << "$" << FYprofit << endl << 
endl;
    }
    else {
        cout << setw(25) << "First year loss:" << "$" << FYprofit << endl << endl;
    }
    
}
int main()
{
    MovieData Movie1 = { "War of the Worlds", "Byron 
Haskin",1953,88 ,15000000.00,28000000.00 };
    MovieData Movie2 = { "War of the Worlds", "Stephen 
Spielberg",2005,118 ,22000000.00,14000000.00 };
    PrintMovieData(Movie1);
    PrintMovieData(Movie2);
    return 0;
}