Write a program to do the following: Ask the user to enter the number of films F
ID: 3864100 • Letter: W
Question
Write a program to do the following: Ask the user to enter the number of films For each film ask the user to enter the following information: The cost of the film The revenue of the film Type of the film 'D' for drama 'C' for comedy 'A' for action 'R' for romantic For each film calculate the profit Profit = revenue-cost Display the maximum profit for the drama films Display how many film didn't achieve profit Display the minimum profit for the comedy films Display the average cost of the action filmsExplanation / Answer
/* Movies.CPP */
#include<iostream>
using namespace std;
struct movie{
float cost;
float revenue;
char type;
float profit;
};
void display_maximum_profit_drama();
void display_didnot_achieve_profit();
void display_minimum_profit_comedy();
void display_average_cost_action_films();
int num;
movie m[50];
int main(){
int i=1;
cout<<"Enter number of films:";
cin>>num;
while(i<=num){
cout<<" Enter film "<<i<<" details";
cout<<" Enter The cost of the film:";
cin>>m[i].cost;
cout<<"Enter The revenue of the film:";
cin>>m[i].revenue;
cout<<"Enter the Type of the film:"<<endl;
cout<<"'D' for drama , 'C' for comedy , 'A' for action, 'R' for romantic:";
cin>>m[i].type;
m[i].profit = m[i].revenue - m[i].cost;
i++;
}
display_maximum_profit_drama();
display_didnot_achieve_profit();
display_minimum_profit_comedy();
display_average_cost_action_films();
return 0;
}
void display_maximum_profit_drama(){
float max_profit = 0;
for(int i=0;i<num;i++){
if(m[i].type == 'D' && m[i].profit > max_profit){
max_profit = m[i].profit;
}
}
cout<<" Maximum profit for the drama films:"<<max_profit<<endl;
}
void display_didnot_achieve_profit(){
int count = 0;
for(int i=0;i<num;i++){
if(m[i].profit == 0)
count++;
}
cout<<count<<" films did not achieve profit"<<endl;
}
void display_minimum_profit_comedy(){
float min_profit = 0;
for(int i=0;i<num;i++){
if(m[i].type == 'C' && m[i].profit > min_profit&&m[i].profit!=0){
min_profit = m[i].profit;
}
}
cout<<"Minimum profit for the comedy films:"<<min_profit<<endl;
}
void display_average_cost_action_films(){
float tot_profit =0, avg_profit;
int noa = 0;
for(int i=0;i<num;i++){
if(m[i].type == 'A'){
tot_profit += m[i].profit;
noa++;
}
}
avg_profit = tot_profit / noa;
cout<<"Average profit for the Action films:"<<avg_profit<<endl;
}
/* Sample Input and Output */
Enter number of films:8
Enter film 1 details
Enter The cost of the film:578000
Enter The revenue of the film:876000
Enter the Type of the film:
'D' for drama , 'C' for comedy , 'A' for action, 'R' for romantic:D
Enter film 2 details
Enter The cost of the film:765000
Enter The revenue of the film:765000
Enter the Type of the film:
'D' for drama , 'C' for comedy , 'A' for action, 'R' for romantic:A
Enter film 3 details
Enter The cost of the film:679000
Enter The revenue of the film:546000
Enter the Type of the film:
'D' for drama , 'C' for comedy , 'A' for action, 'R' for romantic:C
Enter film 4 details
Enter The cost of the film:890000
Enter The revenue of the film:890000
Enter the Type of the film:
'D' for drama , 'C' for comedy , 'A' for action, 'R' for romantic:R
Enter film 5 details
Enter The cost of the film:430000
Enter The revenue of the film:780000
Enter the Type of the film:
'D' for drama , 'C' for comedy , 'A' for action, 'R' for romantic:D
Enter film 6 details
Enter The cost of the film:543000
Enter The revenue of the film:587000
Enter the Type of the film:
'D' for drama , 'C' for comedy , 'A' for action, 'R' for romantic:C
Enter film 7 details
Enter The cost of the film:786500
Enter The revenue of the film:843900
Enter the Type of the film:
'D' for drama , 'C' for comedy , 'A' for action, 'R' for romantic:A
Enter film 8 details
Enter The cost of the film:657000
Enter The revenue of the film:785000
Enter the Type of the film:
'D' for drama , 'C' for comedy , 'A' for action, 'R' for romantic:R
Maximum profit for the drama films:350000
3 films did not achieve profit
Minimum profit for the comedy films:44000
Average profit for the Action films:28700
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.