Entry: C++ Programming Monday, March 16, 2009



#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
void printMenu(float value_meal[4][3]);
void getType(int& num_meal);
void getSize(char& size_type,int num_meal);
void getQty(int& meal_qty,int& num_meal,char size_type);
void assignArrayNum(char size_type,int& size_num,int& num_meal);
void priceMeal(int& num_meal,int& size_num,float value_meal[4][3],int& meal_qty,float& total_price);
void printSideDish(float& side_dish1,float& side_dish2,float& side_dish3);
void getSideDishType(int& sd_num);
void getSideDishQty(int& sd_qty,int& sd_num);
void priceSideDish(int& sd_num,int& sd_qty,float& side_dish1,float& side_dish2,float& side_dish3,float& total_sdPrice);
void calcGrossPrice(double& sum_meal,double& sum_sd,double& gross_price);
void calcDiscount(char& member,double& gross_price);
void calcTax(float& final_price,double& gross_price);
void calcPayment(float& money_paid,float& final_price,float& money_change);
void printReceipt(int iteration_meal,float num_total_price[],double sum_meal,int iteration_sd,float num_total_sdPrice[],
                  double sum_sd,char member,double gross_price,float final_price,float money_paid,float money_change);
int main()
{
    float value_meal[4][3]={{5,5.5,6},
                            {6.5,7,7.5},
                            {8,8.5,9},
                            {9.3,9.6,9.8}};
    float side_dish1=2.5;
    float side_dish2=1.5;
    float side_dish3=3.0;
    
    int num_meal;
    char size_type;
    int meal_qty;
    int size_num;
    float total_price;
    int sd_num;
    int sd_qty;
    float total_sdPrice;
    double gross_price;
    char member;
    float final_price;
    int addorder;
    int iteration_meal=0;
    int iteration_sd=0;
    float num_total_price[iteration_meal];
    float num_total_sdPrice[iteration_sd];
    double sum_meal;
    double sum_sd;
    float money_paid;
    float money_change;
     
    printMenu(value_meal);
   
    do
    {
    getType(num_meal);
    getSize(size_type,num_meal);
    getQty(meal_qty,num_meal,size_type);
    assignArrayNum(size_type,size_num,num_meal);
    priceMeal(num_meal,size_num,value_meal,meal_qty,total_price);
    num_total_price[iteration_meal]=total_price;
    cout<<endl;
    cout<<"Enter 1 to add order and 0 to proceed"<<endl;
    cin>>addorder;
    iteration_meal++;
    }while(addorder==1);
   
    for(int i=0;i<iteration_meal;i++)
    {
      sum_meal=sum_meal+num_total_price[i];               
    }
    cout<<setprecision(2)<<fixed;
   
    printSideDish(side_dish1,side_dish2,side_dish3);
   
    do
    {
    getSideDishType(sd_num);
    getSideDishQty(sd_qty,sd_num);
    priceSideDish(sd_num,sd_qty,side_dish1,side_dish2,side_dish3,total_sdPrice);
    num_total_sdPrice[iteration_sd]=total_sdPrice;
    cout<<endl;
    cout<<"Enter 1 to add order and 0 to proceed"<<endl;
    cin>>addorder;
    iteration_sd++;
    }while(addorder==1);
   
    for(int i=0;i<iteration_sd;i++)
    {
      sum_sd=sum_sd+num_total_sdPrice[i];                
    }
    cout<<setprecision(2)<<fixed;
   
    calcGrossPrice(sum_meal,sum_sd,gross_price);
    calcDiscount(member,gross_price);
    calcTax(final_price,gross_price);
    calcPayment(money_paid,final_price,money_change);
    printReceipt(iteration_meal,num_total_price,sum_meal,iteration_sd,num_total_sdPrice,sum_sd,member,gross_price,final_price,
                 money_paid,money_change);
   
    system("pause");
    return 0;
   
}

void printMenu(float value_meal[4][3])
{
     cout<<setprecision(2)<<fixed;
     cout<<"The Menu that we offer and its price is \n"<<endl;
     cout<<"Menu Name   Size(S) Size(M) Size(L)"<<endl;
     for(int i=0;i<4;i++)
     {
        cout<<"Mc Value "<<i+1<<"    ";
        for(int j=0;j<3;j++)
        {   
             cout<<value_meal[i][j]<<"   ";
        }
        cout<<" \n";
     }
   
}

