Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify this C++ Program in the main program only declare one instance of the struct and use an external file to store all of the

Modify this C++ Program in the main program only declare one instance of the struct and use an external file to store all of the costumers. In the main program a single instance of customers is to be declared. Next create a main menu. The menu will first ask if the customer wants a cup of coffee and provide choices for yes, no or quit. If the customer chooses yes, the program should ask for the first name and store it in the appropriate location. Next, the program should display the options and allow the user to enter their coffee preferences. Based on the customers input the cost should be calculated. Then the customers order number should be displayed. Next the program will store information in a text file named CustOrder.dat in the order given below. OrderNumber, CoffeeName, strength, size, sugarAmount, cream, cost If in the main menu the customer chooses no then the system should show a menu with the following options 1) View an order (which will require an order number), 2) Calculate total profit. Item 2) requires you to write a function that will add up all of the cost values in the file. The result is the total profit. The program should loop until the user chooses to quit in the main menu. #include  #include  #include  using namespace std; struct Coffee { int name; float cost; int strength; bool cream; int amtofsugar; int size; } coffee; struct Customer { string fname[20]; int orno; struct Coffee c1; } customer[100]; float Cost(int name, int size, int sugar, int cream) { float total; total = 0; if (size == 0) { total = 1.50; } else if (size == 1) { total = 2.10; } else if (size == 2) { total = 2.50; } else if (size == 3) { total = 3.00; } else { total = 4.25; } if (name == 1 || name == 2) { total += 0.25; } total += sugar * 0.13; if (cream != 0) { total += 0.08; } return total; } int main() { string quit; Coffee coffee; Customer customer[100]; string name[20]; string answer; cout << "Do you want a cup of coffee: "; cin >> answer; if (answer == "yes") { for (int i = 0; i < 100; ++i) { cout << "Enter your name: "; cin >> customer[i].fname[15]; do { cout << " What type of coffee is it? (Columbian=0, French Roast=1, Italian Blend=2, or House=3: "; cin >> coffee.name; cout << " Enter the size of the coffee (small=0, regular=1, medium=2, large=3, extra-large =4): "; cin >> coffee.size; cout << " Enter the strength of the coffee (1-light, 2-medium, 3-dark): "; cin >> coffee.strength; cout << " Enter the amount of sugar (0-none, 1, 2, 3, 4) in the coffee: "; cin >> coffee.amtofsugar; cout << " Enter 1 for cream 0 for no cream: "; cin >> coffee.cream; cout << " Coffee Info:"; if (coffee.name == 0) cout << " Name: " << "Columbian"; else if (coffee.name == 1) cout << " Name: " << "French Roast"; else if (coffee.name == 2) cout << " Name: " << "Italian Blend"; else if (coffee.name == 3) cout << " Name: " << "House"; else cout << " Wrong choice!!"; if (coffee.amtofsugar == 0) cout << " Amount of sugar: " << "None"; else cout << " Amount of sugar: " << coffee.amtofsugar; if (coffee.strength == 1) cout << " Strength: " << "Light"; else if (coffee.strength == 2) cout << " Strength: " << "Medium"; else if (coffee.strength == 3) cout << " Strength: " << "Dark"; else cout << " Wrong choice!!"; if (coffee.size == 0) cout << " Size: " << "Small"; else if (coffee.size == 1) cout << " Size: " << "Regular"; else if (coffee.size == 2) cout << " Size: " << "Medium"; else if (coffee.size == 3) cout << " Size: " << "Large"; else if (coffee.size == 4) cout << " Size: " << "Extra Large"; else cout << " Wrong choice!!"; if (coffee.cream) cout << " Cream: " << "Yes"; else cout << " Cream: " << "No"; cout << " Cost: " << Cost(coffee.name, coffee.size, coffee.amtofsugar, coffee.cream); cout << " Enter 'quit' to quit or go through the options again."; cin >> quit; } while (quit != "quit"); customer[i].orno = i + 1; cout << "OrderNumber: " << customer[i].orno; break; } } else if (answer == "no") { cout << "Enter your Name:"; cin >> name[15]; for (int i = 0; i < 100; ++i) { if (name == customer[i].fname) { cout << "Order Number" << i + 1; } } } return 0; }

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

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions