Question

In: Computer Science

C++ Pie bakery our bakery makes 8 kinds of pie, and receives orders for these pies...

C++ Pie bakery

our bakery makes 8 kinds of pie, and receives orders for these pies from on-line buyers. The program you’ll write for this lab knows the price of each pie, so as each new order is received, it’s possible to know how much money the bakery should be receiving.

The program must read in lines of input which have two fields: a pie type and a quantity. With this, the program needs to update the quantity of that type of pie, adding the new order to those already received. You already have code that you’ve written for previous labs that uses getline() and splits the line read in into two separate parts: you get to re-use that here, since you have the same work to do – breaking an input string into two substrings, the first is the name of a kind of pie string and the second is the quantity int.

The program you are writing would be part of a larger system used by the bakery to track and schedule its baking. That’s good for you because it means that the input your program reads is guaranteed not to have bogus order numbers or pie types. A sample input line looks like:

raspberry 10

When the program reaches the end of input it prints out, for each type of pie, the quantity ordered and the total price of that number of those pies. After that it prints out the grand total of all orders (total number of pies, total price).

One problem you face is mapping pie types as strings (how you read them in) to the int index of the array element holding the struct for that pie type. For example, you might read in ”apple” and need to figure out that it’s in array element 3. You must use a function to handle this.

To make life a bit easier, you should initialize an array of struct with these pie types and prices:

peach lemon pumpkin blueberry apple raspberry strawberry cherry

$3.75 $4.50 $5.75 $4.25 $3.70 $6.35 $5.65 $5.20

Of course, you’ll need more than just these two fields in your struct.
A sample run with 100 individual pie orders might produce output like this.

Orders for peach:
Orders for lemon:
Orders for pumpkin:
Orders for blueberry:
Orders for apple:
Orders for raspberry:
Orders for strawberry:
Orders for cherry:

115 value is $ 431.25 128 value is $ 576.00 75 value is $ 431.25 75 value is $ 318.75 71 value is $ 262.70 89 value is $ 565.15 122 value is $ 689.30 53 value is $ 275.60

Grand total: 728 pies for $3550.00

You can test your program with data you type in, or on a test data file you create.

Solutions

Expert Solution

#include <iostream>
using namespace std;
int main()
{
    string pie_types [] = {"peach", "lemon", "pumpkin", "blueberry", "apple" ,"raspberry", "strawberry", "cherry"};
    float price[] = {3.75 ,4.50 ,5.75 ,4.25 ,3.70 ,6.35, 5.65, 5.20};
    int n;
    float grand_total = 0;
    int number_of_items[8];
    int total_item = 0;
    for(int i = 0;i<8;i++)
    {
        cout<<"Enter "<<pie_types[i]<<" quantity ";   // Enter quantity for each item
        cin>>number_of_items[i];                      // Store quantity in number of items array      
        total_item += number_of_items[i];             // Total number of items
    }
    for(int i = 0;i<8;i++)
    {
        cout<<"Orders for "<<pie_types[i]<<" : "<<"$"<<(price[i]*number_of_items[i])<<endl; // total cost of each item
        grand_total += price[i]*number_of_items[i];
    }
    
    cout <<"Grand Total: " <<total_item <<" Pies for "<<"$"<<grand_total;   // Grand total of all the items 
    return 0;
}

Related Solutions

Bart's Bakery makes two kinds of pies: apple and blueberry. If you select a pie at...
Bart's Bakery makes two kinds of pies: apple and blueberry. If you select a pie at random, the probability it is apple is 0.88. Bart's Bakery also makes two sizes of pies: large and small. The probability a randomly selected apple pie is large is 0.60. The probability a randomly selected blueberry pie is large is 0.75. Given that a randomly selected pie is small, what is the probability it is an apple pie? Group of answer choices 0.9215 0.0785...
Problem B Peerless Pies makes various kinds of pie, including pumpkin pies. The demand for pumpkin...
Problem B Peerless Pies makes various kinds of pie, including pumpkin pies. The demand for pumpkin pies varies, based on time of year and other factors. The company wants to determine the reorder point for pumpkins. Average pounds of pumpkins needed 60 pounds per week Standard deviation of demand 4 pounds per week    Customer service level desired 97.5% Lead time 2    weeks 3 What amount of safety stock is appropriate? 4 Determine the reorder point. (Round up if necessary.) 5...
Buck and Sally Starnes formed the Starnes Pie Cooperative.  The company makes pies, all kinds of pie,...
Buck and Sally Starnes formed the Starnes Pie Cooperative.  The company makes pies, all kinds of pie, with a specialty in Derby Pie, but has an assorted collection of fruit pies, meringues, and even a Boston Cream Pie that is to die for.  At first, the couple operated the company out of their own kitchen and garage.  With some success, Buck and Sally eventually quit their “real” jobs to work on pies full time.  They hired several workers to help them process orders too.  They...
STPL is considering acquiring Pie Smiles, a small chain bakery that specialise in making gourmet pies. A sales manager from Pie Smiles has provided the following actual sales:
  STPL is considering acquiring Pie Smiles, a small chain bakery that specialise in making gourmet pies. A sales manager from Pie Smiles has provided the following actual sales: Year Sales ($) 1 9,000 2 9,900 3 10,360 4 11,260 5 11,680 6 ? The sales manager from Pie Smiles has suggested that sales would be $8,200 in year 1.   Required: Using exponential smoothing with a weight of α =0.3, develop forecasts for years 2 through to 6 . Using...
C# Question: OO Design Our battleships game needs several different kinds of ship – we need...
C# Question: OO Design Our battleships game needs several different kinds of ship – we need a type to store the ships and information about it. Create a base class called Ship Create child classes for each of the ship types in the game (https://en.wikipedia.org/wiki/Battleship_(game)#Description) that inherit from Ship Ships should have the following properties A private array of positions A Position is composed of an X and Y coordinate – you should create a struct to encapsulate this A...
A steam turbine receives 8 kg/s of steam at 9 MPa, 650 C and 60 m/s...
A steam turbine receives 8 kg/s of steam at 9 MPa, 650 C and 60 m/s (pressure, temperature and velocity). It discharges liquid-vapor mixture with a quality of 0.94 at a pressure of 325 kPa and a velocity of 15 m/s. In addition, there is heat transfer from the turbine to the surroundings for 560 kW. Find the power produced by the turbine and express it in kW
A steam turbine receives 8 kg/s of steam at 9 MPa, 650 C and 60 m/s...
A steam turbine receives 8 kg/s of steam at 9 MPa, 650 C and 60 m/s (pressure, temperature and velocity). It discharges liquid-vapor mixture with a quality of 0.94 at a pressure of 325 kPa and a velocity of 15 m/s. In addition, there is heat transfer from the turbine to the surroundings for 560 kW. Find the power produced by the turbine and express it in kW.
c- The check-cashing store also makes one-month add-on interest loans at 8 percent discount interest per...
c- The check-cashing store also makes one-month add-on interest loans at 8 percent discount interest per week. Thus if you borrow $100 for one month (four weeks),the interest will be ($100 × 1.084 ) − 100 = $36.05. Because this is discount interest, your net loan proceeds today will be $63.95. You must then repay the store $100 at the end of the month. To help you out, though, the store lets you pay off this $100 in installments of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT