In: Computer Science
Joe’s Pizza Palace needs a C++ program to calculate the number of slices a pizza of any size can be divided into. The program should perform the following steps:
A. Ask the user for the diameter of the pizza in inches.
B. Divide the diameter by 2 to get the radius.
C. Calculate the number of slices that may be taken from a pizza of that size if each slice has an area of 14.125 square inches.
D. Display a message telling the number of slices.
E. Modify the program you wrote so that it reports the number of pizzas you need to buy for a party if each person attending is expected to eat an average of four slices.
F. The program should ask the user for the number of people who would be at the party and for the diameter of the pizzas to be ordered.
G. It should then calculate and display the number of pizzas to purchase.
Because it is impossible to buy a part of a pizza, the number of required pizzas should display as a whole number.
(Hint: using setprecision and fixed from iomanip header file) The number of square inches in the total pizza can calculate with this formula: Area=πr2 Where variable r is the radius of the pizza and π is the Greek letter PI. In your program, make PI a named constant with the value 3.14. Display the number of slices as a whole number (i.e., with no decimals).
#include <iostream>
#include<iomanip>
using namespace std;
int main()
{
double d,r,s,area;
double totalp=0.0;
int people;
cout<<"Enter the diameter of pizza in inches: ";
cin>>d;//read diameter
r=d/2;//get radius
area=3.14*r*r;//find area
s=area/14.125;//get the number of slices where each slice has
14.125 square inches
cout<<setprecision(0)<<fixed;
cout<<"Number of slices: "<<s<<endl;
cout<<"Enter number of people attending the party: ";//read
number of people
cin>>people;
people=people*4;//4 slices per person
totalp=people/s;//calculate number of pizzas
cout<<"Number of pizzas needed to be purchased:
"<<totalp;
return 0;
}
Screenshots:
The screenshots are attached below for reference.
Please follow them for output.
Please upvote my answer. Thank you.