Programming language is C++. Show code and an example of the output on Putty whe
ID: 3783754 • Letter: P
Question
Programming language is C++. Show code and an example of the output on Putty when done.
With one cut across the middle of a pizza you can cut off half, that is, 50% of the pizza. different place you can cut off less than 50%. The length of the cut is called the "chord" and the piece removed is called the "segment." Look up (or derive yourself) the formula for the area of a segment in terms of the chord length and the diameter, and write a C++ program to ask for the chord length in inches and print out the percentage of a 14" pizza remaining after the segment is cut off. Running your program should look like this: Pizza diameter is 14". Enter chord length in inches: 0 That cut leaves 100% of the pizza. Enter chord length in inches: 14 That cut leaves 50% of the pizza. Enter chord length in inches: 10.17 That cut leaves 90% of the pizza. Use while(cin >> chord) so the program will keep reading and calculating until end of file. Name your program hw1pr2.cpp. Reminder: If you did not derive the formula yourself, state in a comment where you got the formula.Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
// Title of CMD Window
system("title How many Slices are in your Pizza?");
// Declare variables
double diameter = 0.0, // Diameter of the pizza
slices = 0.0, // No. of slices in the pizza
area = 0.0, // Area of the whole pizza
// Area of one pizza slice
const double PI = 3.14159;
// Display prompt
cout << "What is the diameter of the pizza (inches):" << " ";
cin >> diameter;
// Calculate the area of the pizza
area = PI * diameter;
// Calculate number of slices for the size of pizza given
slices = area / oneSlice;
// Display results
cout << " " << "You have " << slices << " slice(s) in this pizza:" << " "
<< "************************************" << " "
<< " Diameter of pizza= " << diameter << " "
<< " Area of pizza= " << area << " "
<< "************************************" << " ";
system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.