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

The program runs smooth but I need to put the menu.txt file in my program #inclu

ID: 664201 • Letter: T

Question

The program runs smooth but I need to put the menu.txt file in my program

#include<iostream>

#include<string>

#include<iomanip>

using namespace std;

//Define structs as global type

struct menuItemType

{

string menuItem;

double menuPrice;

};

// Function declarations

void getdata(menuItemType[], menuItemType[], int&);

void showMenu(menuItemType[], int);

void printCheck(menuItemType[], int);

//main method

int main()

{

int items = 0;

menuItemType menuList[] = { "Cheese Omelette", 3.99,

"Omelette In a Bag", 2.79,

"40-Second Omelette", 4.99,

"Denver Ometette", 5.99,

"Green Eggs and Ham Omelette", 14.99,

"Spanish Omelette", 3.59,

"French Potato Omelette", 6.97,

"Greg's Ham & Cheese Omelette", 2.99,

"Cheesy Chicken Omelette", 6.56,

"Western Omelette", 11.99,

"BLT Omelette", 5.99,

"Super Simple Omelette", 0.99,

"Hawaiian Omelette", 11.99,

"Spam Omelette", 1.99,

"Bacon Cheddar & Chives Omelette", 11.99,

"Smoked Beef Omelette", 9.99,

"Cheese And Herb Souffle Omelette", 6.99,

"Campfire Omelette", 5.99,

"Omelette Savoyarde(French)", 23.99,

"Omelette On a Stick", 4.99,

"Neapolitan Omelette", 7.99,

"German Omelette With Bacon", 8.99,

"The 123 Omelette", 2.99,

"Jelly Omelette", 1.99,

"Coffee", 0.79,

};

menuItemType order[10];

cout << "Welcome to Johnny's Restaurant menu Item price ";

showMenu(menuList, 25);

getdata(menuList, order, items);

printCheck(order, items);

//Pause the system for a while

system("pause");

return 0;

}

//method definition of "printCheck"

void printCheck(menuItemType order[], int items)

{

//Declare variables

int i;

double total = 0, tax;

cout << "Your Check Ordered Items Item price ";

showMenu(order, items);

for (i = 0; i<items; i++)

total += order[i].menuPrice;

cout << " Items cost total " << "$" << setprecision(2) << fixed << total << endl;

tax = total*.05;

cout << "Tax " << "$" << setprecision(2) << fixed << tax << endl;

cout << "Amount Due " << "$" << setprecision(2) << fixed << total + tax << endl;

}

//method definition of "getdata"

void getdata(menuItemType menu[], menuItemType order[], int& items)

{

char yesno = 'Y';

int n;

while (toupper(yesno) == 'Y')

{

cout << "Enter your order item number: ";

cin >> n;

while (n<1 || n>25)

{

cout << "invalid item number ";

cout << "Enter your order item number: ";

cin >> n;

}

order[items].menuItem = menu[n - 1].menuItem;

order[items].menuPrice = menu[n - 1].menuPrice;

items++;

cout << "Would you like continue?(y/n)? ";

cin >> yesno;

}

}

//Method definition of "showMenu"

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;

}

Explanation / Answer

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <cstdlib>

using namespace std;

const double tax_rate = 0.05;

struct menuItemType
{
string ItemName;
double ItemPrice;
};

void getData(ifstream &in, menuItemType menuList[]);
void showMenu(menuItemType menuList[]);
void printCheck(menuItemType menuList[]);


int main()
{
menuItemType menuList[10];
menuList[10].ItemName;
menuList[10].ItemPrice;

ifstream in;
in.open("Menu.txt");
cout << "Welcome to Johnny's Breakfast Diner!" << endl;

getData(in,menuList);
showMenu(menuList);

    return 0;
}

void getData(ifstream &in, menuItemType menuList[])
{
int i = 0;
while (!in.eof())
{
    in >> menuList[i].ItemName >> menuList[i].ItemPrice;
    i++;
}

}

void showMenu(menuItemType menuList[])
{

int j = 0;
char answ;

cout << fixed << setprecision(2);
cout << "Would you like to take a look at our menu? (Y/N)";
cin >> answ;
if (answ == 'Y' || answ == 'y')
{
    cout << left << setw(10) << "Item#" << left << setw(15) << "Item" << left     << setw(18) << "Price" << endl;
    do {
    {
        cout << left << setw(8) << j << " " << left << setw(15) << menuList[j].ItemName << " " << "$" << menuList[j].ItemPrice << endl;
        j++;
    }
} while (j < 8);
    printCheck(menuList);

}

else if (answ == 'N' || answ == 'n')
{
    system("cls");
    cout << "Have a good day!" << endl;
}

}

void printCheck(menuItemType menuList[])
{
char answ;
int choice;
bool menu = true;
double subtotal = 0;
double tax = (subtotal * tax_rate);
double total = (tax + subtotal);
cout << "Would like to place your order (Y/N)";
cin >> answ;

if (answ == 'Y' || answ == 'y')
{
    cout << "Please enter the number of the item, 8 to finish order:";

    do {
        cin >> choice;

        if (choice == 0)
        {
        cout << menuList[0].ItemName << " " << "$" << menuList[0].ItemPrice << endl;
        subtotal = subtotal + menuList[0].ItemPrice; \ for some reason here it doesn't store the prices have no idea why
        }

        else if (choice == 1)
        {
            cout << menuList[1].ItemName << " " << "$" << menuList[1].ItemPrice << endl;
            subtotal = subtotal + menuList[1].ItemPrice;
        }

        else if (choice == 2)
        {
            cout << menuList[2].ItemName << " " << "$" << menuList[2].ItemPrice << endl;
            subtotal = subtotal + menuList[2].ItemPrice;
        }

        else if (choice == 3)
        {
            cout << menuList[3].ItemName << " " << "$" << menuList[3].ItemPrice << endl;
            subtotal = subtotal + menuList[3].ItemPrice;
        }

        else if (choice == 4)
        {
            cout << menuList[4].ItemName << " " << "$" << menuList[4].ItemPrice << endl;
            subtotal = subtotal + menuList[4].ItemPrice;
        }

        else if (choice == 5)
        {
            cout << menuList[5].ItemName << " " << "$" << menuList[5].ItemPrice << endl;
            subtotal = subtotal + menuList[5].ItemPrice;
        }

        else if (choice == 6)
        {
            cout << menuList[6].ItemName << " " << "$" << menuList[6].ItemPrice << endl;
            subtotal = subtotal + menuList[6].ItemPrice;
        }

        else if (choice == 7)
        {
            cout << menuList[7].ItemName << " " << "$" << menuList[7].ItemPrice << endl;
            subtotal = subtotal + menuList[7].ItemPrice;
        }

        else if (choice == 8)
        {
            break;
        }
    }while(menu = true);

cout << "Taxes" << "$" << tax << endl;
cout << "Amount Due" << "$" << total << endl;

}

else if (answ == 'N' || answ == 'n')
{
    system("cls");
    cout << "Ok, maybe I can help you at a later time." << endl;
}


}