-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommerse.cpp
More file actions
250 lines (216 loc) · 7.22 KB
/
Commerse.cpp
File metadata and controls
250 lines (216 loc) · 7.22 KB
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/***********************************************************************
* Program:
* Product
* Author:
* Bryce Maughan
* Summary:
* Demonstrate OOP in C++
************************************************************************/
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
using namespace std;
/**********************************************************************
* This is the Product class
*
***********************************************************************/
class Product{
private:
string id, name;
double price, quantity;
public:
// default constructor
Product(){
id = "";
name = "";
price = 0;
quantity = 0;
}
//perameterized constructor
Product(string i, string n, double p, double q){
// initialize private variables
id = i;
name = n;
price = p;
quantity = q;
}
//Overloading syntax:
Product operator * (Product p){
Product temp;
temp.price = price * p.quantity;
return temp;
}
// grabbing the Total Price:
double getTotalPrice(){
return price * quantity;
}
void display(){
cout << "***** Product Details *****\n";
cout << "Id: " << id << endl; // Item number
cout << "Name: " << name << endl; // Item Name
cout << "Price: " << price << endl; // Retail price per Item
cout << "Quantity: " << quantity << endl; // assume the customer filled out this feild:
cout << "--- ^ ---\n";
cout << "\n";
}
void summary(){ // Summary of Product Details
cout << name << " | " << quantity << " | $" << getTotalPrice() << endl;
}
};
/**********************************************************************
* This is the Order class
*
***********************************************************************/
class Order{
private:
string id;
public:
Order(){
id = "";
}
Order(string i){
id = i;
}
string getId(){
return id;
}
vector<Product> products;
void addProduct(Product p){
products.push_back(p);
}
double getSubTotal(){
double subTotal = 0;
for (Product i : products){
subTotal += i.getTotalPrice();
}
return subTotal;
}
double getTax(){
return getSubTotal() * 0.065;
}
double getTotal(){
return getSubTotal() + getTax();
}
void displayReceipt(){
cout << "Confimation Number: " << id << endl;
cout << "Product Name | Quantity Ordered | Total Retail Price\n";
cout << endl;
cout << "***** Products in Cart *****\n";
for (vector<Product>::iterator it = products.begin(); it != products.end(); ++it){
(*it).summary();
}
cout << endl;
cout << "------------ <| Order: " << id << " Summary |> ------------\n";
cout << "Retail Subtotal: ----- $" << getSubTotal() << endl;
cout << "Tax: ----------------- $" << getTax() << endl;
cout << "Total: --------------- $" << getTotal() << endl;
}
void orderSummary(){
for (Product p : products){
p.summary();
}
}
};
/**********************************************************************
* This is the Order class
*
***********************************************************************/
class Customer{
private:
string id;
string name;
public:
vector<Order> orders;
Customer(){
id = "";
name = "";
}
Customer(string i, string n){
id = i;
name = n;
}
string getId(){
return id;
}
string getName(){
return name;
}
void addOrder(Order o){
orders.push_back(o);
}
int getOrderCount(){
int orderCount = 0;
for (Order o : orders){
orderCount += 1;
}
return orderCount;
}
double getTotal(){
double grandTotal = 0;
for (Order o : orders){
grandTotal += o.getTotal();
}
return grandTotal;
}
void history(){ // Just a little example of what I can display from the Customer's History:
cout << "Customer Number: " << id << endl;
cout << "Product Name | Quantity Ordered | Total Retail Price\n";
for (vector<Order>::iterator it = orders.begin(); it != orders.end(); ++it){
cout << "Summary For Order: " << (*it).getId() << endl;
(*it).orderSummary(); // I have to place 'it' within parentheses with the star pointer to get my member data.
}
cout << endl;
cout << "------------ <| Customer: " << id << " Summary |> ------------\n";
cout << "Name on Account: --------------------- > " << name << endl;
cout << "Number of Orders Made: --------------- > " << getOrderCount() << endl;
cout << "Total Ammount for All Orders Made: --- $" << getTotal() << endl;
}
};
/**********************************************************************
* MAIN
*
***********************************************************************/
int main(){
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2); // All decimal places are rounded to hundreths
// Customer Login:
Customer customer("aa32", "Gandalf");
// Create Shopping Cart:
cout << endl;
cout << endl;
cout << "###### New Order ######\n";
Order order1("1138");
// Customer Adds Products to Cart:
Product p1("1238223", "Sword", 1899.99, 10);
//submit Product entry to cart:
order1.addProduct(p1);
Product p2("838ab883", "Shield", 989.75, 6);
//submit Product entry to cart:
order1.addProduct(p2);
//Display Orter Recipt:
order1.displayReceipt();
// On Order Submit:
cout << "*** Thank You for your purchase " << customer.getName() << "! ***" << endl;
cout << "*** Your order number is: " << order1.getId() << " ***" << endl;
customer.addOrder(order1); // Save order to customer history
// Making a new order:
cout << endl;
cout << endl;
cout << "###### New Order ######\n";
Order order2("1277182");
Product p3("2387127", "The One Ring", 1000000, 1);
order2.addProduct(p3);
Product p4("1828191", "Wizard Staff", 199.99, 3);
order2.addProduct(p4);
order2.displayReceipt();
// On Order Submit:
cout << "*** Thank You for your purchase " << customer.getName() << "! ***" << endl;
cout << "*** Your order number is: " << order1.getId() << " ***" << endl;
customer.addOrder(order2); // Save order to customer history
// Display Saved Customer Purchase History:
cout << endl;
customer.history();
return 0;
}