Tuesday, 23 October 2018

Pizza Pi | Set #2 | C++

Problem Set 2. How Many Pizzas?

Modify the program you wrote in Problem Set 1(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.

The code for the above described problem is give below:
copy & enjoy!


#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\t\t\t----Pizza Pi----\t\t\t\t\t |" << endl;   // Program Title
cout << "--------------------------------------------------------------------------------------------------" << endl;
cout << "|  This program will ask for the number of people who will attend the party & diameter of Pizza  |\n";
cout << "|              and then it will tell you how many pizzas you should buy for the party.           |\n";
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
nPple,         // Here "nPple" stands for the number of people
nPiz,          // Here "nPiz" stands for the number of pizzas
radius;

cout << "|  How many people are comming to your party?\t\t\t\t\t\t         |" << endl;
cout << "|  ";
cin >> nPple;
cout << "|  Write the dimeter in inches of pizza you want to buy. \t\t\t\t\t |" << endl;
cout << "|  ";
cin >> dimtr;      // Input from the user for the diameter of the Pizza

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 from one pizza
nPiz = (nPple * 4) / nSlc;

cout << "--------------------------------------------------------------------------------------------------" << endl;
cout << "| \t\t\tThe pizza of diameter " << dimtr << " will have about " << setprecision(1) << fixed << nSlc << " slices\t\t\t |" << endl;
cout << "|\t\t\t     If each person eats 4 slices in the party\t\t\t\t |" << endl;
cout << "| \t\tthe you should buy about " << nPiz << " pizzas to fullfil the need of the party\t\t |" << endl;
cout << "--------------------------------------------------------------------------------------------------" << endl;


cout << endl;
cout << "       \t\t\t\t-----------------------------" << endl;
cout << "       \t\t\t\t| Made By -------> Asad Ali |" << endl;
cout << "       \t\t\t\t-----------------------------" << endl;

system("pause");
return 0;         // Return a zero value to the main function
} // end main function



OutPut of this code / problem will go like this:



Now we ENTER 12 number of people



Then we ENTER 8 inches as diameter of pizza
and result goes as follows:


Share:

Monday, 22 October 2018

Pizza Pi | Set #1 | C++

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

Output of this code will go like that:



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.


Share:

padacode.blogspot.com

Powered by Blogger.