In: Computer Science
Please in C++, show screenshots of output plus .txt file. thanks
Breakfast Billing System
Write a program to help a local restaurant automate its breakfast
billing system. The program should do the following:
Show the customer the different breakfast items offered by the
restaurant.
Allow the customer to select more than one item from the
menu.
Calculate and print the bill
Assume that the restaurant offers the following breakfast items
(the price of each item is shown to the right of the item):
Plain Egg $1.45
Bacon and Egg $2.45
Muffin $0.99
French Toast $1.99
Fruit Basket $2.49
Cereal $0.69
Coffee $0.50
Tea $0.75
Use an array, menuList, of the struct menuItemType, with three
components: menuItem of string, menuPrice of type double, and Count
of type int. Your program must contain at least the following
functions:
Function getData: This function loads the data from a file named
menu.txt with the above breakfast items into the array
menuList.
Function showMenu: This function shows the different items offered
by the restaurant and tells the user how to select the items.
Function printCheck: This function calculates and prints the check.
(Note that the billing amount should include a 5% tax.)
A sample output is:
Welcome to Johnny’s Restaurant
Bacon and Egg 1 $2.45
Muffin 1 $0.99
Coffee 2 $1.00
Amount Total $4.44
Tax $0.22
Amount Due $4.66
*******************************************Summary**********************************************
The program for above question is given below with comments and output screenshots and file screenshot
The program is working absolutely same as asked in the question
However , there is not much code in main () function , as everything is done in the functions so...
I hope it works for you!!!!!!
********************************************Program**********************************************
#include <iostream>
#include<fstream> //for reading and writing in file
using namespace std;
struct menuItem //struct menuItem
{
string Item;
double Price;
int Count;
};
menuItem menuList[8]; //creating menuList array of type menuItem
void getData()
{
ifstream file;
file.open("menu.txt"); //opening file..Note:the pile must be in same folder as .cpp file otherwise you will have to specify the path of file in quotes
string item,s; //variables
double price;
int i=0;
do{
getline(file,item,'$'); //reading the string untill $ sign
file>>price; //reading the double value from file and storing in price
menuList[i].Item=item; //storing item name in menuList i th element
menuList[i].Price=price; //storing item price in menuList i th element
menuList[i].Count=0; //setting count =0 of all items
i++;
}while(getline(file,s)); //storing a string in s until new line and if the line is stored then continue the loop
//In above loop if we dont store the line in s ..it takes the \n character of previous line in the Item name ..so had to store it in string s
file.close(); //closing file
}
void showMenu()
{
int choice,count;
cout<<"*****************MENU**********************"<<endl;
for(int i=0;i<8;i++)
{
cout<<(i+1)<<". "<<menuList[i].Item<<"\t"<<menuList[i].Price<<endl; //printing menu items and prices from menulist
}
do
{
cout<<endl<<"Enter the number of Item you want to order (0 for exit)"<<endl; //asking for item to order
cin>>choice;
if(choice!=0) //if user doesn't want to exit
{ cout<<"How much do you want the "<<menuList[choice-1].Item<<endl; //asking for the quantity of item
cin>>count;
menuList[choice-1].Count=count; //storing the quantity in the count
}else if(choice>8) //if choice is not in the list
cout<<"Enter a valid Item"<<endl;
}while(choice!=0); //continue until user doesn't press 0
}
void printCheck()
{
double total=0,tax,due;
ofstream file("bill.txt"); //opening file for printing bill
cout<<"-----------------------------"<<endl; //wrting on console
cout<<"---------Your Bill---------"<<endl;
file<<"-----------------------------"<<endl; //wrinting in file
file<<"---------Your Bill---------"<<endl;
for(int i=0;i<8;i++)
{
if(menuList[i].Count!=0) //if the count of ith elemnt of menulist is not zero then it means the user has ordered that item
{
cout<<menuList[i].Item<<"\t"<<menuList[i].Count<<"\t$"<<menuList[i].Price<<endl; //printing orders on console
file<<menuList[i].Item<<"\t"<<menuList[i].Count<<"\t$"<<menuList[i].Price<<endl; //printing orders in file
}
total=total+menuList[i].Price*menuList[i].Count; //storing the total price of ordered items
}
tax=total*5/100; //calculating the tax
due=total+tax; //calculating the amount due
//printing the total ,tax,amount due on console
cout<<"------------------------------"<<endl;
cout<<"Amount Total:\t"<<"$"<<total<<endl;
cout<<"Tax:\t\t"<<"$"<<tax<<endl;
cout<<"Amount Due :\t"<<"$"<<due<<endl;
cout<<"------------------------------"<<endl;
//printing the total ,tax,amount due in file
file<<"------------------------------"<<endl;
file<<"Amount Total:\t\t"<<"$"<<total<<endl;
file<<"Tax:\t\t\t\t"<<"$"<<tax<<endl;
file<<"Amount Due :\t\t"<<"$"<<due<<endl;
file<<"------------------------------"<<endl;
file.close(); //closing file
}
int main()
{
getData(); //loading the menu into menulist
showMenu(); //showing menu to user and getting orders
printCheck(); //calculating total and amount due and printing the bill on console and file
return 0;
}
menu.txt
Plain Egg $1.45
Bacon and Egg $2.45
Muffin $0.99
French Toast $1.99
Fruit Basket $2.49
Cereal $0.69
Coffee $0.50
Tea $0.75
**********************************************Output**************************************************
Console
Output file
Program