In: Computer Science
C++...This program is broken down into phases for your convenience only. Please turn in only the final phase. Before turning in your program, please make sure that it does something reasonable if the user enters a negative number the first time.
Phase I: Write a program for a theater that will keep track of how many people in each of 5 age categories attended a particular movie. Use the 5 age categories listed below in the sample screen output. The user will enter a number of ages, entering a negative number when there are no more ages to enter. Your program will then report on how many people in each age group attended. Sample screen output:
Enter age of attendee (-1 to quit): 34 Enter age of attendee (-1 to quit): 16 Enter age of attendee (-1 to quit): 68 Enter age of attendee (-1 to quit): 53 Enter age of attendee (-1 to quit): 39 Enter age of attendee (-1 to quit): 23 Enter age of attendee (-1 to quit): 21 Enter age of attendee (-1 to quit): -1 age 0 to 18: 1 age 19 to 30: 2 age 31 to 40: 2 age 41 to 60: 1 over 60: 1 |
Phase II: Modify your program so that, in addition
to the report that the program currently produces, it also gives
the average age of the people in attendance, the age of the oldest
person in attendance, and the age of the youngest person in
attendance. Sample screen output:
Enter age of attendee (-1 to quit): 34 Enter age of attendee (-1 to quit): 16 Enter age of attendee (-1 to quit): 68 Enter age of attendee (-1 to quit): 53 Enter age of attendee (-1 to quit): 39 Enter age of attendee (-1 to quit): 23 Enter age of attendee (-1 to quit): 21 Enter age of attendee (-1 to quit): -1 age 0 to 18: 1 age 19 to 30: 2 age 31 to 40: 2 age 41 to 60: 1 over 60: 1 The average age was 36. The youngest person in attendance was 16. The oldest person in attendance was 68. |
Phase III: Modify your program so that it also asks each attendee for a theater concession stand purchase. The attendee must make a selection based on the following choices …
1 - Soft Drink (such as Coca Cola, ICCEE, Mineral Water etc...)
2 - Popcorn
3 - Nachos
4 - Soft drink & Popcorn
5 - Soft drink & Nachos
6 - Organic and Gluten-free snacks
7 – None
The program output should now also provide a theater concession stand sales summary with a count of each category purchased.
Note: Include a validation routine to ensure that a correct choice is input for each attendee.
Check the sample screen output below for the final formatted display of theater statistics.
========================== THEATER STATS PROGRAM ========================== Movie theater snacks available for purchase ========================================== 1 - Soft Drink (such as Coca Cola, ICCEE, Mineral Water etc...) 2 - Popcorn 3 - Nachos 4 - Soft drink & Popcorn 5 - Soft drink & Nachos 6 - Organic and Gluten-free snacks 7 - None ========================================== Enter age of attendee (-1 to quit): 34 Movie theater snack purchased. (Select items 1 - 7):4 -------------------------- Enter age of attendee (-1 to quit): 16 Movie theater snack purchased. (Select items 1 - 7):5 -------------------------- Enter age of attendee (-1 to quit): 68 Movie theater snack purchased. (Select items 1 - 7):12 Invalid selection, please choose from 1 - 7 Movie theater snack purchased. (Select items 1 - 7):6 -------------------------- Enter age of attendee (-1 to quit): 53 Movie theater snack purchased. (Select items 1 - 7):6 -------------------------- Enter age of attendee (-1 to quit): 39 Movie theater snack purchased. (Select items 1 - 7):1 -------------------------- Enter age of attendee (-1 to quit): 23 Movie theater snack purchased. (Select items 1 - 7):2 -------------------------- Enter age of attendee (-1 to quit): 21 Movie theater snack purchased. (Select items 1 - 7):3 -------------------------- Enter age of attendee (-1 to quit): 21 Movie theater snack purchased. (Select items 1 - 7):4 -------------------------- Enter age of attendee (-1 to quit): -1 ================================== THEATER STATS PROGRAM RESULTS ================================== age 0 to 18: 1 age 19 to 30: 3 age 31 to 40: 2 age 41 to 60: 1 over 60: 1 The average age was 34 The youngest person in attendance was 16 The oldest person in attendance was 68 Theater Concession Stand sales ================================== Soft Drink (such as Coca Cola, ICCEE, Mineral Water etc.): 1 Popcorn: 1 Nachos: 1 Soft drink & Popcorn: 2 Soft drink & Nachos: 1 Organic and Gluten-free snacks: 2 Process returned 0 (0x0) execution time : 169.589 s Press any key to continue. |
C++ CODE
#include <iostream>
using namespace std;
int main()
{ int age =
0,snack,large=0,small=0,a=0,b=0,c=0,d=0,e=0,n=0,a1=0,b1=0,c1=0,d1=0,e1=0,f1=0,ar[25];
float avg,sum,p=0; //display
cout<<"\n ==========================";
cout<<"\n THEATER STATS PROGRAM ";
cout<<"\n ==========================";
cout<<"\nMovie theater snacks available for purchase ";
cout<<"\n==========================================";
cout<<"\n1 - Soft Drink (such as Coca Cola, ICCEE, Mineral
Water etc...) ";
cout<<"\n2 - Popcorn ";
cout<<"\n3 - Nachos ";
cout<<"\n4 - Soft drink & Popcorn ";
cout<<"\n5 - Soft drink & Nachos ";
cout<<"\n6 - Organic and Gluten-free snacks ";
cout<<"\n7 - None ";
cout<<"\n========================================== ";
while (1>0)
{
cout <<"\nEnter age of attendee (-1 to quit):"; //input the
ge of attendee
cin>>age;
if(age<0) //checking the age is valid
{ break;
}
while(1>0)
{
cout<<"Movie theater snack purchased. (Select items 1 - 7):
";
cin>>snack; //input snack purchased
if(snack>=1 && snack<=7) //checking the input is
valid
break;
else{
cout<<"\nInvalid selection, please choose from 1 - 7\n
";
continue;
}}
cout<<"--------------------------";
if (age>=0 && age<=18) { //finding the age
categories
a++;
} else if (age>=19 && age<=30) {
b++;
} else if (age>=31 && age<=40) {
c++;
} else if (age>=41 && age<=60) {
d++;
} else if (age>60) {
e++;
}else ;
if (snack==1) { //finding the count of each category
purchased.
a1++;
} else if (snack==2) {
b1++;
} else if (snack==3) {
c1++;
} else if (snack==4) {
d1++;
} else if (snack==5) {
e1++;
}else if (snack==6) {
f1++;
} else ;
p=p+1;
sum=sum+age; // finding the sum of age
ar[n]=age;
n++;
}
large=small=ar[0];
for(int i=1;i<n;++i) //finding the youngest and
oldest person
{
if(ar[i]>large)
large=ar[i];
if(ar[i]<small)
small=ar[i];
}
avg=sum/p; //finding the average of age
cout << "\nage 0 to 18: "<<a; //display count of each
category
cout << "\nage 19 to 30: "<<b;
cout << "\nage 31 to 40: "<<c;
cout<<"\nage 41 to 60: "<<d;
cout<<"\nover 60: "<<e;
cout<<"\nThe average age was : "<<avg; //display
average age
cout<<"\nThe youngest person in attendance was :
"<<small; //display youngest person
cout<<"\nThe oldest person in attendance was :"<<large;
//display oldest person
cout<<"\n\nTheater Concession Stand sales ";
cout<<"\n================================== "; //display
count of each category purchased.
cout<<"\nSoft Drink (such as Coca Cola, ICCEE, Mineral Water
etc.):"<<a1 ;
cout<<"\nPopcorn: "<< b1;
cout<<"\nNachos: "<<c1 ;
cout<<"\nSoft drink & Popcorn: "<<d1 ;
cout<<"\nSoft drink & Nachos: "<< e1;
cout<<"\nOrganic and Gluten-free snacks: "<<f1 ;
return 0;
}
I hope the answer is clear and satisfactory . If you have any doubts feel free to ask in the comment section. Please give a thumbs up.
OUTPUT