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

in C++ Jason opened a coffee shop selling coffee, cheese cakes, and coffee beans

ID: 3812463 • Letter: I

Question

in C++

Jason opened a coffee shop selling coffee, cheese cakes, and coffee beans. Coffee is sold at the shop in two sizes: small (9 oz, $1.5) and large (12 oz, $1.9). Cheese cakes cost $3 per slice. Coffee beans are sold with $0.6 per oz. Write a menu-driven program that will make the coffee shop operational. Your program should allow the user to do the following:

• Choose among coffee, cakes, or beans to purchase.
• Buy coffee in any size and in any number of cups.
• Buy cheese cakes in any number of slices.
• Buy coffee beans in any amount.
• At any time show the total number of cups of each size sold, total number of slices of cakes sold, and total amount of coffee beans sold.
• At any time show the total amount of coffee sold.
• At any time show the total money made.

Your program should consist of at least the following functions:

• a function to show the user how to use the program,
• a function to sell coffee,
• a function to sell cakes,
• a function to sell coffee beans,
• a function to show the number of cups of each size of coffee, the number of slices of cheese cakes, and the amount of coffee beans sold,
• a function to show the total amount of coffee sold, and
• a function to show the total money made.

Your program should not use any global variables. Special values such as coffee cup sizes and cost of a coffee cup must be declared as named constants.

Explanation / Answer

Program:-

#include<iostream>
#include<cstdlib>
using namespace std;
struct item           //giving items types in structure it is not declaration items declared in use_program() function below
{
       float money;
       int n9coffee;
       int n12coffee;
       int ncake;
       int nbeans;
};

item sell_coffee(item t)   //function for sell coffee
{
   int a,n;
   cout<<"Enter 1 for 9oz 2 for 12 oz"<<endl;           //choose type of coffee 9oz or 12oz
   cin>>a;
   while(a!=1&&a!=2)
   {
       cout<<"Invalid choice try again"<<endl;
       cin>>a;
   }
   cout<<"Enter how many Coffee you want to buy"<<endl;
   cin>>n;
   if(a==1)       //calculating money for 9oz coffee
   {
       t.n9coffee+=n;
       t.money+=(float)n*1.5;
   }
   else       //calculating money for 12oz coffee
   {
       t.n12coffee+=n;
       t.money+=(float)n*1.9;
   }
   return t;       //return the structure
}

item sell_cake(item t)       //function for sell cake
{
   int n;
   cout<<"Enter how many Cake Slices you want to buy"<<endl;
   cin>>n;
   t.ncake+=n;
   t.money+=(float)n*3;   //calculating money for cake
   return t;       //return the structure
}

item sell_coffee_beans(item t)       //function for sell coffee beans
{
   int n;
   cout<<"Enter how much oz's you want to buy"<<endl;
   cin>>n;
   t.nbeans+=n;
   t.money+=(float)n*0.6;       //calculating money for coffee beans
   return t;       //return the structure
}

void sold(item t)       //function for printing number of items sold
{
   cout<<"Number of sold Items"<<endl;
   cout<<"Coffee 9oz "<<t.n9coffee<<endl;       //printing coffee 9oz
   cout<<"Coffee 12oz "<<t.n12coffee<<endl;   //printing coffee 12oz
   cout<<"Chese Cake "<<t.ncake<<endl;       //printing cake
   cout<<"Coffee Beans "<<t.nbeans<<endl;       //printing coffee beans
}

void total_money(item t)   //function for money earned
{
   cout<<"Total Money earned is : "<<t.money<<endl;
}

void use_program()   //function for how to use of program
{
   int ch;
   item t;       //declaring structure item means that declaring all variables
   t.money=0;   //initilizing all items to 0 initially
   t.n9coffee=0;
   t.n12coffee=0;
   t.ncake=0;
   t.nbeans=0;
   while(1)
   {
       cout<<endl;
       cout<<"COFFEE shop MENU 1.Buy Coffee 2.Buy Cake 3.Buy Coffee Beans 4.Show total sold 5.Show total Money earned 6.Quit"<<endl;
       cout<<"Enter Your Choice"<<endl;
       cin>>ch;
       switch(ch)
       {
           case 1:t=sell_coffee(t);   //call for sell coffee
               break;
           case 2:t=sell_cake(t);       //call for sell cake
               break;
           case 3:t=sell_coffee_beans(t);   //call for sell coffee beans
               break;
           case 4:sold(t);       //call for items sold
               break;
           case 5:total_money(t);   //call for money earned
               break;
           case 6:exit(0);
           default: cout<<"Invalid Choice try again"<<endl;
       }
   }  
}

int main()
{
   use_program();   //call for use of program
   return 0;
}

Output:-

COFFEE shop MENU
1.Buy Coffee
2.Buy Cake
3.Buy Coffee Beans
4.Show total sold
5.Show total Money earned
6.Quit
Enter Your Choice
4
Number of sold Items
Coffee 9oz      0
Coffee 12oz     0
Chese Cake      0
Coffee Beans    0

COFFEE shop MENU
1.Buy Coffee
2.Buy Cake
3.Buy Coffee Beans
4.Show total sold
5.Show total Money earned
6.Quit
Enter Your Choice
5
Total Money earned is : 0

COFFEE shop MENU
1.Buy Coffee
2.Buy Cake
3.Buy Coffee Beans
4.Show total sold
5.Show total Money earned
6.Quit
Enter Your Choice
1
Enter 1 for 9oz 2 for 12 oz
1
Enter how many Coffee you want to buy
2

COFFEE shop MENU
1.Buy Coffee
2.Buy Cake
3.Buy Coffee Beans
4.Show total sold
5.Show total Money earned
6.Quit
Enter Your Choice
1
Enter 1 for 9oz 2 for 12 oz
2
Enter how many Coffee you want to buy
1

COFFEE shop MENU
1.Buy Coffee
2.Buy Cake
3.Buy Coffee Beans
4.Show total sold
5.Show total Money earned
6.Quit
Enter Your Choice
2
Enter how many Cake Slices you want to buy
5

COFFEE shop MENU
1.Buy Coffee
2.Buy Cake
3.Buy Coffee Beans
4.Show total sold
5.Show total Money earned
6.Quit
Enter Your Choice
3
Enter how much oz's you want to buy
10

COFFEE shop MENU
1.Buy Coffee
2.Buy Cake
3.Buy Coffee Beans
4.Show total sold
5.Show total Money earned
6.Quit
Enter Your Choice
4
Number of sold Items
Coffee 9oz      2
Coffee 12oz     1
Chese Cake      5
Coffee Beans    10

COFFEE shop MENU
1.Buy Coffee
2.Buy Cake
3.Buy Coffee Beans
4.Show total sold
5.Show total Money earned
6.Quit
Enter Your Choice
5
Total Money earned is : 25.9

COFFEE shop MENU
1.Buy Coffee
2.Buy Cake
3.Buy Coffee Beans
4.Show total sold
5.Show total Money earned
6.Quit
Enter Your Choice
6


Process exited normally.
Press any key to continue . . .