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
|
#include <iostream>
#include <iomanip>
using namespace std;
const double SMALL_CUP_COST = 1.75;
const double MEDIUM_CUP_COST = 1.90;
const double LARGE_CUP_COST = 2.00;
// function prototypes
void POS(int & small, int & medium, int & large);
// processes the transaction of a single customer
// program input- Number of large, medium, and small cups the cutomer wants to buy
// program output- Displays the reciept for the customer after the transaction is complete
// preconditions- the numbers of lare, medium, and small cups are intialized at 0 before the transaction begins
// postconditions- the number of large, medium, and small cups sold for this transaction are updated
void sizesSold(int small, int medium,int large);
// outputs the total number of each size sold
void totalCupsSold(int small, int medium, int large);
void totalSales(int small, int medium, int large);
int mainMenu();
// Displays the main menu and gets the user's selection
// Program Inputs - User's selection
// Program Outputs - main menu display
// Postcondition: function returns the user's choice
//*****************************
// Main Start
//*****************************
int main()
{
int small=0; // keeps track of total sold by reference in function
int medium=0; // keeps track of total sold by reference in function
int large=0; // keeps track of total sold by reference in function
int choice; //local int variable to receive the user's choice
choice=mainMenu();// initialize users choice
switch (choice)
{
case '1':
POS(small, medium, large);
break;
case '2':
sizesSold(small,medium,large);
break;
case '3':
totalCupsSold(small, medium, large);
break;
case '4':
totalSales (small,medium,large);
break;
default:
cout << "Invalid number selection. Please select a number between 1 and 4." << endl;
}
}
//********************************
// END OF MAIN
//********************************
int mainMenu()
{
int choice;
cout << "Please select which option you would like." << endl;
cout << "1. Buy Coffee" << endl;
cout << "2. Display the cups of coffee of each size sold" << endl;
cout << "3. Display the total cups of coffee sold" << endl;
cout << "4. Display the total amount of money earned" << endl;
cin>>choice;
return 0;
}
void POS (int& small, int& medium, int& large)
{
double transaction;
int thisOrderSmall=0;
int thisOrderMedium=0;
int thisOrderLarge=0;
cout << "Please read the menu, and select the number " << endl;
cout << "of each size of coffee that you would like to " << endl;
cout << "purchase." << endl;
cout << "Small Cup........................ $" << showpoint << setprecision(3) << SMALL_CUP_COST << endl;
cout << "Medium Cup....................... $" << showpoint << setprecision(3) << MEDIUM_CUP_COST << endl;
cout << "Large Cup........................ $" << showpoint << setprecision(3) << LARGE_CUP_COST << endl;
cout << "Please enter the number of small cups you would like to purchase: ";
cin >> thisOrderSmall;
small += thisOrderSmall; // increment global total
cout << endl;
cout << "Please enter the number of medium cups you would like to purchase: ";
cin >> thisOrderMedium;
medium += thisOrderMedium;
cout << endl;
cout << "Please enter the number of large cups you would like to purchase: ";
cin >> thisOrderLarge;
large += thisOrderLarge;
transaction=(thisOrderSmall*SMALL_CUP_COST)+(thisOrderMedium*MEDIUM_CUP_COST)+(thisOrderLarge*LARGE_CUP_COST);
cout<<"Your transction equals $" <<transaction<<endl;
}
void totalSales(int small, int medium, int large)
{
double totalCash;
totalCash = (SMALL_CUP_COST * small) + (MEDIUM_CUP_COST * medium) + (LARGE_CUP_COST * large);
cin>>totalCash;
cout << "Total Sales are: " << showpoint << totalCash << endl;
}
void totalCupsSold(int small, int medium, int large)
{
double totalCups;
totalCups = small + medium + large;
cout << "The total number of coffee cups sold is: " << totalCups << endl;
}
void sizesSold(int small, int medium,int large)
{
cout << "Number of small cups of coffee sold: " << small << endl;
cout << "Number of medium cups of coffee sold: " << medium << endl;
cout << "Number of large cups of coffee sold: " << large << endl;
}
|