Question

Part 1: Pizza Price Calculator Size S (10") M(13") L(16") Base Price $6.99 $9.99 $12.99 Each...

Part 1: Pizza Price Calculator

Size S (10") M(13") L(16")
Base Price $6.99 $9.99 $12.99
Each Topping $0.70 $1.00 $1.50

Develop a C++ program that reads in the size of a pizza (S,M, or L) and the number of toppings, and then outputs the total price of the pizza on the screen. The price must be calculated based on the table above. For example, when a customer orders a pizza of size 'M' with three toppings, the total price is $9.99 + $1.00 x 3 = $12.99. The maximum number of toppings for one pizza is 5.

  • Use three functions: one for input, one calculating, and one for output.
    • pizzaOrder: gets the size and the number of toppings.
      • Use call-by-reference to return two values back to main function.
      • The size must be a character, S, M, or L.
        • If user inputs characters other than S, M, or L, the program should prompt to input it again.
      • The number of toppings ranges 0 to 5.
        • If user inputs values out of the range, the program should prompt to input it again.
    • calculatePizzaPrice: calculate the total price of the pizza.
      • The price must be calculated based on the table above.
    • displayPizzaPrice: outputs the total price , size of the number of toppings on the screen.
      • Amounts in dollar should be formatted; show 2 digits of fraction part to represent the cent, like $12.99.
    • State 'precondition' and 'postcondition' for each function in comment lines.
    • Your functions should work with main function below.
  • Include a loop that lets the user repeat this computation for new input values until the user wishes to end the program.
    • This is implemented already. But you have to define askYesNo function. See below.
  • Declare variables to express all constant values used in the code with the modifier const. And use them in your code.
  • Use an appropriate data type for each variable and function.
  • Hint : see Supermarket Pricing code here.
  • State your name in a comment line.
int main(int argc, const char * argv[]) {
    do{
        // get a pizza order
        char pizzaSize;
        int numberOfToppings;
        pizzaOrder(pizzaSize,numberOfToppings);

        // calculate the price
        double pizzaPrice = calculatePizzaPrice(pizzaSize,numberOfToppings);
        
        // print the price
        displayPizzaPrice(pizzaSize,numberOfToppings,pizzaPrice);
        
        std::cout << "Repeat? [Y/N]";
    }while(askYesNo());
    
    std::cout << "Bye\n";
    return 0;
}

in C ++

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The program uses three functions

  • pizzaOrder - to get input
  • calculatePizzaPrice- calculates the pizza price based on the slab given
  • displaypizzaprice- displays the pizza size, number of toppings and prize
  • setprecision has been used to print the price with 2 decimal points.
  • both upper and lower case of letters of 's' or 'S', 'm' or 'M', 'l' or 'L' is accepted in this code.
  • To repeat the input letter 'y' or 'Y' should be given. if not the program quits.

Comments are given in the code

code:

#include<iostream>
#include<ctype.h>
#include<iomanip>
// pizzaOrder() get pizzaSize and number of Toppings as input from the user.
/*The size must be a character, S, M, or L.
If user inputs characters other than S, M, or L, the function should prompt to input it again.
The number of toppings ranges 0 to 5.
If user inputs values out of the range, the function should prompt to input it again.*/
void pizzaOrder(char* pizzaSize, int* n)
{
bool t = 1;
while (t)
{
t = 0;
std::cout << "\nEnter Pizza Size(S/M/L)-S-10inch,M-13inch and L-16inch :";
std::cin >> *pizzaSize;
if (toupper(*pizzaSize) != 'S' && toupper(*pizzaSize) != 'M' && toupper(*pizzaSize) != 'L')
{
std::cout << "\n Enter Valid Input";
t = 1;
continue;
}
}
t = 1;
while (t)
{
t = 0;
std::cout << "\n Enter Number of Toppings : ";
std::cin >> *n;
if (*n < 0 || *n>5)
{
std::cout << "\n Enter Valid Input";
t = 1;
continue;
}
}
}
/* alculate the total price of the pizza.
The price must be calculated based on the values given in the problem.
All the values should be declared as constant using const.
*/
double calculatePizzaPrice(char pizzaSize, int n)
{
const float sPrice = 6.99;
const float mPrice = 9.99;
const float lPrice = 12.99;
const float sTop = .70;
const float mTop = 1.00;
const float lTop = 1.50;
float pizPrice=0, topPrice=0;
if (toupper(pizzaSize) == 'S')
{
pizPrice = sPrice;
topPrice =n * sTop;
}
else if (toupper(pizzaSize) == 'M')
{
pizPrice = mPrice;
topPrice = n * mTop;
}
else if (toupper(pizzaSize) == 'L')
{
pizPrice = lPrice;
topPrice = n * lTop;std::cout << "topPrice: " << topPrice;
}
double price = pizPrice + topPrice;
  
return price;
}
/*outputs the total price , size of the number of toppings on the screen.
Amounts in dollar should be formatted; show 2 digits of fraction part to represent the cent, like $12.99.*/
void displayPizzaPrice(char pizzaSize, int n, double price)
{
std::cout << "\n Pizza Size : " << pizzaSize;
std::cout << "\n Toppings : " << n;
std::cout << "\n Pizza Price : $" << std::setprecision(4) << price;
}
bool askYesNo()
{
char ans;
std::cin >> ans;
if (toupper(ans) == 'Y')
return true;
else
return false;
}
// Main method
int main(int argc, const char* argv[])
{
do {
// get a pizza order
char pizzaSize;
int numberOfToppings;
pizzaOrder(&pizzaSize, &numberOfToppings);

// calculate the price
double pizzaPrice = calculatePizzaPrice(pizzaSize, numberOfToppings);

// print the price
displayPizzaPrice(pizzaSize, numberOfToppings, pizzaPrice);

std::cout << "\n Repeat? [Y/N]";
} while (askYesNo());

std::cout << "Bye\n";
return 0;
}

Screenshot

pizzaOrder()

calculatePizzaPrice()

dispalyPizzaPrice()

main()

Output 1:

Output 2:

As mentioned in the description of the problem state your name as comment.

Add a comment
Know the answer?
Add Answer to:
Part 1: Pizza Price Calculator Size S (10") M(13") L(16") Base Price $6.99 $9.99 $12.99 Each...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • using C# language This program will demonstrate inheritance. Your Pizza Shop expands and now handles delivery...

    using C# language This program will demonstrate inheritance. Your Pizza Shop expands and now handles delivery orders and sit down orders in a restaurant setting. There are differences in a SeatedPizzaOrder and a DeliveryPizzaOrder. These are more specialized versions of the PizzaOrders you have been creating all along and you decide to write a program that handles them the same as much as possible and reuses the code of a general PizzaOrder class as much as possible to demonstrate inheritance....

  • // Write a program that determines how many of each type of vowel are in an...

    // Write a program that determines how many of each type of vowel are in an entered string of 50 characters or less. // The program should prompt the user for a string. // The program should then sequence through the string character by character (till it gets to the NULL character) and count how many of each type of vowel are in the string. // Vowels: a, e, i, o, u. // Output the entered string, how many of...

  • Using Java, I created 3 files, Pizza,PizzaOrder, and PizzaOrder_Demo that I attached down below. But I...

    Using Java, I created 3 files, Pizza,PizzaOrder, and PizzaOrder_Demo that I attached down below. But I cannot compile it. Could you please point out the error.The question is that This programming project extends Q1. Create a PizzaOrder class that allows up to three pizzas to be saved in an order. Each pizza saved should be a Pizza object as described in Q1. In addition to appropriate instance variables and constructors, add the following methods: public void setNumPizzas(int numPizzas)—sets the number...

  • MUST BE PROCEDURAL CODE, DO NOT USE GLOBAL VARIABLES. Write a program in C++that generates random...

    MUST BE PROCEDURAL CODE, DO NOT USE GLOBAL VARIABLES. Write a program in C++that generates random words from a training set as explained in the lectures on graphs. Do not hard-code the training set! Read it from a file. A suggested format for the input file: 6 a e m r s t 10 ate eat mate meet rate seat stream tame team tear Here are some suggestions for constants, array declarations, and helper functions #include <iostream> #include <fstream> #include...

  • Pizza Hub sells pizzas of four sizes, S, M, L, X. The prices are $6.99, $8.99,...

    Pizza Hub sells pizzas of four sizes, S, M, L, X. The prices are $6.99, $8.99, $12.50, and $15.00 respectively. For each pizza, there is an optional extra topping that costs $1.00, $2.00, $3.25, and $4.50 for each size. Write a program to prompt a user to order one pizza of any size, and then ask if an extra topping is needed. Based on these, calculate and display the cost of the ordered pizza accordingly. For this program, you need...

  • C++ ONLY!!! NOT JAVA. The standard deviation is calculated from an array X size n with...

    C++ ONLY!!! NOT JAVA. The standard deviation is calculated from an array X size n with the equation std=sqrt(sum((xi-mean)2/(n-1))) Sum the square of difference of each value with the mean. Divide that sum by n-1. Take the square root and you have the standard deviation. //System Libraries #include <iostream> //Input/Output Library #include <cstdlib> //Srand #include <ctime> //Time to set random number seed #include <cmath> //Math Library #include <iomanip> //Format Library using namespace std; //User Libraries //Global Constants, no Global Variables...

  • Help with C++ reverse program with leading zeros. I need to put the line from the...

    Help with C++ reverse program with leading zeros. I need to put the line from the function that display the zeros in main not in the function. So how can I move the display with leading zeros in main. Thanks. Here is my code. #include <iostream> #include <cstdlib> #include <iostream> using std::cout; using std::cin; using std::endl; //function templates int reverseNum(int); int main() { //variables char buf[100]; int num; while (true) { //prompt user for input cout << "Enter the number...

  • USE!! PYTHON!!! Programming:   Pizza 1. Write a Pizza class to that this client code works. Please...

    USE!! PYTHON!!! Programming:   Pizza 1. Write a Pizza class to that this client code works. Please note that it is ok if the toppings are listed in a different order. >>> pie = Pizza() >>> pie Pizza('M',set()) >>> pie.setSize('L') >>> pie.getSize() 'L' >>>pie.addTopping('pepperoni') >>>pie.addTopping('anchovies') >>>pie.addTopping('mushrooms') >>> pie Pizza('L',{'anchovies', 'mushrooms', 'pepperoni'}) >>>pie.addTopping('pepperoni') >>> pie Pizza('L',{'anchovies', 'mushrooms', 'pepperoni'}) >>>pie.removeTopping('anchovies') >>> pie Pizza('L',{'mushrooms', 'pepperoni'}) >>> pie.price() 16.65 >>> pie2 = Pizza('L',{'mushrooms','pepperoni'}) >>> pie2 Pizza('L',{'mushrooms', 'pepperoni'}) >>> pie==pie2 True The Pizza class should have...

  • The purpose of this problem is to sort a 2 dimensional array of characters. Specify the...

    The purpose of this problem is to sort a 2 dimensional array of characters. Specify the size of the array and input the array. If the array is longer than specified, output if it is larger or smaller. Utilize the outputs supplied in main(). Example supplied in 2 test cases. Input 3↵ 3↵ 678↵ 567↵ 456↵ Expected Output Read·in·a·2·dimensional·array·of·characters·and·sort·by·Row↵ Input·the·number·of·rows·<=·20↵ Input·the·maximum·number·of·columns·<=20↵ Now·input·the·array.↵ The·Sorted·Array↵ 456↵ 567↵ 678↵ Input 3↵ 5↵ Ted↵ Mary↵ Bobby↵ Expected Output Read·in·a·2·dimensional·array·of·characters·and·sort·by·Row↵ Input·the·number·of·rows·<=·20↵ Input·the·maximum·number·of·columns·<=20↵ Now·input·the·array.↵ The·Sorted·Array↵ Bobby↵...

  • C++ problem where should I do overflow part? in this code do not write a new...

    C++ problem where should I do overflow part? in this code do not write a new code for me please /////////////////// // this program read two number from the user // and display the sum of the number #include <iostream> #include <string> using namespace std; const int MAX_DIGITS = 10; //10 digits void input_number(char num[MAX_DIGITS]); void output_number(char num[MAX_DIGITS]); void add(char num1[MAX_DIGITS], char num2[MAX_DIGITS], char result[MAX_DIGITS], int &base); int main() { // declare the array = {'0'} char num1[MAX_DIGITS] ={'0'}; char...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT