Problem Set 1. 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: Area = πr2
NOTE: π is the Greek letter pi = 3.14159 can be used as its value. The variable r is the radius of the pizza. Divide the diameter by 2 to get the radius.
Make sure the output of the program displays the number of slices in fixed point notation, rounded to one decimal place of precision.
Code for the above Problem is given below:
#include "pch.h" // if you are not using Microsoft Visual Studio you can remove this line
#include <iostream> // input output library
#include <iomanip> // library for setting precision
using namespace std;
const double pi = 3.14159; // global veriable for pi and its value cannot be changed
const double slcArea = 14.125; // global variable for area of slices and this value cannot be changed
int main() // start of main function
{
cout << "-------------------------------------------------" << endl;
cout << "|\t\t----Pizza Pi----\t\t|" << endl; // Program Title
cout << "-------------------------------------------------" << endl;
cout << "| This program will ask for diameter of Pizza |\n";
cout << "| and then will tell you how many slices |\n";
cout << "| can be takken form that Pizza. |" << endl;
cout << "-------------------------------------------------" << endl;
double dimtr, // Here "dimtr" stands for diameter of the pizza
nSlc, // Here "nSlc" stands for number of slices of pizza
area, // Here "area" stands for the area of the pizza
radius;
cout << "| Enter the diameter of the pizza (inches) : ";
cin >> dimtr; // Input from the user for the diameter of the Pizza
cout << "-------------------------------------------------" << endl;
radius = dimtr / 2; // converts diameter of pizza into radius
area = pi * pow(radius, 2); // finds the area of the piza as Area = πr2
nSlc = area / slcArea; // finds the number of slices can be takken
cout << "| Number of slices can be taken from pizza |\n| with diameter " << dimtr << " is : "
<< setprecision(1) << fixed << nSlc << endl;
cout << "-------------------------------------------------" << endl;
cout << endl;
cout << " -----------------------------" << endl;
cout << " | Made By -------> Asad Ali |" << endl;
cout << " -----------------------------" << endl;
return 0; // Return a zero value to the main function
} // end main function
#include <iostream> // input output library
#include <iomanip> // library for setting precision
using namespace std;
const double pi = 3.14159; // global veriable for pi and its value cannot be changed
const double slcArea = 14.125; // global variable for area of slices and this value cannot be changed
int main() // start of main function
{
cout << "-------------------------------------------------" << endl;
cout << "|\t\t----Pizza Pi----\t\t|" << endl; // Program Title
cout << "-------------------------------------------------" << endl;
cout << "| This program will ask for diameter of Pizza |\n";
cout << "| and then will tell you how many slices |\n";
cout << "| can be takken form that Pizza. |" << endl;
cout << "-------------------------------------------------" << endl;
double dimtr, // Here "dimtr" stands for diameter of the pizza
nSlc, // Here "nSlc" stands for number of slices of pizza
area, // Here "area" stands for the area of the pizza
radius;
cout << "| Enter the diameter of the pizza (inches) : ";
cin >> dimtr; // Input from the user for the diameter of the Pizza
cout << "-------------------------------------------------" << endl;
radius = dimtr / 2; // converts diameter of pizza into radius
area = pi * pow(radius, 2); // finds the area of the piza as Area = πr2
nSlc = area / slcArea; // finds the number of slices can be takken
cout << "| Number of slices can be taken from pizza |\n| with diameter " << dimtr << " is : "
<< setprecision(1) << fixed << nSlc << endl;
cout << "-------------------------------------------------" << endl;
cout << endl;
cout << " -----------------------------" << endl;
cout << " | Made By -------> Asad Ali |" << endl;
cout << " -----------------------------" << endl;
return 0; // Return a zero value to the main function
} // end main function
When the 12 was entered:
So, what is meant by this; this program actually takes input from the user for the diameter of the Pizza then the program will show the number of slices can be taken form that particular size Pizza.
0 comments:
Post a Comment
Thanks for visiting my Blog.
Have any problem, feel free to contact us via Email: asadalipkp9@gmail.com
Have a nice day!