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

Use this code to create multiple functions. #include<iostream> #include<iomanip>

ID: 3693698 • Letter: U

Question


Use this code to create multiple functions.


#include<iostream>
#include<iomanip>
#include<fstream>


using namespace std;


int main()


{
cout << fixed << showpoint << setprecision(2);

ofstream outFile;
outFile.open("Feras's.txt");
outFile << "..Skinny Feras's Restaurant .. " << endl;




int choise=10, quantity;
float paid, SubTotal=0, Tax = .10, Total, RM, more;


while(choise!=0)
{
system("cls");
cout << " **Welcome To Skinny Alsaif Restaurant Lol**" << endl;
cout << " What would you like to have?" << endl;
cout << "1. Burger." << endl;
cout << "2. Pizza." << endl;
cout << "3. Rize With Chickens." << endl;
cout << "4. Spaghetti." << endl;
cout << "5. Steak." << endl;
cout << "6. Apple pie." << endl;
cout << "7. Tea." << endl;
cout << "8. Coffee." << endl;
cout << "9. Salad." << endl;
cout << "10.Meat." << endl;
cout << "Subtotal: $" << SubTotal << endl;
cout << "Please Enter 0 whenever you are ready :)" << endl;
cout << "choise: ";
cin >> choise;


if (choise!=0)
{
cout << "Enter quantity: ";
cin >> quantity;


}
if(choise== 1)
SubTotal = SubTotal + (2.40 * quantity);
else if (choise == 2)
SubTotal = SubTotal + (5.99 * quantity);
else if (choise == 3 ||choise == 4)
SubTotal = SubTotal + (4.90 * quantity);
else if (choise == 5 || choise== 6 )
SubTotal = SubTotal + (6.79 * quantity);
else if (choise == 7 || choise== 8 )
SubTotal = SubTotal + (3.99 * quantity);
else if (choise == 9 || choise== 10 )
SubTotal = SubTotal + (7.50 * quantity);
}


system("cls");


cout << " *5SubTotal $" << SubTotal << endl;
cout << "*Tax $" << SubTotal * Tax << endl;
Total = SubTotal + (SubTotal * Tax);
cout << "*Total $" << SubTotal + (SubTotal * Tax) << endl;
cout << "*Enter Payment Amount $";
cin >> paid;


while(paid < Total)
{




system("cls");


cout << " *You did not paid enough" << endl;
cout << "*Amount paid $" << paid << " Total $" << Total << endl;
cout << "*Enter Payment Amount $";
cin >> more;
paid = paid + more;
}
if(paid >= Total)
RM = paid - Total;
outFile << "SubTotal $" << SubTotal << endl;
outFile << "Tax $" << Tax << endl;
outFile << "Total $" << Total << endl;
outFile << "Change due $" << paid - Total << endl;
cout << "*Change Due $" << RM << endl;
cout << " Have a Nice Day " << endl;


outFile.close();
system("pause");
return 0;
} Use your code from the menu system created back in March so that it uses multiple functions. You should create as many functions as possible for this assignment. In addition, I would like to see the usage of arrays in your program where appropriate. This is not required, but strongly encouraged.

Explanation / Answer

Here is the modularized code for you:

#include<iostream>
#include<iomanip>
#include<fstream>
using namespace std;
void displayMenu(float SubTotal)
{
system("cls");
cout << " **Welcome To Skinny Alsaif Restaurant Lol**" << endl;
cout << " What would you like to have?" << endl;
cout << "1. Burger." << endl;
cout << "2. Pizza." << endl;
cout << "3. Rize With Chickens." << endl;
cout << "4. Spaghetti." << endl;
cout << "5. Steak." << endl;
cout << "6. Apple pie." << endl;
cout << "7. Tea." << endl;
cout << "8. Coffee." << endl;
cout << "9. Salad." << endl;
cout << "10.Meat." << endl;
cout << "Subtotal: $" << SubTotal << endl;
}
int readChoise()
{
int choise;
cout << "Please Enter 0 whenever you are ready :)" << endl;
cout << "choise: ";
cin >> choise;
return choise;
}
float purchaseBurger(int q)
{
return 2.40 * q;
}
float purchasePizza(int q)
{
return 5.99 * q;
}
float purchaseRizeWithChickOrSpaghetti(int q)
{
return 4.90 * q;
}
float purchaseSteakOrApplePie(int q)
{
return 6.79 * q;
}
float purchaseTeaOrCoffee(int q)
{
return 3.99 * q;
}
float purchaseSaladOrMeat(int q)
{
return 7.50 * q;
}
float calculateSubtotalWithTax(float SubTotal, float Tax)
{
return SubTotal * Tax;
}
float calculateTotal(float SubTotal, float Tax)
{
return SubTotal + (SubTotal * Tax);
}
float readPayment(float Total)
{
float paid, more;
cin >> paid;
while(paid < Total)
{
system("cls");
cout << " *You did not paid enough" << endl;
cout << "*Amount paid $" << paid << " Total $" << Total << endl;
cout << "*Enter Payment Amount $";
cin >> more;
paid = paid + more;
}
return paid;
}
int main()
{
cout << fixed << showpoint << setprecision(2);
ofstream outFile;
outFile.open("Feras's.txt");
outFile << "..Skinny Feras's Restaurant .. " << endl;
int choise=10, quantity;
float paid, SubTotal=0, Tax = .10, Total, RM, more;
while(choise!=0)
{
displayMenu(SubTotal);
choise = readChoise();
if (choise!=0)
{
cout << "Enter quantity: ";
cin >> quantity;
}
if(choise== 1)
SubTotal = SubTotal + purchaseBurger(quantity);
else if (choise == 2)
SubTotal = SubTotal + purchasePizza(quantity);
else if (choise == 3 ||choise == 4)
SubTotal = SubTotal + purchaseRizeWithChickOrSpaghetti(quantity);
else if (choise == 5 || choise== 6 )
SubTotal = SubTotal + purchaseSteakOrApplePie(quantity);
else if (choise == 7 || choise== 8 )
SubTotal = SubTotal + purchaseTeaOrCoffee(quantity);
else if (choise == 9 || choise== 10 )
SubTotal = SubTotal + purchaseSaladOrMeat(quantity);
}
system("cls");
cout << " *5SubTotal $" << SubTotal << endl;
cout << "*Tax $" << calculateSubtotalWithTax(SubTotal, Tax) << endl;
Total = calculateTotal(SubTotal, Tax);
cout << "*Total $" << Total << endl;
cout << "*Enter Payment Amount $";
paid = readPayment(Total);
if(paid >= Total)
RM = paid - Total;
outFile << "SubTotal $" << SubTotal << endl;
outFile << "Tax $" << Tax << endl;
outFile << "Total $" << Total << endl;
outFile << "Change due $" << paid - Total << endl;
cout << "*Change Due $" << RM << endl;
cout << " Have a Nice Day " << endl;
outFile.close();
system("pause");
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