Programming Challenge Chapter 3 – Q #19 How Many Pizzas? – Tony Gaddis – Starting Out With C++

Programming Challenge Chapter 3 – Q #19 How Many Pizzas? – Tony Gaddis – Starting Out With C++



Problem: -

Modify the program you wrote in Programming Challenge 18 (Pizza Pi) 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. The program should ask the user for the number of people who will be at the party and for the diameter of the pizzas to be ordered. It should then calculate and display the number of pizzas to purchase.


Programming Challenge 18 (Pizza Pi)

Joe s Pizza Palace needs a 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) Calculate the number of slices that may be taken from a pizza of that size. 
C) Display a message telling the number of slices.
  • To calculate the number of slices that may be taken from the pizza, you must know the following facts: Each slice should have an area of 14.125 inches. 
  • To calculate the number of slices, simply divide 
  • the area of the pizza by 14.125. The area of the pizza is calculated with this formula: 

Solution: -

#include <iostream>

#include <iomanip>

#include <cmath>

using namespace std;

int main()

{

      const float PIZZA_AREA = 14.125,

            PI = 3.14159;

      float diameter;

      int people;

      double radius = 0.0, area = 0.0, no_of_slice = 0.0, slice_needed = 0.0, no_of_pizza = 0.0;

      cout << "How Many Peopel Who Ate The Pizza: ";

      cin >> people;

      cout << "What is The Diameter of Pizza in Inches:  ";

      cin >> diameter;

      //Calculation

      radius = diameter / 2.0;

      area = PI * pow(radius, 2);

      no_of_slice = area / PIZZA_AREA;

      slice_needed = people * 4;

      no_of_pizza = slice_needed / no_of_slice;

      cout << setprecision(1) << showpoint << fixed;

      cout << "No of Slice  =        " << no_of_slice << endl;

      cout << "No of Slice Needed =  " << slice_needed << endl;

      cout << "No of Pizza For Order = " << no_of_pizza << endl;

      return 0;

}

This is the solution of this question




OUTPUT OF THIS QUESTION 

Input is highlighted with yellow color.



Explanation of this Solution

  1. Add two header file for math and pattern.
  2. Declare two float constants and initialize given values.
  3. Declare another a float variable for input.
  4. Declare another a int variable for input.
  5. Declare five double variable for calculations.
  6. Take input one by one from user.
  7. Calculate the values.
  8. Calculate the values by using given formula.
  9.  In last, display output on the screen in a pattern.
  10. Return 0 to the main function.

Also, I attach CPP file of this problem. You can download this file

Click Here to Download This File





Post a Comment

0 Comments