// Torrez, Elaine CS1A
// ----------------------------------------------
// MOVIE PROFIT
// ----------------------------------------------
//
// This program stores information about a movie using
// a structure called MovieData. It includes the movie's
// production cost and first-year revenue, then displays
// the movie information and calculates the first-year
// profit or loss.
//
// ----------------------------------------------
// INPUT
// (no user input for this program)
//
// PROCESSING
// Create two MovieData variables
// Compute first-year profit or loss
// Pass each variable to a function to display data
//
// OUTPUT
// Movie Title
// Movie Director
// Year Released
// Running Time (minutes)
// First-year Profit or Loss
//
// ----------------------------------------------
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// Structure to hold movie information
struct MovieData {
string title; // Title of the movie
string director; // Director of the movie
int year; // Year released
int minutes; // Movie length in minutes
double productionCost; // Cost to produce the movie
double firstYearRev; // First-year revenue
};
// -------------------------------------------------
// Function: displayMovie
// This function displays all the information for one
// movie, including the first-year profit or loss.
// -------------------------------------------------
void displayMovie(const MovieData &m)
{
double profitLoss = m.firstYearRev - m.productionCost;
cout << "Title : " << m.title << endl;
cout << "Director : " << m.director << endl;
cout << "Year Released: " << m.year << endl;
cout << "Runtime : " << m.minutes << " minutes" << endl;
if (profitLoss >= 0)
{
cout << "First-Year Profit : $" << profitLoss << endl;
}
else
{
cout << "First-Year Loss : $" << -profitLoss << endl;
}
cout << "----------------------------------------\n";
}
int main()
{
//--------------------------------------------------
// DECLARATIONS
//--------------------------------------------------
MovieData movie1; // First Movie
MovieData movie2; // Second Movie
//--------------------------------------------------
// INITIALIZE MOVIE 1 (profit example)
//--------------------------------------------------
movie1.title = "Inception";
movie1.director = "Christopher Nolan";
movie1.year = 2010;
movie1.minutes = 148;
movie1.productionCost = 160000000.00; // $160M
movie1.firstYearRev = 825000000.00; // $825M
//--------------------------------------------------
// INITIALIZE MOVIE 2 (loss example)
//--------------------------------------------------
movie2.title = "Random Indie Film";
movie2.director = "New Director";
movie2.year = 2024;
movie2.minutes = 95;
movie2.productionCost = 5000000.00; // $5M
movie2.firstYearRev = 2000000.00; // $2M
//--------------------------------------------------
// FORMATTING FOR MONEY OUTPUT
//--------------------------------------------------
cout << fixed << setprecision(2);
//--------------------------------------------------
// OUTPUT
//--------------------------------------------------
displayMovie(movie1);
displayMovie(movie2);
return 0;
}