Computer Programming Lab Assignment 2

LAB ASSIGNMENT NO. 02
Task1:

1.      Json opened a coffee shop at the beach and sells coffee in three sizes: small (9oz) , medium(12oz), and large(15oz). the cost of one small cup is $1.75, one medium cup is $1.90, and one large cup is $2.00. write a menu driven program that will make the coffee shop operational. Your program should allow the user to do the following:

a.       Buy coffee in any size and in any number of cups.
b.      At any time show the total number of cups of each size sold.
c.       At anytime show the total amount of coffee sold.
d.      At anytime show the total money made.

Your program should consist of atleast the following functions:
                                i.            A function to show the user how to use program.
                              ii.            A function to sell coffee
                            iii.            A function to show number of cups of each size sold.
                            iv.            A function to show the total amount of coffee sold.
                              v.            A function to show the total money made.

Your program should not use any global variables and special values such as coffee cup sizes and cost of a coffee cup must be declared as named constants.
Source Code:#include <iostream>

#include <iomanip>
using namespace std;
//User Define Functions
//First Function How To Use Program
void MenuOfCoffeShop()
{
    cout<<setw(60)<<setfill('=')<<"="<<endl;
     cout<<"          Jason Coffee Shop "<<endl;
cout<<" 1: Buy Coffee "<<endl;
cout<<"  2: Display Total Number OF Cup Sold By Size"<<endl;
cout<<" 3: Display Total Amount Of Coffee Sold "<<endl;
cout<<" 4: Display Total Money Made"<<endl;
cout<<" 0: Exit"<<endl;
cout<<setw(60)<<setfill('=')<<"="<<endl;

}
//Second Function Order
int SellCoffee(int&x,int&y,int&z,float &TotalMoneySmall,float& TotalMoneylarge,float&TotalMoneyMedium )
{
char Size,Ch;//Ch mean Choice you want to order or not
int Num; //Cup Of Cofee You Want
float CostSmallCup=1.75, CostMedCup=1.90, CostLargCup=2;
cout<<setw(60)<<setfill('=')<<"="<<endl;
    cout<<"Do You Want To Buy Coffee?('y' for Yes and 'n' For No)"<<endl;
cin>>Ch;
while(Ch!='n')
{
    cout<<setw(60)<<setfill('=')<<"="<<endl;
cout<<"Enter Size Of Coffee \n 'S' or 's' for Small \n 'M' or 'm' for Medium \n 'L' or 'l' for Large "<<endl;
cin>>Size;

if(Size=='s'||Size=='S')
{
    cout<<setw(60)<<setfill('=')<<"="<<endl;
   cout<<"Enter Cups Of Coffee"<<endl;
cin>>Num;
TotalMoneySmall=TotalMoneySmall+(CostSmallCup*Num);
x=x+Num;

}
else if(Size=='M'||Size=='m')
{cout<<setw(60)<<setfill('=')<<"="<<endl;
cout<<"Enter Cups Of Coffee"<<endl;
cin>>Num;
y=y+Num;
TotalMoneyMedium=(CostMedCup*Num)+TotalMoneyMedium;

}
else if(Size=='L'||Size=='l')
{cout<<setw(60)<<setfill('=')<<"="<<endl;
cout<<"Enter Cups of Coffee"<<endl;
cin>>Num;
TotalMoneylarge=(CostLargCup*Num)+TotalMoneylarge;
z=z+Num;
}
cout<<setw(60)<<setfill('=')<<"="<<endl;
cout<<"Do You Want To Buy Coffee?('y' for Yes and 'n' For No)"<<endl;
cin>>Ch;


}

}
//Third Function Number Of Cups Each Size Sold
void NumCupSold(int s,int m,int l)
{
int TotalCupSold=s+m+l;
cout<<setw(60)<<setfill('=')<<"="<<endl;
cout<<"Number Of Small Cups Sold are: "<<s<<endl;
cout<<setw(60)<<setfill('=')<<"="<<endl;
cout<<"Number Of Medium Cups Sold are: "<<m<<endl;
cout<<setw(60)<<setfill('=')<<"="<<endl;
cout<<"Number Of Large Cups Sold are: "<<l<<endl;
cout<<setw(60)<<setfill('=')<<"="<<endl;
cout<<"Total Number Of Cups Are Sold are: "<<TotalCupSold<<endl;
cout<<setw(60)<<setfill('=')<<"="<<endl;
}
//fourth Function total amount of coffee sold
void TAmntCofSold(int s,int m,int l)
{
int small=9, medium =12, large=5;//small,medium,large are amount of coffee in each cup
int TOtalAmntCoffeeSold=s*small+medium*m+l*large;
cout<<setw(60)<<setfill('=')<<"="<<endl;
cout<<"Total Amount of Coffee Sold is "<<TOtalAmntCoffeeSold<<"(oz)"<<endl;
}
//fifth Function Total Money Made
void TotalMoneyMade(float tm,float tsm,float tmm,float tlm)
{
// float TotalMoneySmall,TOtalMoneyMedium,TotalMoneyLarge;

tm=tsm+tmm+tlm;
cout<<setw(60)<<setfill('=')<<"="<<endl;
cout<<"Total Money: "<<tm<<"$"<<endl;
}

int main()
{
char SizeOfCoffee;
float CostSmallCup=1.75, CostMedCup=1.90, CostLargCup=2,TotalAmountCofSold;
int Choice, NumSmallCup, NumMedCup,NumLargCup, SmallCupsold=0,MedCupSold,LargCupSold=0,s=0,m=0,l=0,TotalCupSold,Num;
  float TotalAmount,TotalMoneySmall,TOtalMoneyMedium,TotalMoneyLarge;


do
{

MenuOfCoffeShop();
cout<<"enter Choice ";
cin>>Choice;

//choice is for sell coffe
if (Choice==1)
{
SellCoffee(s,m,l,TotalMoneySmall,TOtalMoneyMedium,TotalMoneyLarge);
}
//choice 2 is for num of cup sold by size
else if(Choice==2)
{
NumCupSold(s,m,l);                    //Number Of Cup Sold Size
}
//total amount of coffee sold
else if(Choice==3)
{
TAmntCofSold(s,m,l);
}
//total money made
else if(Choice==4)
{
TotalMoneyMade(TotalAmount,TotalMoneySmall,TOtalMoneyMedium,TotalMoneyLarge);
}
else if(Choice==0)
{
cout<<endl;
}
else
{
cout<<"Invalid "<<endl;
}

   } while(Choice!=0);

//   system("pause");
  return 0;

}




2.      (Airline Seating Assignment) write a program that can be used to assign seats for a commercial airplane. The airplane has 13 rows, with 6 seats in each row. Row 1 and 2 are first class, row 3 through 7 are business class, and row 8 through 13 are economy class. Your program must prompt the user to enter the following information:
a.      Ticket type (first class , business class ,or economy class).
b.      Desired seat
Output the seating planin the following form:


A
B
C
D
E
F
Row 1
*
*
X
*
X
X
Row 2
*
X
*
X
*
X
Row 3
*
*
X
X
*
X
Row 4
X
*
X
*
X
X
Row 5
*
X
*
X
*
*
Row 6
*
X
*
*
*
X
Row 7
X
*
*
*
X
X
Row 8
*
X
*
X
X
*
Row 9
X
*
X
X
*
X
Row 10
*
X
*
X
X
X
Row 11
*
*
X
*
X
*
Row 12
*
*
X
X
*
X
Row 13
*
*
*
*
X
*

Here , * indicates the seat is available; X indicates the seat is occupied. Make a menue driven program; show the user’s choices and allow the user to make appropriate choices. 
Source Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int r,c;// r for row and c for column
char bb[14][7];
char Class;
cout<<setw(60)<<setfill('*')<<"*"<<endl;
// Before Booking * showing seats are available
cout<<"         A        B        C        D        E        F"<<endl;
for(int i=1;i<14;i++)
{
cout<<"Row"<<i<<"     ";
for(int j=1;j<7;j++)

{
bb[i][j]='*';
cout<<bb[i][j]<<"        ";
}
cout<<endl;
}
//loop for booking
do
{
    cout<<setw(60)<<setfill('*')<<"*"<<endl;
cout<<"'f' for First Class \n 'e' For Economy Class \n 'b' For Business Class \n '0' for End Booking \n";
cout<<setw(60)<<setfill('*')<<"*"<<endl;
cin>>Class;
//if user enter first class
if(Class=='f')
{cout<<setw(60)<<setfill('*')<<"*"<<endl;
    cout<<"ENTER Row ";
cin>>r;
cout<<setw(60)<<setfill('*')<<"*"<<endl;
cout<<"Enter Column ";
cin>>c;
if(r<3&&c<7)
{
if(bb[r][c]=='*')
{
bb[r][c]='X';
}
else if(bb[r][c]='X')
                 {cout<<setw(60)<<setfill('*')<<"*"<<endl;
cout<<"seat is reserved"<<endl;

                 }
}
if(r>2)
                cout<<setw(60)<<setfill('*')<<"*"<<endl;
cout<<"Invalid class"<<endl;



}
//if user enter business class
else if(Class=='b')
    {
        cout<<setw(60)<<setfill('*')<<"*"<<endl;
        cout<<"ENTER Row ";
    cin>>r;
    cout<<setw(60)<<setfill('*')<<"*"<<endl;
    cout<<"Enter Column ";

    cin>>c;
    if(r>2&&r<8&&c<7)
{
if(bb[r][c]=='*')
{
bb[r][c]='X';
}
if(bb[r][c]='X')
                    cout<<setw(60)<<setfill('*')<<"*"<<endl;
cout<<"seat is reserved"<<endl;
}
if(r>7)
                cout<<setw(60)<<setfill('*')<<"*"<<endl;
cout<<"Invalid class"<<endl;
    //bb[r][c]='X';

}
//if user enter economy class
else if(Class=='e')
{
    cout<<setw(60)<<setfill('*')<<"*"<<endl;
    cout<<"ENTER Row";
cin>>r;
cout<<setw(50)<<setfill('*')<<"*"<<endl;
cout<<"Enter Column";

cin>>c;
if(r>7&&r<14&&c<7)
{
if(bb[r][c]=='*')
{
bb[r][c]='X';
}
if(bb[r][c]='X')
                    {cout<<setw(60)<<setfill('*')<<"*"<<endl;
cout<<"seat is reserved"<<endl;}
}
else if (r>13)
                cout<<setw(60)<<setfill('*')<<"*"<<endl;
cout<<"Invalid class"<<endl;


//bb[r][c]='X';
}
else
{cout<<setw(60)<<setfill('*')<<"*"<<endl;
cout<<"Invalid"<<endl;
}
cout<<setw(60)<<setfill('*')<<"*"<<endl;
cout<<"         A        B        C        D        E        F"<<endl;
for(int i=1;i<14;i++)
{
cout<<"Row"<<i<<"     ";
for(int j=1;j<7;j++)

{

cout<<bb[i][j]<<"        ";
}
cout<<endl;
}
cout<<setw(60)<<setfill('*')<<"*"<<endl;
}while(Class!=0);

//system("pause");
return 0;

}

Comments

  1. kindly write its flowchart also ??????

    ReplyDelete

Post a Comment

Popular posts from this blog

Computer Programming Lab 5

Computer Programming lab 11

Computer Programming Lab 4