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
|
#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <stdio.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
class Customer //this is my class
{
public: // these are the methods of my class
void setCustName(string name) //sets the customers name
{
customerName = name;
}
void setCustAddress(string address) // sets the customer address
{
customerAddress = address;
}
string getCustName() const //gets the customer name
{
return customerName;
}
string getCustAddress() const //gets the customer address
{
return customerAddress;
}
void displaymessage1() const // message that displays the name
{
cout << "Welcome " << getCustName() << " to Games2Go.\n";
}
void displaymessage2() const //message that displays the shipping destination
{
cout << "Your order will be shipped to " << getCustAddress() << "\n";
}
private: // these are the attributes or variales of my class.
string customerName;
string customerAddress;
};
int menu(string custName){
int Selection;
cout << " Thank you for visiting Games2Go\n";// welcome message to the customer
cout << "\n";
cout << custName <<" Please select from the product menu below.\n";// this is introducing the product menu
cout << " Product Menu\n"; // this menu give the customer different ways to search for the game they want.
cout << "\n";
cout << " Product name Price\n";
cout << "\n";
cout << "\n";
cout << "1 - Call of Duty: Advanced Warfare $59.00\n";
cout << "2 - Destiny $65.00\n";
cout << "3 - Assasins Creed: Unity $45.00\n";
cout << "4 - NBA 2K15 $52.00\n";
cout << "5 - Super Smash Bros $59.00\n";
cout << "6 - Watch Dogs $49.00\n";
cout << "7 - Starcraft $19.00\n";
cout << "8 - Counterstrike $25.00\n";
cout << "\n";
cout << " Enter 0 to quit and check out\n";
cin >> Selection;
return Selection;
}
double salesprice (int Selection, int quantity[], double line[]){ // this is the fuction to get the price before taxes
double price;
cout << "Enter the quantity you would like to buy\n";
cin >> quantity[Selection-1];
switch(Selection){
case 1: { price = 59;}
break;
case 2: { price = 65;}
break;
case 3: { price = 45;}
break;
case 4: { price = 52;}
break;
case 5: { price = 59;}
break;
case 6: { price = 49;}
break;
case 7: { price = 19;}
break;
case 8: { price = 25;}
break;
break;
default: {price = 0;}
break;
}
line[Selection-1] = price*quantity[Selection-1];
return line[Selection-1];
}
double totaltax (double price) // this is the fuction to calculate the sales tax
{
const double TAX = 0.05;
double saleTax;
saleTax = (price *TAX);
return saleTax;
}
void showProducts(string order[], int quantity[], double lines[])
{
cout << "\n";
cout << setw(33) << "This is your current order\n";
cout << "\n";
cout << setw(36) <<" Product " << setw(5) << "Quantity" << setw(10) << "Price\n";
cout << "\n";
for (int count=0; count<8; count++){
cout << setw(30)<< order[count] << setw(9)<< quantity[count] << setw(12)<<lines[count]<<"\n";
}
}
int main()
{
Customer myCustomer;
string custName;
string custAddress;
int Selection;
double totalsalestax = 0;
double subtotal = 0;
double totalsale = 0;
double totalprice = 0;
string productOrder[8] = {"Call of Duty: Advanced Warfare", "Destiny", "Assasins Creed: Unity", "NBA 2K15", "Super Smash Bros", "Watch Dogs", "Starcraft", "Counterstrike"};
double lineAmount[8] = {0, 0, 0, 0, 0, 0, 0, 0};
int orderQty[8] = {0, 0, 0, 0, 0, 0, 0, 0};
cout << fixed << setprecision(2);
cout << "Please enter your name:"; // asks customers name
getline (cin, custName);
cout << "\n";
myCustomer.setCustName(custName); //sets the customer name as the input custName
cout << "Please enter your address:"; // asks customers address
getline (cin, custAddress);
cout << "\n";
myCustomer.setCustAddress(custAddress); // sets the customer address as the input custAddress
myCustomer.displaymessage1(); // displays the welcome message for the customer name
cout << "\n";
Selection = menu(custName);
int count = 0;
while (Selection !=0)
{
subtotal = salesprice(Selection, orderQty, lineAmount);
cout << "Your last selection totalled $" << subtotal <<"\n";
showProducts(productOrder, orderQty, lineAmount);
cout << "\n";
totalprice = totalprice + subtotal;
cout << "The total of your order so far is $" << totalprice << "without tax\n";
Selection = menu(custName);
}
totalsalestax = totaltax(subtotal);
totalsale = totalsalestax+subtotal;
cout << "Your reciept is as follows\n";
showProducts(productOrder, orderQty, lineAmount);
cout << "\n";
cout << "Your final order amount is $" << totalprice << "\n";
cout << "\n";
cout << "You paid $" << totalsalestax << " in taxes today\n";
cout << "\n";
cout << "Your total purchase amount is $" << totalsale << "\n";
cout << "\n";
myCustomer.displaymessage2(); //displays the customer address information
return 0;
}
|