Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The programming language is C++ Given the following programming need Joe\'s Pizz

ID: 3882240 • Letter: T

Question

The programming language is C++

Given the following programming need Joe's Pizza Palace needs a program to determine the number of pizzas one needs 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 To calculate the number of pizzas, one must know the number of slices that may be taken from the pizza. To calculate the number of slices 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 where (r for radius is ½ of diameter) Write a program with the specifications and instructions given below Follow the guidelines given in the Program Documentation document for all user-defined identifiers (variables, named constants and functions) and other aspects of programming form and style 1. Use named constants for ALL identifiers whose values will not change during program execution. (There are three of them.) These may be defined globally, above main, so that they may be accessed by the functions which require them for calculations. Note: These values will be changed during grading 2. 3. Define integer data types for ALL input and ALL output variables Only two values will be input in this order-people, diameter. This is explained in more detail below but you will calculate the output number of slices per pizza and the number of pizzas to order as whole numbers (integers) but display them with one decimal place of precision so that the whole value is obvious. Do the math calculations manually before coding Make the program iterative allowing the user to input multiple sets of data, terminating when the user enters the sentinel value -1 for the number of people to feed at the party. The main function will need a counter variable which increments with each order placed 4. 5. Code a generic value returning function to calculate and return the area of the pizza as a type double The function should have one int input parameter for the diameter. Use the pow function when calculating area. Because area must be calculated as a floating point double data type you must either perform Type Casting or use literal values of type double in the calculation of area NOTE: Generic - meaning that function could be used to calculate the area of any circle given an integer parameter for its diameter. Do not use the word "pizza “ in the code or documentation. This function can be placed in a reusable library for use in other programs 6. Write a value returning function to calculate and return the number of slices per pizza as a type int. The function should have one double input parameter for the area. Calculate the number of slices using double floating point values but before returning, downcast the calculated value to a whole number (an int) so that there will be no fractions of a pizza remaining. You must use type casting to remove any warning message:s

Explanation / Answer

C++ complete program:

#include<iostream>

#include<cmath>

#include <iomanip>

#include <locale>

using namespace std;

//function declarations

double areaCal(int dia);

int numOfSlices(double input);

int numOfPizzasToOrder(int in1,int in2);

void display(int a,int b,int c,int d,int e);

//constatns

const double SLICEAREA=14.125;

const double PIE =3.14;

int main()

{

int numOfPeople,diameter;

int counter=0,num;

//asking the usert to start the program and -1 to quit

cout<<"Enter any number to start,-1 to quit. ";

cin>>num;

//while loop to make program iterative until user enters -1

while(num!=-1)

{

//incrementing counter value

counter++;

//asking for inputs and stroring them in respective variables

cout<<" Enter the number of people in party #"<<counter<<":";

cin>>numOfPeople;

cout<<"Enter the diameter of the pizza you wish to buy:";

cin>>diameter;

//calling functions

double area=areaCal(diameter);

int slices=numOfSlices(area);

int numOfPizzas=numOfPizzasToOrder(numOfPeople,slices);

display(numOfPeople,diameter,counter,slices,numOfPizzas);

//asking the user again to making the program iterative

cout<<" Enter any number to continue,-1 to quit. ";

cin>>num;

}

cout<<"Thank you.Bye.";

return 0;

}

//function implementations

double areaCal(int diameter)

{

double area;

area=(double)PIE*pow(0.5*diameter,2);

return area;

}

int numOfSlices(double area)

{

return (int)(area/SLICEAREA);

}

int numOfPizzasToOrder(int people,int slices)

{

//implement the logic to calcualte the number of pizzas

return 15;

}

void display(int numOfPeople,int diameter,int counter,int numOfSlices,int numOfPizzas)

{

//displaying output to console

cout<<" Pizza #"<<counter<<" Requirements";

cout<<" ";

cout<<left << setw(2)<<" Number of People "

<< right << setw(16) <<numOfPeople;

cout<<left << setw(2)<<" Pizza Diameter "

<< right << setw(17) <<diameter;

cout<<left << setw(2)<<" Number of Slices per Pizza "

<< right << setw(5) <<numOfSlices;

cout<<left << setw(2)<<" Number of Pizzas to Order "

<< right << setw(6)<<numOfPizzas;

cout<<" ";

}