1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
|
/**
Jason 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 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 any time show the total amount of coffee sold.
D. At any time show the total money made
your program should consist of at least the following funtions:
a function to show the user how to use the program
a function to sell coffee
a function to show the number of cups of each size sold
a function to show the total amount of coffee sold
a function to show the total amount of money made.
Your program should not use an global variables and special values
such as coffee cup sizes and cost of a coffee cup must be declared as named constants.
*/
#include <iostream>
#include <iomanip>
using namespace std;
//constants
double const smCoffee = 1.75;
double const mdCoffee = 1.90;
double const lgCoffee = 2.00;
//Function prototypes
void initialize (int& numberSmCups, int& numberMedCups, int& numberLgCups,double& totalSmCups,
double& totalMedCups, double& totalLgCups);
void showChoices();
void buyCoffee(int& numberSmCups,double& totalSmcups,int& numberMedCups,double& totalMedCups,int& numberLgCups
,double& totalLgCups);
void cupsSold(int& numberSmCups,int& numberMedCups,int& numberLgCups);
void coffeeSold();
void totalAmount(double& totalSmCups,double& totalMedCups, double& totalLgCups);
void printCupsSold(int& numberSmCups,int& numberMedCups,int& numberLgCups);
//Main
int main()
{
//declare variables
int numberSmCups;
int numberMedCups;
int numberLgCups;
double totalSmCups;
double totalMedCups;
double totalLgCups;
int choice;
//initialize
initialize(numberSmCups,numberMedCups,numberLgCups,totalSmCups,
totalMedCups,totalLgCups);
//showChoice switch
do
{
showChoices();
cin >> choice;
cout << endl;
switch (choice)
{
case 1:
cout <<"You selected to buy coffee."<< endl;
initialize(numberSmCups,numberMedCups,numberLgCups,totalSmCups,
totalMedCups,totalLgCups);
buyCoffee(numberSmCups,totalSmCups,numberMedCups,totalMedCups,numberLgCups,totalLgCups);
break;
case 2:
cout << "The total amount of cups sold by size is: "<<endl;
cupsSold(numberSmCups,numberMedCups,numberLgCups);
break;
case 3:
cout << "function for lifetime coffee sold";
break;
case 4:
cout << "The total money made for Coffee Sales is: ";
totalAmount(totalSmCups,totalMedCups,totalLgCups);
break;
case 99:
break;
default:
cout << "Invalid input." << endl;
}
}
while (choice != 99);
cout<< " Thank you for using this program. Have a nice day."<<endl;
return 0;
} //end Main
void showChoices()
{
cout << "Enter--" << endl;
cout<< endl;
cout << "1: Buy Coffee " << endl;
cout << "2: Shows the total cups sold by size "<< endl;
cout << "3: Shows the total amount of coffee sold"<<endl;
cout << "4: Shows the total amount of money made"<< endl;
cout << "99: To quit the program." << endl;
}// end showChoices
void initialize (int& numberSmCups, int& numberMedCups, int&numberLgCups,double& totalSmCups,
double& totalMedCups, double& totalLgCups/*,int& lifeSmCups,int lifeMdCups,int lifeLgCups*/){
numberSmCups=0;
numberMedCups=0;
numberLgCups=0;
totalSmCups=0;
totalMedCups=0;
totalLgCups=0;
} //end initialize
void buyCoffee(int& numberSmCups,double& totalSmCups,int& numberMedCups,double& totalMedCups,
int& numberLgCups,double& totalLgCups){
char coffeeSize;
char order;
cout <<"Would you like some coffee? (y for yes, n for no)"<<endl;
cin>>order;
while(true){
if (order == 'y' ||order =='Y'){
cout<<"What size coffee would you like? (s,m,l)";
cin>> coffeeSize;
if (coffeeSize == 's'){
cout<<"How many?";
cin>>numberSmCups;
totalSmCups = numberSmCups * smCoffee;
cout<<"Small Coffee: "<<numberSmCups<<" "<<totalSmCups<<endl;
cout<<"add another?"<<endl;
cin>> order;
}
else
if (coffeeSize == 'm'){
cout<<"How many?";
cin>>numberMedCups;
totalMedCups = numberMedCups * mdCoffee;
cout<<"Medium Coffee: "<<numberMedCups<<" "<<totalMedCups<<endl;
cout<<"add another?"<<endl;
cin>> order;
}
else
if (coffeeSize == 'l'){
cout<<"How many?";
cin>>numberLgCups;
totalLgCups = numberLgCups * lgCoffee;
cout<<"Large Coffee: "<<numberLgCups<<" "<<totalLgCups<<endl;
cout<<"add another?"<<endl;
cin>> order;}
}
else
break;
}//end While
cout<<"you ordered: "<<endl;
cout<< endl;
if (numberSmCups>= 1) cout<<"Small Coffee: "<<numberSmCups<<" "<<"@"<<" "<<smCoffee<<" "<<"$"<<totalSmCups<< endl;
if (numberMedCups>=1)cout<<"Medium Coffee: "<<numberMedCups<<"@"<<" "<<mdCoffee<<" "<<" $"<<totalMedCups<<endl;
if (numberLgCups>=1) cout<<"Large Coffee: "<<numberLgCups<<"@"<<" "<<lgCoffee<<" "<<" $"<<totalLgCups<<endl;
cout<< endl;
cout<<"Amount Due: "<<" "<<"$"<< (totalSmCups+ totalMedCups+ totalLgCups)<<endl;
}//end BuyCoffee
void cupsSold(int& numberSmCups,int& numberMedCups,int& numberLgCups){
static int lifeSmCups=0;
static int lifeMdCups=0;
static int lifeLgCups=0;
lifeSmCups = lifeSmCups + numberSmCups;
lifeMdCups = lifeMdCups + numberMedCups;
lifeLgCups = lifeLgCups + numberLgCups;
//cout<<"Total Small cups: "<<lifeSmCups<<endl;
//cout<<"Total Medium Cups:"<<lifeMdCups<<endl;
// cout<<"Total Large Cups:"<<lifeLgCups<<endl;
}//end cupsSold
void printCupsSold (int& numberSmCups,int& numberMedCups,int& numberLgCups){
}
void totalAmount(double& totalSmCups,double& totalMedCups, double& totalLgCups){
static double lifeSmAmount=0;
static double lifeMdAmount = 0;
static double lifeLgAmount = 0;
static double moneyMade = 0;
lifeSmAmount = lifeSmAmount + totalSmCups;
lifeMdAmount = lifeMdAmount + totalMedCups;
lifeLgAmount = lifeLgAmount + totalLgCups;
moneyMade= lifeSmAmount + lifeMdAmount+ lifeLgAmount;
cout<<"Total: "<<"$"<<moneyMade<<endl;
}//end totalAmount
|