Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ I need to add a new class to my program down below. This new class will have the structs inside of it and now

C++ I need to add a new class to my program down below. This new class will have the structs inside of it and now kinda do inventory check after an order is placed. Its passed to a receive() method in the new class. Then this will call a calcRemainproduct() to determine if there enough product to complete the order. Subtract the amount of each product from their respective amounts. If there not enough it returns a message that it can't complete order and which product is low. Then calculates the remaining amounts and compares the low amount threshold ( threshold enough to produce 4 cups). If a product is low it sends a low product warning. The manager then can refill this towards the end of the code with the switch options. The final part is producing the order, giving a return message that the order is ready or if there wasn't enough that it can't be filled due to low product. The amounts to be used is Coffee: 0.25 for each strength level, .5 per size, 2 for creamer (if selected), 1 for each sugar used.

#include #include #include #include #include using namespace std; enum strength {light=1, medium=2, dark=3}; enum coffeeName {Columbian=1, FrenchRoast=2, ItalianBlend=3, House=4}; struct cafe { int coffeeName; double price; int strength; int size; int sugar; bool creamer = true; bool blend = true; }; struct customer { string name; cafe rdata; int order; //ordernumber }; void calcPrice(customer &c) { double price = 0; if(c.rdata.size == 0) price = 1.50; else if (c.rdata.size == 1) price = 2.10; else if(c.rdata.size == 2) price = 2.50; else if(c.rdata.size == 3) price = 3.00; else if (c.rdata.size == 4) price= 4.25; if(c.rdata.blend != false) price = price + 0.25; if(c.rdata.creamer != false) price = price + 0.08; if(c.rdata.sugar == 1) price = price + 0.13; else if(c.rdata.sugar == 2) price = price +(2*0.13); else if(c.rdata.sugar == 3) price = price + (3*0.13); c.rdata.price = price;

} int main() { customer c; struct customer arr[10]; //order number char ch1,ch2,input; //char input; int i,option, answer; int flag = 0;

do{ do { cout<<" Main Menu. "<>input; cin.ignore(); if((input == 'y')||(input == 'Y')) { cout<<"Name for the order?"<

cout<<"What coffee would you like?"<<" Columbian=1, FrenchRoast=2, ItalianBlend=3, House=4"<>c.rdata.coffeeName; cout<<"How strong? (Light=1,Medium=2,Dark=3)"<>c.rdata.strength; cout<<"Size of Coffee?(S=0,R=1,M=2,L=3,XL=4)"<>c.rdata.size; cout<<"How much sugar?"<>c.rdata.sugar; cout<<"Would you like French roast or Italian blend(Y/N)"<>input; if(ch1=='Y') { c.rdata.blend=true; } cout<<"Do you want creamer?(Y/N)"<>input; if(ch2=='Y') { c.rdata.creamer=true; } cout<<"Here is your order number #:"<<(arr[10].order + 1)<

//writing out to the file fstream infile("menu.dat", ios::out | ios::app); infile<< "OrderNumber:" << c.order << " CoffeeName:" << c.rdata.coffeeName << " Strength" << c.rdata.strength << " Size: " << c.rdata.size << " SugarAmount: " << c.rdata.sugar << endl; calcPrice(c); infile<< "Cream: " << c.rdata.creamer << " Cost: $ " << c.rdata.price << endl; infile.close();

cout<<"Back to Main menu?"<>input; } }//inner do while loop while(input == 'Y'||input == 'y');

//if user selects No in Main Menu if(input == 'N'||input == 'n') { cout<<"[1]View an order " <<"[2] View Total Profit "; cin>>answer;

switch(answer) { case 1: cout<<"Enter a order number"; cin>>option;

for(i=0;i<10;i++){ //display option if(arr[10].order != option) { flag = 1; cout<<"Here is your order:"<

} case 2: char filename[] = "menu.dat"; ifstream infile(filename); string line; double total_price = 0.0; double amount = 0.0; cout << "Calculating total profit"; while(getline(infile, line, ' ')) { size_t found = line.find('$'); //check line containing $ if(found !=string::npos) { stringstream ss(line.substr(1+found)); //grab the amound ss>>amount; //convert string to dollar total_price+=amount; //add the dollar to running total } } infile.close(); cout << " Total profit: " << total_price << endl; break;

}

} reorder code

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions