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

I need to create a LunchOrder application that prompts the user for the number o

ID: 3544943 • Letter: I

Question


I need to create a LunchOrder application that prompts the user for the number of hamburgers, salads, French fries, and sodas and then displays the total for the order.  The LunchOrder application should include a Food object with a constructor that accepts the price, fat, carbs, and fiber for an item.  Food method should return the price of the item and return the fat, carbohydrates, and fiber.  Use the chart below for food prices and nutrition information:


             Item                             Price           Fat(g)                    Carbs(g)           Fiber(g)
            Hamburger                  $1.85              9                           33                      1
            Salad                           $2.00               1                           11                     5
            French fries                 $1.30             11                           36                     4
            Soda                             $0.95              0                           38                      0

Application output should look similar to:

Enter number of hamburgers:   3
Each hamburger has 9.0g of fat, 33.0g of carbs, and 1.0g of fiber.

Enter number of salads:  4
Each salad has 1.0g of fat, 11.0g of carbs, and 5.0g of fiber.

Enter number of French fries:   2
French fries have 11.0g of fat, 36.0g of carbs, 4.0g of fiber.

Enter number of sodas:  5
Each soda has 0.0g of fat, 38.0g of carbs, 0.0g of fiber.

Your order comes to:  $20.90

Explanation / Answer

Working proof : http://ideone.com/2zgLF6

#include <iostream>

using namespace std;

class food

{

public:

string item[4];

double price[4],fat[4],carbs[4],fiber[4];

food()

{

item[0]="Hamburger";

item[1]="Salad";

item[2]="French fries";

item[3]="Soda";

}

// member function

public :

double getDetail(string ip);

void setfood(string it,double p,double f, double c, double fb);

};

void food::setfood(string it,double p,double f, double c, double fb)

{

int i;

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

{

if(item[i].compare(it)==0)

break;

}

price[i]=p;

fat[i]=f;

carbs[i]=c;

fiber[i]=fb;

}

double food::getDetail(string ip)

{

int i;

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

{

if(item[i].compare(ip)==0)

break;

}

cout<<"Each "<<item[i]<<" has "<<fat[i]<<"g of fat, "<<carbs[i]<<"g of carbs, and "<<fiber[i]<<"g of fiber"<<endl;

return price[i];

}


int main()

{

double order=0,n,price;

food user;

user.setfood("Hamburger",1.85,9,33,1);

user.setfood("Salad",2.00 ,1 ,11 ,5);

user.setfood("French fries", 1.30, 11, 36 ,4);

user.setfood("Soda" ,0.95, 0 ,38, 0);


cout<<"Enter number of hamburgers: "<<endl;

price=user.getDetail("Hamburger");

cin>>n;

order+=price*n;

cout<<"Enter number of Salad: "<<endl;

price=user.getDetail("Salad");

cin>>n;

order+=price*n;

cout<<"Enter number of French fries: "<<endl;

price=user.getDetail("French fries");

cin>>n;

order+=price*n;

cout<<"Enter number of Soda: "<<endl;

price=user.getDetail("Soda");

cin>>n;

order+=price*n;

cout<<"Your Order is :"<<order<<endl;

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