Question

In: Computer Science

C++...This program is broken down into phases for your convenience only. Please turn in only the...

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. 

Solutions

Expert Solution

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


Related Solutions

This program is broken down into phases for your convenience only. Please turn in only the...
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...
The manipulation of the LIBOR can be broken down into three phases. What were these and...
The manipulation of the LIBOR can be broken down into three phases. What were these and how did they differ in terms of motivation and moral justification?
in c++ please In this program you are going to have several files to turn in...
in c++ please In this program you are going to have several files to turn in (NOT JUST ONE!!) hangman.h – this is your header file – I will give you a partially complete header file to start with. hangman.cpp – this is your source file that contains your main function functions.cpp – this is your source file that contains all your other functions wordBank.txt – this is the file with words for the game to use.  You should put 10...
IN C LANGUAGE ONLY PLEASE! First Program: create branchloop.c file Content of the program Enter your...
IN C LANGUAGE ONLY PLEASE! First Program: create branchloop.c file Content of the program Enter your name while running your program as you did with hello2.c (using argc and argv) name has to be 2 words max (e.g. Jose Lopez, Maria Rodrigues) . Make sure to check properly. Print your name 10 times using a loop. 10 is a fixed number. Count how many characters are in your first name and last name. If the number of characters of your...
You are managing a large construction project that’s been broken down into sub-projects (or phases). Each...
You are managing a large construction project that’s been broken down into sub-projects (or phases). Each of these sub-projects is scheduled to take between three and six months to complete. At the end of each subproject, you plan to go through the closing processes and document lessons learned. Which of the following BEST describes what you must do at the beginning of each sub-project or phase? a. Make sure you don’t involve the team, to avoid introducing too much project...
Write down the C++ Program
 Write a function, which accept three integer values as arguments find the largest of three and then return the largest value to main program. Write a main program which will call the function by passing three integer values and print the value returned by the function.?
I have this matlab program, and need to turn it into a C++ program. Can anyone...
I have this matlab program, and need to turn it into a C++ program. Can anyone help me with this? % Prompt the user for the values x and y x = input ('Enter the x coefficient: '); y = input ('Enter the y coefficient: '); % Calculate the function f(x,y) based upon % the signs of x and y. if x >= 0    if y >= 0        fun = x + y;    else        fun = x + y^2;    end...
TEXT ONLY PLEASE (PLEASE NO PDF OR WRITING) C++ CODE Instructions Write a program that implements...
TEXT ONLY PLEASE (PLEASE NO PDF OR WRITING) C++ CODE Instructions Write a program that implements the algorithm given in Example 1 - 3 (Chapter 1), which determines the monthly wages of a salesperson. The instructions for Example 1 - 3have been posted below for your convenience. Example 1 - 3 Every salesperson has a base salary. The salesperson also receives a bonus at the end of each month, based on the following criteria: If the salesperson has been with...
In C++ Please, using only the libraries given in this homework prompt, Write a program that...
In C++ Please, using only the libraries given in this homework prompt, Write a program that (1) prompts for two integers, (2) prints out their sum, (3) prints out the first divided by the second, and (4) prints out the natural log of the first number raised to the power of the second number. #include <iostream> #include <iomanip> using namespace std; int main() { <your answer goes here> return 0; }
Please give a brief yet thorough explanation of the physiology of the lungs broken down short...
Please give a brief yet thorough explanation of the physiology of the lungs broken down short enough and in bullets for a powerpoint.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT