C++:Problem14

Problem:
A coffee shop sells expresso coffee for $1.25 a cup, bagels for $1.50 and Danish pastries for $2.25. Write a cash register program to compute a customer's bill. Using functions (Therefore, you must have at least four functions)
• To obtain the quantity of each item ordered (Hint: use call-by-reference variables)
• Calculate the subtotal of the bill
• Calculate the total cost of the bill, including a 7 percent sales tax
• Display an itemized bill for example as follows:

Item Quantity Price

Coffee 3 $3.75
Bagels 2 $3.00
Danish 1 $2.25

Sub total $9.00
Sales Tax $ .63

Total $9.63

Objective:
• Using functions with call by value and call by reference
• Write comments for functions: purpose, precondition and postcondition
• No Global Variable (only when necessary)
• Using formatting comments
• Using good style for source program

Display:
Enter the amount of coffee: 1

Enter the amount of bagels: 1

Enter the amount of danish pastries: 1
Item Quantity Price

Coffee 1 $1.25
Bagels 1 $1.50
Danish 1 $2.25

Sub total $5.00
Sales Tax $0.35

Total $5.35


Would you like to try again?(y/n) n


End of program

Code:
//function declaration
void display(float cprc,float bprc,float dprc, int cqnt, int bqnt,int dqnt, float sbttl,float ttl);
//purpose:display the design of the bill
//precondition: none
//Postcondition: returns the display function

//function declaration
float coffee(int& quantity);
//purpose: To find price of coffee
//precondition: input quantity of cups
//postcondition: returns the price of coffee

//function declaration
float bagel(int& quantity);
//purpose: To find price of bagel
//precondition: input quantity of bagels
//postcondition: returns the price of bagels

//function declaration
float danish(int& quantity);
//purpose: To find price of danish pasries
//precondition: input quantity of danish pastries
//postcondition: returns the price of danish pastries

//function declaration
float cal_subTtl(float p1, float p2, float p3);
//purpose: To find price of coffee, bagels and danish pastries
//precondition: none
//postcondition: returns the price1, price2 and price3

//function declaration
float cal_Total(float st);
//purpose: To find total of subtotal and tax
//precondition: none
//postcondition: returns the total of the bill


#include
#include
#include
using namespace std;

int main()
{
//declaration of variables
float cprice, bprice, dprice, subtotal, total;
int cquant, bquant, dquant;
char choice;

//decimal format
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

do
{
cout < cprice = coffee(cquant);
bprice = bagel(bquant);
dprice = danish(dquant);
subtotal = cal_subTtl(cprice, bprice, dprice);
total = cal_Total(subtotal);
display(cprice,bprice,dprice,cquant,bquant,dquant,subtotal,total);

cout <<"\n\nWould you like to try again?(y/n) ";
cin >> choice;
}
while(toupper(choice) =='y');

cout << "\n\nEnd of program"< return 0;
}

//function definition
void display(float cprc,float bprc,float dprc, int cqnt, int bqnt,int dqnt, float sbttl,float ttl)
{

cout<< "Item\t\t"<<"Quantity\t\t"<<"Price"< cout<< "Coffee"<< setw(8) << cqnt<< setw(11) <<"$"< cout<< "Bagels"<< setw(8) << bqnt<< setw(11) << "$"< cout<< "Danish"<< setw(8)<< dqnt<< setw(11) << "$"< cout<< "Sub total"<< setw(16) << "$" << sbttl< cout<< "Sales Tax"<< setw(16) << "$"<< .07*sbttl< cout<< "Total"<< setw(20) << "$" <
}


//function definition
float coffee(int& quantity)
{

cout<< "Enter the amount of coffee: ";
cin>> quantity;
return quantity * 1.25 ;
}

//function definition
float bagel(int& quantity)
{

cout< cin>> quantity;
return quantity * 1.50 ;
}

//function definition
float danish(int& quantity)
{
cout< cin>> quantity;
return quantity * 2.25 ;
}

//function definition
float cal_subTtl(float p1, float p2, float p3)
{
return p1 + p2 + p3;
}

//function definition
float cal_Total(float st)
{
return (.07 * st) + st;
}