Question

In: Computer Science

C++ Prompt the user for the number of guests attending the event. Determine and report the...

C++

  • Prompt the user for the number of guests attending the event.
  • Determine and report the number of large, medium, and small pizzas you need to order.
  • For every 7 guests, order one large pizza.
  • For every 3 guests left over, order one medium pizza.
  • For every 1 guest left over, order one small pizza.

Part 2 - Serving Size

  • Compute and report the total area of pizza (in square inches) you need to purchase. Do not round these values.
  • Compute and report the total area of pizza (in square inches) each guest can eat. Do not round these values.

Part 3 - Supplementing the Budget (

  • Prompt the user for the percent of the total price to be paid as a tip. The tip percentage will be input as a whole integer from 0 to 100.
  • Compute and report the total cost (including tip) of all the pizzas, rounding to the nearest dollar. Note: Changing the value type into an int alone will not round to the nearest dollar. See the end of the "Notes" section below.

Part 4 - The "Magic" of Avoiding Magic Numbers

Sometime it may feel like a nuisance to make sure to properly use constants for magic numbers, so here we give you the opportunity to see how useful it can be. By changing just some of the constants, your program can simulate any pizza sizes and prices, without having to touch any other part of your code. Those constants are how many people each pizza feeds, the dimensions of each pizza, and the cost of each pizza. Make sure that you have written your code so that by changing only those nine values, and re-compiling, you can simulate any arbitrary pizza values.

Since you will be changing constants and recompiling for Part 4, you will be submitting a different compiled program than used in Parts 1, 2, and 3. Thus, do not submit the updated program here. Instead, copy your program from here into the following zyBook section (Main Lab 2B), change 9 of your constants, and submit the program from there. The grading TA will combine the points from the auto-grade of both 2A (possible 85 points) and 2B (possible 15 points) to get your full auto-grade points. The new values you will use are given in section Main Lab 2B.

Sample Input

303

15

 

Sample Output

In this case the output would look like:

Please enter the number of guests: 
43 large pizzas, 0 medium pizzas, and 2 small pizzas will be needed. 
A total of 13735 square inches of pizza will be purchased (45.3302 per guest).
 Please enter the tip as a percentage (i.e. 10 means 10%): 
The total cost of the event will be: $743

Solutions

Expert Solution

FOR Part-1 Part-2 And Part-3:

EXPLANATION: Modular division is used to calculate the remaining guests

Division is used to get the number of the pizzas that can be ordered based on its feeding capacity

Source Code :

#include <iostream>
#include<cmath>

//for round function
using namespace std;
void calculatePizza(int noOfGuests);
void calculatePizza(int noOfGuests){
   //Declare the costs of each sized pizza
   double largeCost=30,mediumCost=20,smallCost=10,guests=noOfGuests;
   //number of large count pizzas
   int largeCount=noOfGuests/7;
   noOfGuests%=7;
   //number of medium count pizzas
   int mediumCount=noOfGuests/3;
   noOfGuests%=3;
   //number of smallcount pizas
   int smallCount=noOfGuests;
   //Find the cost of pizzas
   double cost=largeCount*largeCost+mediumCount*mediumCost+smallCost*smallCount;
   //Assuming the size of large size pizza is 30 , medium size pizza is 20 small size pizza is 10 sqinches
   double size=largeCount*30+mediumCount*20+smallCount*10;
  
   cout<<largeCount<<" Large Pizzas is, "<<mediumCount<<" medium Pizzas, "<<smallCount<<" small pizzas will be needed";
   cout<<"A total of "<<size<< " square inches of pizza will be purchased ("<<size/guests<<")";
   int tipPercent;
   cout<<"Please enter the tip as a percentage : ";
   cin>>tipPercent;
   double tip= round(cost*(tipPercent/100));
   cout<<"The total cost of the event will be: $"<<cost+tip;
}
  
int main()
{
cout<<"Please enter the number of guests: ";
int noOfGuests;
cin>>noOfGuests;
calculatePizza(noOfGuests);
}

Pizza Source Code Image

OUTPUT:

// Output is based on the price and size of which i have taken

PART_4:

Explanation: In the previous part we have taken all the things in a static  way while calculating  in this we declaring the variables for every size, feeding count, cost of pizza by changing the data for these values can lead to being desired output for the defined pizza options

SOURCE CODE:

#include <iostream>
#include<cmath>
using namespace std;
void calculatePizza(int noOfGuests);
void calculatePizza(int noOfGuests){
   //Declare the costs of each sized pizza
   double largeCost=30,mediumCost=20,smallCost=10,guests=noOfGuests,sizeLarge=30,sizeMedium=20,sizeSmall=10;
   int feedLarge=5,feedMedium=3,feedSmall=1;
   //number of large count pizzas
   int largeCount=noOfGuests/feedLarge;
   noOfGuests%=feedLarge;
   //number of medium count pizzas
   int mediumCount=noOfGuests/feedMedium;
   noOfGuests%=feedMedium;
   //number of smallcount pizas
   int smallCount=noOfGuests;
   //Find the cost of pizzas
   double cost=largeCount*largeCost+mediumCount*mediumCost+smallCost*smallCount;
   //Assuming the size of large size pizza is 30 , medium size pizza is 20 small size pizza is 10 sqinches
   double size=largeCount*sizeLarge+mediumCount*sizeMedium+smallCount*sizeSmall;
  
   cout<<largeCount<<" Large Pizzas is, "<<mediumCount<<" medium Pizzas, "<<smallCount<<" small pizzas will be needed";
   cout<<"A total of "<<size<< " square inches of pizza will be purchased ("<<size/guests<<")";
   int tipPercent;
   cout<<"Please enter the tip as a percentage : ";
   cin>>tipPercent;
   double tip= round(cost*(tipPercent/100));
   cout<<"The total cost of the event will be: $"<<cost+tip;
}
  
int main()
{
cout<<"Please enter the number of guests: ";
int noOfGuests;
cin>>noOfGuests;
calculatePizza(noOfGuests);
}

SOURCE CODE IMAGE:

OUTPUT:


Related Solutions

In C++ Prompt user to enter two integers •Determine whether the first number is divisible by...
In C++ Prompt user to enter two integers •Determine whether the first number is divisible by the second. If the second number is zero, the program should not do division •Output the remainder of the two numbers •Compare the two integers, display the integers in non-decreasing order.
Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream>, switch and if-else statements only and do not use string storing for the conversion in words. Thank you.** **Our class is still discussing on the basics of programming. Please focus only on the basics. Thank you.** Example outputs: Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four...
Create a C++ program that will prompt the user to input an positive integer number and...
Create a C++ program that will prompt the user to input an positive integer number and output the corresponding number to words. Check all possible invalid input data. (Please use only switch or if-else statements. Thank you.)
Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream> and switch and if-else statements only. Thank you. Ex. Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four Enter a number: 100000 One Hundred Thousand Enter a number: -2 Number should be from 0-1000000 only
1. Write a program in C++ to find the factorial of a number. Prompt the user...
1. Write a program in C++ to find the factorial of a number. Prompt the user for a number and compute the factorial by using the following expression. Use for loops to write your solution code. Factorial of n = n! = 1×2×3×...×n; where n is the user input. Sample Output: Find the factorial of a number: ------------------------------------ Input a number to find the factorial: 5 The factorial of the given number is: 120 2. Code problem 1 using While...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                       ...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names             Quit If the user selects Guess-number, your program needs to call a user-defined function called int guess-number ( ). Use random number generator to generate a number between 1 – 100. Prompt the user to guess the generated number and print the following messages. Print the guessed number in main (): Guess a number: 76 96: Too large 10 Too small 70 Close...
Program IN C Prompt the user to enter month number and year. Retain an appropriate response...
Program IN C Prompt the user to enter month number and year. Retain an appropriate response for invalid month numbers, but don’t worry about validity of year. 2.Determine the number of days in the month entered (ignore leap years). 3.Use the answer to step 2 in one FOR-LOOP to ask the user to enter a FAHRENHEIT temperature (integer or floating) for each day of the month utilizing a prompt that includes the DATE. a. Prompt the user to enter the...
Prompt the user for their name, get and store the user input. Prompt the user for...
Prompt the user for their name, get and store the user input. Prompt the user for their age, get and store the user input. We will assume that the user will enter a positive integer and will do no error checking for valid input. Determine and store a movie ticket price based on the user's age. If their age is 12 or under, the ticket price is $5. If their age is between 13 and 64, inclusive, the ticket price...
IN C This assignment is to write a program that will prompt the user to enter...
IN C This assignment is to write a program that will prompt the user to enter a character, e.g., a percent sign (%), and then the number of percent signs (%) they want on a line. Your program should first read a character from the keyboard, excluding whitespaces; and then print a message indicating that the number must be in the range 1 to 79 (including both ends) if the user enters a number outside of that range. Your program...
In Python, your program will read in a number (no need to prompt the user), and...
In Python, your program will read in a number (no need to prompt the user), and then reads in that number of lines from the terminal. Then the program should print an array of strings formatted in a nice regular box. So if the user inputs this: 5 Grim visaged war has smooth’d his wrinkled front And now, instead of mounting barded steeds To fright the souls of fearful adversaries He capers nimbly in a lady’s chamber To the lascivious...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT