Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Foundtional Programing I . C++. Baisac Program. #include<iostream> #include<stri

ID: 3764865 • Letter: F

Question

Foundtional Programing I . C++.

Baisac Program.

#include<iostream>
#include<string>
#include<fstream>

#include<iomanip>

Menu Project

Using the attached program as an example, class notes and examples shown in class, create a menu system that does the following:

Create a series of parallel arrays for common menu categories in restaurants (appetizers, main course, desserts, and drinks

Create 4 input file variables, 4 input files, and 4 counter variables for reading in data for each of the categories

Using while loops to read in the data from each file and store the data into the arrays, be sure to check for files that cannot be opened

Create a main menu with user options for each category, include a subtotal value within the menu

When a user selects a category, the data stored within the array for that category is displayed on the screen

Allow the user to select the item from the category, and then update the subtotal for the current amount owed based on the item's price

While the user selects items, use another array to store the item purchased (name and price)

Allow the user to move between the main menu and category menus until the user has finished ordering items

When finished, display a receipt for the user with an itemized list of food/drink items purchased with names and prices for each

Display a subtotal, tax, and total for the user's purchase. Use 10% tax for easy math

Prompt the user for amount of money entered, then determine change due to the customer and display the amount on the screen

For full points, you MUST use functions. You may choose the code to move into functions. You will have at least 3 functions in your program for full points.

This Format >>

#include<iostream>

#include<string>

#include<fstream>

#include<iomanip>

using namespace std;

void testFile(ifstream &iFile, string fileName)

{

   if(!iFile.is_open())

   {

       cout << fileName << " file did not open" << endl;

       system("pause");

       exit(1);

   }

}

int main()

{

ifstream iFile;

  

  

  

   while(!appInfo.eof())

   {

       getline(appInfo, appName[appCounter]);

       appInfo >> appPrice[appCounter];

       appCounter++;

       appInfo.ignore();

   }

while(!drinkInfo.eof())

   {

getline(drinkInfo, drinkName[appCounter]);

       drinkInfo >> drinkPrice[drinkCounter];

       drinkCounter++;

       drinkInfo.ignore();

   }

system("pause");

return 0;

}

Explanation / Answer

#include <bits/stdc++.h>
using namespace std;

void options(){
cout<<"select category:"<<endl;
cout<<endl;
cout<<"1 for appetizers"<<endl;
cout<<"2 for main_course"<<endl;
cout<<"3 for deserts"<<endl;
cout<<"4 for drinks"<<endl;
cout<<"5 to exit"<<endl;
cout<<"Enter your choice:"<<endl;

}

void print_appetizers(pair<string,float> * appetizers,int appetizersc){
cout<<"appetizers: "<<endl;
cout<<endl;
for(int i=0;i<appetizersc;i++){
cout<<i+1<<" ";
cout<<appetizers[i].first<<" "<<appetizers[i].second<<endl;
}
cout<<"0 to select other categories:"<<endl;
cout<<"Enter your choice:"<<endl;
}

void print_main_course(pair<string,float> * main_course,int main_coursec){
cout<<"main_course: "<<endl;
cout<<endl;
for(int i=0;i<main_coursec;i++){
cout<<i+1<<" ";
cout<<main_course[i].first<<" "<<main_course[i].second<<endl;
}
cout<<"0 to select other categories:"<<endl;
cout<<"Enter your choice:"<<endl;
}

void print_deserts(pair<string,float> * deserts,int desertsc){
cout<<"deserts: "<<endl;
cout<<endl;
for(int i=0;i<desertsc;i++){
cout<<i+1<<" ";
cout<<deserts[i].first<<" "<<deserts[i].second<<endl;
}
cout<<"0 to select other categories:"<<endl;
cout<<"Enter your choice:"<<endl;

}

void print_drinks(pair<string,float> * drinks,int drinksc){
cout<<"drinks: "<<endl;
cout<<endl;
for(int i=0;i<drinksc;i++){
cout<<i+1<<" ";
cout<<drinks[i].first<<" "<<drinks[i].second<<endl;
}
cout<<"0 to select other categories:"<<endl;
cout<<"Enter your choice:"<<endl;
}


int main(){
ifstream appetizersf,main_coursef,desertsf,drinksf;
appetizersf.open("appetizers.txt");
main_coursef.open("main_course.txt");
desertsf.open("deserts.txt");
drinksf.open("drinks.txt");
pair<string,float> * appetizers;
pair<string,float> * main_course;
pair<string,float> * deserts;
pair<string,float> * drinks;
int appetizersc,main_coursec,desertsc,drinksc;
appetizersf>>appetizersc;
main_coursef>>main_coursec;
desertsf>>desertsc;
drinksf>>drinksc;
appetizers=new pair<string,float>[appetizersc];
main_course=new pair<string,float>[main_coursec];
deserts=new pair<string,float>[desertsc];
drinks=new pair<string,float>[drinksc];
string s;
float n;
int count=0;
while(appetizersc>count){
pair<string,float> p;
appetizersf>>s>>n;
p.first=s;
p.second=n;
appetizers[count]=p;
count++;
}
count=0;
while(main_coursec>count){
pair<string,float> p;
main_coursef>>s>>n;
p.first=s;
p.second=n;
main_course[count]=p;
count++;
  
}
count=0;
while(desertsc>count){
pair<string,float> p;
desertsf>>s>>n;
p.first=s;
p.second=n;
deserts[count]=p;
count++;
}
count=0;
while(drinksc>count){
pair<string,float> p;
drinksf>>s>>n;
p.first=s;
p.second=n;
drinks[count]=p;
count++;
}
int itemcount=0;
float subtotal=0.0;
pair<string,float> arr[100];
int ordercomp=0;
int catnum;
while(!ordercomp){
options();
cin>>catnum;
if(catnum==5){
ordercomp=1;
}
else{
int itemnum;
if(catnum==1){
print_appetizers(appetizers,appetizersc);
cin>>itemnum;
if(itemnum!=0){
if(itemnum>0 && itemnum<=appetizersc){
arr[itemcount]=appetizers[itemnum-1];
subtotal+=arr[itemcount].second;
cout<<"subtotal = "<<(subtotal*11)/10<<endl;
itemcount++;
}
else{
cout<<"Invalid entry"<<endl;
}
}
}
else if(catnum==2){
print_main_course(main_course,main_coursec);
cin>>itemnum;
if(itemnum!=0){
if(itemnum>0 && itemnum<=main_coursec){
arr[itemcount]=main_course[itemnum-1];
subtotal+=arr[itemcount].second;
cout<<"subtotal = "<<(subtotal*11)/10<<endl;
itemcount++;
}
else{
cout<<"Invalid entry"<<endl;
}
}
}
else if(catnum==3){
print_deserts(deserts,desertsc);
cin>>itemnum;
if(itemnum!=0){
if(itemnum>0 && itemnum<=desertsc){
arr[itemcount]=deserts[itemnum-1];
subtotal+=arr[itemcount].second;
cout<<"subtotal = "<<(subtotal*11)/10<<endl;
itemcount++;
}
else{
cout<<"Invalid entry"<<endl;
}
}
}
else{
print_drinks(drinks,drinksc);
cin>>itemnum;
if(itemnum!=0){
if(itemnum>0 && itemnum<=drinksc){
arr[itemcount]=drinks[itemnum-1];
subtotal+=arr[itemcount].second;
cout<<"subtotal = "<<(subtotal*11)/10<<endl;
itemcount++;
}
else{
cout<<"Invalid entry"<<endl;
}
}

}

}

}
cout<<"Your final order: "<<endl;
for(int i=0;i<itemcount;i++){
cout<<arr[i].first<<" "<<arr[i].second<<endl;
}
cout<<endl;
cout<<"total amountto be paid including tax = "<<(subtotal*11)/10<<endl;
cout<<endl;
float amount=(subtotal*11)/10;
if(amount==0){
cout<<"You haven't ordered anything."<<endl;
}
else{
int transaction=0;
float moneypaid,change;
while(!transaction){
cout<<"Enter valid amount to confirm order: ";
cin>>moneypaid;
if(moneypaid>=(subtotal*11)/10){
change=moneypaid-(subtotal*11)/10;
cout<<"Order confirmed"<<endl;
cout<<"change = "<<change<<endl;
transaction=1;
}
}
}
  

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote