In: Computer Science
1. Start a new customer order – clear the order data (give a second chance to not clear data) This will clear all the running totals (set them to zero).
Ordering Ice Cream Sundaes – should prompt the user for the number of ice cream sundaes.
Ordering Ice Cream Cones – should prompt the user for the number of ice cream cones.
Ordering Milkshakes – should prompt the user for the number of milkshakes.
Generate the customer receipt for their order. This should be appended to any other
orders already written to the file. The receipt output file should be named: receipt.rpt
Exit the program - Make sure to exit the program gracefully through the return 0 at the
bottom of main( ).
Write a menu driven program that will provide the user with the 6 menu options indicated above. The user should be able to make a selection, execute the code for that selection, and then return to the menu until option (6) Exit is selected. If the end-user enters an invalid menu option, print an error message and redisplay the menu, getting a new selection.
When an option from the menu is selected your program should call a function to do the selection processing. If the end-user enters a qty that is less than 0 or enters character data, print an error message and prompt the user for a new value. Keep a running total of how many of each item is ordered.
When the option to start a new order is selected, ask the user if they are sure they want to clear the order. If the user answers ‘y’ or ‘Y’ then clear the running totals for all ice cream products. Any other input should not clear the running totals.
When the end-user selects to create a receipt, write a summary of the items ordered (don't print items that have a count of zero), calculate the subtotal, tax (using 6%), and the total order to an output file named receipt.rpt (use append mode of opening the file so each order is appended to the end of the file). If the entire order is zero, do not generate a summary; simply write the line: No order was placed. Each receipt written should have a delimiter, a new line, line of “*”, and a new line. In c++
All the explanation is in the code comments. Hope this helps!
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int flag = 0, choice, is = 0, ic = 0, m = 0, x;
// cost per item
double pis = 110.0, pic = 45.5, pm = 99.9;
double subtotal, tax, total;
// open file
ofstream fout;
fout.open("receipt.rpt", std::ios_base::app);
// run till exited
while(flag!=1)
{
// give options to user
cout << "1 - Clear the order data" << endl;
cout << "2 - Order Ice Cream Sundaes" << endl;
cout << "3 - Order Ice Cream Cones" << endl;
cout << "4 - Order Milkshakes" << endl;
cout << "5 - Generate receipt for order" << endl;
cout << "6 - Exit the program" << endl;
// user choice
cout << "Enter choice: ";
cin >> choice;
if(choice == 1)
{
string tmp;
// again ask if to be cleared
cout << "Are you sure you want to clear order (y/Y)?:
";
cin >> tmp;
if(tmp == "Y" || tmp == "y")
{
// set everything to 0
is = 0;
ic = 0;
m = 0;
}
}
else if(choice == 2)
{
// take input till valid is not found
while(true)
{
cout << "Enter quantity for Ice Cream Sundaes: ";
cin >> x;
if(x > 0)
break;
cout << "Quantity should be greater than 0" <<
endl;
}
// add to ice cream Sundaes
is += x;
}
else if(choice == 3)
{
// take input till valid is not found
while(true)
{
cout << "Enter quantity for Ice Cream Cones: ";
cin >> x;
if(x > 0)
break;
cout << "Quantity should be greater than 0" <<
endl;
}
//add to ice cream cones
ic += x;
}
else if(choice == 4)
{
// take input till valid is not found
while(true)
{
cout << "Enter quantity for Milkshakes: ";
cin >> x;
if(x > 0)
break;
cout << "Quantity should be greater than 0" <<
endl;
}
// add to Milkshakes
m += x;
}
else if(choice == 5)
{
// Generate receipt
if(ic == 0 && is == 0 && m==0)
fout << "No order was placed." << endl;
else
{
// print in the format required
if(is!=0)
fout << "Ice Cream Sundaes: " << is <<
endl;
if(ic!=0)
fout << "Ice Cream Cones: " << ic << endl;
if(m!=0)
fout << "Milkshakes: " << m << endl;
subtotal = pis*is + pic*ic + pm*m;
fout << "Subtotal: $" << subtotal << endl;
tax = (6*subtotal)/100;
fout << "Tax: $" << tax << endl;
total = subtotal + tax;
fout << "Total: $" << total << endl;
}
fout << "\n****************************************\n"
<< endl;
}
// exit by setting flag to 1
else if(choice == 6)
{
flag = 1;
}
else
{
// invalid choice
cout << "Wrong choice\n";
}
}
return 0;
}
Sample run:
input:


ouput file:

Code screenshots:



