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

Create an input file named menu.txt that contains the following breakfast items.

ID: 3632541 • Letter: C

Question

Create an input file named menu.txt that contains the following breakfast items. The input file contains the menu item on one line, followed by the price on a second line.

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

Project Requirements:
Create a struct, menuItemType with three components: menuItem of the type string, menuPrice of the type double, selected of the type bool.
struct menuItemType
{
string menuItem;
double menuPrice;
bool selected;
};

Declare an array of these structs.
menuItemType menu[20];

You will need to write at least three functions:

getdata – will read the data from the input file
store menuItem from the file
store menuPrice from the file
set selected to false
Review the following code:
do
{
getline(infile, menu[i].menuItem);
infile >> menu[i].menuPrice;
infile.get(); // to get of the eol character after the price
… // set the selected member to false
} while (infile);


showmenu – will display a list of the available menu choices

Menu Choices
1. Plain Egg $1.45
2. Bacon and Egg $2.45
3. Muffin $0.99
4. French Toast $1.99
5. Fruit Basket $2.49
6. Cereal $0.69
7. Coffee $0.50
8. Tea $0.75
9. Finished Ordering

You will then prompt the user to enter their choice and update the associated struct member selected to be true. This process should continue until the user enters a sentinel value to end their choices.

printcheck – will display a check listing the items purchased, their individual cost, the total amount, the tax of 8% and the total amount due.

Your Name Restaurant

Plain Egg $1.45
Muffin $0.99
Coffee $0.50

Total $2.94
Tax .24
Total Due $3.18

Notes about String Alignment:
Combining strings and numeric data in a cout statement can be tricky to line up. You may need to change between left and right alignment to get the information to line up.
cout << “hello” << setw(5) << 10 << endl;
Displays: hello***10

cout << setw(10) << “hello” << setw(5) << 10 << endl;
Displays: *****hello***10

cout << setw(10) << left << “hello” << setw(5) << 10 << endl;
Displays: hello*****10***

cout << setw(10) << left << “hello” << setw(5) << right << 10 << endl;
Displays: hello********10

Explanation / Answer

please rate - thanks

#include<iostream>
#include<string>
#include<iomanip>
#include <fstream>
using namespace std;
struct menuItemType
{string menuItem;
double menuPrice;  
bool selected;
};
int getdata(menuItemType[]);
void getOrder( menuItemType[],int);
void showMenu( menuItemType[],int);
void printCheck(menuItemType[],int );
int main()
{
int choices=0;
menuItemType menu[20];                         

cout<<"Welcome to my Restaurant My menu      Item      price ";
choices=getdata(menu);
getOrder(menu,choices);
printCheck(menu,choices);
system("pause");
return 0;
}
void printCheck(menuItemType order[],int items)
{int i;
double total=0,tax;
cout<<" Your Name Restaurant ";
for(i=0;i<items;i++)
     if(order[i].selected)
         {total+=order[i].menuPrice;
         cout<<setw(16)<<left<<order[i].menuItem<<"$"<<
               setprecision(2)<<fixed<<order[i].menuPrice<<endl;
     }
cout<<" Total    "<<"$"<<setprecision(2)<<fixed<<total<<endl;
tax=total*.08;
cout<<"Tax "<<"$"<<setprecision(2)<<fixed<<tax<<endl;
cout<<"Amount Due    "<<"$"<<setprecision(2)<<fixed<<total+tax<<endl;
}
int getdata(menuItemType menu[])
{ifstream infile;
int i=0;
   infile.open("menu.txt");           //open file
   if(infile.fail())             //is it ok?
       { cout<<"file did not open please check it ";
        system("pause");
        system("exit");
        }
do
{
getline(infile, menu[i].menuItem);
infile >> menu[i].menuPrice;
infile.get(); // to get of the eol character after the price
menu[i].selected=false;
i++;
} while (infile);

infile.close();
return i-1;
}
void getOrder(menuItemType menu[],int choices)
{int n;
showMenu(menu,choices);
cout<<"Enter your order item number: ";
cin>>n;
while(n!=choices+1)
{
while(n<1||n>9)
    {cout<<"invalid item number ";
     cout<<"Enter order item number: ";
     cin>>n;
     }
menu[n-1].selected=true;
cout<<"Enter order item number: ";
cin>>n;
}
}
void showMenu(menuItemType a[],int n)
{int i;
    for(i=0;i<n;i++)
         {cout<<i+1<<". "<<setw(16)<<left<<a[i].menuItem<<"$"<<setprecision(2)<<fixed<<a[i].menuPrice<<endl;
          }
    cout<<i+1<<". Finished Ordering ";
}

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