Can you please write the code in C++ 1. With one cut across the middle of a pizz
ID: 3786216 • Letter: C
Question
Can you please write the code in C++
1. With one cut across the middle of a pizza you can cut off half, that is, 50% of the pizza. With one cut at a 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. 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()
{
double diameter = 14, length;
cout << "Pizza diameter is " << diameter << " inches.";
cout << "Enter length length in inches: ";
while(cin >> length)
{
if(length==0){
cout<<"That cut leaves 100% of the pizza"<<endl;
}
int area = length*diameter/2;
float percentage=(area*length)/100;
cout << " That cuts out " << percentage << " percent of the pizza. "<<endl;
cout << "Enter length length in inches: ";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.