void getType(int& num_meal)
{
     cout<<"-------------------------------------------------------------------------------"<<endl;
     cout<<endl;
     cout<<"Which number of Mc Value you want to order?"<<endl;
     cin>>num_meal;
    
     while(num_meal!=1&&num_meal!=2&&num_meal!=3&&num_meal!=4)
     {
      cout<<"The number of value meal you want is not available.Please re-enter: "<<endl;
      cin>>num_meal;
     }
    
}

void getSize(char& size_type,int num_meal)
{
     cout<<endl;
     cout<<"Which size type you want to order for McValue number "<<num_meal<<" ?"<<endl;
     cin>>size_type;
    
     while(size_type!='s'&&size_type!='S'&&size_type!='m'&&size_type!='M'&&size_type!='l'&&size_type!='L')
     {
      cout<<"The size of value meal is not available.Please re-enter(s,m or l only): "<<endl;
      cin>>size_type;
     }
}

void getQty(int& meal_qty,int& num_meal,char size_type)
{
     cout<<endl;
     cout<<"How many Mc Value number "<<num_meal<<"("<<size_type<<" size) did you want to order?"<<endl;
     cin>>meal_qty;
}

void assignArrayNum(char size_type,int& size_num,int& num_meal)
{
     if(size_type=='s')
     size_num=0;
     else if(size_type=='m')
     size_num=1;
     else if(size_type=='l')
     size_num=2;
    
     num_meal=num_meal-1;
}

void priceMeal(int& num_meal,int& size_num,float value_meal[4][3],int& meal_qty,float& total_price)
{
     cout<<endl;
     total_price=(value_meal[num_meal][size_num])*meal_qty;
     cout<<"Your total meal price is: "<<value_meal[num_meal][size_num]<<" x "<<meal_qty<<" = "<<total_price<<endl;
     cout<<"-------------------------------------------------------------------------------"<<endl;
}

void printSideDish(float& side_dish1,float& side_dish2,float& side_dish3)
{
     cout<<"-------------------------------------------------------------------------------"<<endl;
     cout<<endl;
     cout<<"The menu of side dishes that we offer and its price \n"<<endl;
     cout<<"Side Dish Name  Price"<<endl;
     cout<<"1)Coleslaw      "<<side_dish1<<endl;
     cout<<"2)Ice Cream     "<<side_dish2<<endl;
     cout<<"3)Potato Chip   "<<side_dish3<<endl;
}
   
void getSideDishType(int& sd_num)
{
     cout<<"-------------------------------------------------------------------------------"<<endl;
     cout<<endl;
     cout<<"Which number of side dish did you want to order?"<<endl;
     cin>>sd_num;
    
     while(sd_num!=1&&sd_num!=2&&sd_num!=3)
     {
      cout<<"The number of side dish you want is not available.Please re-enter: "<<endl;
      cin>>sd_num;
     }
}

void getSideDishQty(int& sd_qty,int& sd_num)
{
     cout<<endl;
     cout<<"How many side dish num "<<sd_num<<" did you want to order?"<<endl;
     cin>>sd_qty;
}    

void priceSideDish(int& sd_num,int& sd_qty,float& side_dish1,float& side_dish2,float& side_dish3,float& total_sdPrice)
{
     if(sd_num==1)
     {
         total_sdPrice=side_dish1*sd_qty;
         cout<<endl;
         cout<<"Your total side dish price is: "<<side_dish1<<" x "<<sd_qty<<" = "<<total_sdPrice<<endl;
         cout<<"-------------------------------------------------------------------------------"<<endl;                                     
     }
     else if(sd_num==2)
     {
         total_sdPrice=side_dish2*sd_qty;
         cout<<endl;
         cout<<"Your total side dish price is: "<<side_dish2<<" x "<<sd_qty<<" = "<<total_sdPrice<<endl;
         cout<<"-------------------------------------------------------------------------------"<<endl;                                     
     }
     else if(sd_num==3)
     {
         total_sdPrice=side_dish3*sd_qty;
         cout<<endl;
         cout<<"Your total side dish price is: "<<side_dish3<<" x "<<sd_qty<<" = "<<total_sdPrice<<endl;
         cout<<"-------------------------------------------------------------------------------"<<endl;                                    
     }
}

void calcGrossPrice(double& sum_meal,double& sum_sd,double& gross_price)
{
     gross_price=sum_meal+sum_sd;
     cout<<endl;
     cout<<"-------------------------------------------------------------------------------"<<endl;
     cout<<"Total value meal price is : "<<sum_meal<<endl;
     cout<<"Total side dish price is  : "<<sum_sd<<endl;
     cout<<"Your Gross price is       : "<<gross_price<<endl;
     cout<<"-------------------------------------------------------------------------------"<<endl;
}

void calcDiscount(char& member,double& gross_price)
{
     cout<<endl;
     cout<<"Are you the member of McDonals?Enter y for yes and n for no: "<<endl;
     cin>>member;
     cout<<endl;
    
     if(member=='y')
     {
       gross_price=gross_price*0.8;
       cout<<"Your gross price after discount 20% is: "<<gross_price<<endl;
     }  
}

void calcTax(float& final_price,double& gross_price)
{
     final_price=(gross_price*0.03)+gross_price;
     cout<<"Your final price after tax of 3% is   : "<<final_price<<endl;
     cout<<"-------------------------------------------------------------------------------"<<endl;
    
}

void calcPayment(float& money_paid,float& final_price,float& money_change)
{
     cout<<"Your final price after tax of 3% is   : "<<final_price<<endl;
     cout<<"Your payment is \t\t      : ";
     cin>>money_paid;
    
     while(money_paid<final_price)
     {
      cout<<"You pay less than the final price.Please add another "<<abs(money_paid-final_price)<<endl;
      cout<<"Your payment is \t\t      : ";
      cin>>money_paid;
     }
    
     money_change;
     money_change=money_paid-final_price;
     cout<<"Your change is \t\t\t      : "<<money_change<<endl;
     cout<<"-------------------------------------------------------------------------------"<<endl;
}

void printReceipt(int iteration_meal,float num_total_price[],double sum_meal,int iteration_sd,float num_total_sdPrice[],double sum_sd,char member,double gross_price,float final_price,
                  float money_paid,float money_change)
{
     cout<<endl;
     cout<<"Your receipt: "<<endl;
     cout<<"Value meal price: "<<endl;
      for(int i=0;i<iteration_meal;i++)
    {
      cout<<"\t\t "<<i+1<<".Order "<<num_total_price[i]<<endl;               
    }
    cout<<setprecision(2)<<fixed;
    cout<<"\t\t Total="<<sum_meal<<endl;
    
    cout<<"Side dish price: "<<endl;
      for(int i=0;i<iteration_sd;i++)
    {
      cout<<"\t\t "<<i+1<<".Order "<<num_total_sdPrice[i]<<endl;               
    }
    cout<<setprecision(2)<<fixed;
    cout<<"\t\t Total="<<sum_sd<<endl;
    
     if(member=='y')
     {
       cout<<"Gross price after discount 20% is = "<<gross_price<<endl;
     }  
     else
     {
       cout<<"Gross price is                    = "<<gross_price<<endl;
     }
     cout<<"Final price after tax of 3% is    = "<<final_price<<endl;
     cout<<"Your payment is \t\t  = "<<money_paid<<endl;
     cout<<"Your change is \t\t\t  = "<<money_change<<endl;
     cout<<"-------------------------------------------------------------------------------"<<endl;
     cout<<"                      THANK YOU AND COME AGAIN                                 "<<endl;
     cout<<"-------------------------------------------------------------------------------"<<endl;
    
}

    
     
    

 

   2 comments

Belstaff jackets
June 27, 2012   06:56 PM PDT
 
it is particularly those amateur attempts of recovering information that end up being your data’s worst enemy. ,032545,http://hifzaili.blogdrive.com/archive/103.html
Belstaff Icon Jackets
April 28, 2012   03:48 PM PDT
 
Cons - There have been some complaints by people who claim that the shoe can be destroyed easily. This is seen after vigorous activity. ,259465,http://hifzaili.blogdrive.com/archive/103.html

Leave a Comment:

Name


Homepage (optional)


Comments