-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonline store.cpp
337 lines (328 loc) · 8.27 KB
/
online store.cpp
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#include<iostream>
#include <stdlib.h>
#include<string>
using namespace std;
class Product
{
string name;
int price;
int quantity;
public:
void Setter(string name, int price, int quantity)
{
this->name = name;
this->price = price;
this->quantity = quantity;
}
string Getter_Name()
{
return name;
}
int Getter_price()
{
return price;
}
int Getter_quantity()
{
return quantity;
}
};
class Electronic : public Product
{
string brand;
public:
void Setter_brand(string brand)
{
this->brand = brand;
}
string Getter_brand()
{
return brand;
}
};
class Clothing : public Product
{
string size;
public:
void Setter_size(string size)
{
this->size = size;
}
string Getter_size()
{
return size;
}
};
class Books : public Product
{
string author;
public:
void Setter_author(string author)
{
this->author = author;
}
string Getter_author()
{
return author;
}
};
class Customer
{
string email;
string name;
string address;
public:
void Setter(string name, string email, string address)
{
this->name = name;
this->email = email;
this->address = address;
}
string Getter_Name()
{
return name;
}
string Getter_email()
{
return email;
}
string Getter_address()
{
return address;
}
};
class RegularCustomer : public Customer
{
};
class PremiumCustomer : public Customer
{
int loyaltyPoints;
public:
void SetLoyaltyPoints(int points)
{
loyaltyPoints = points;
}
int GetLoyaltyPoints()
{
return loyaltyPoints;
}
};
class ShoppingCart
{
private:
Customer* customer;
Product* products[10];
int numProducts;
public:
ShoppingCart()
{
customer = nullptr;
numProducts = 0;
for (int i = 0; i < 10; i++)
{
products[i] = nullptr;
}
}
void SetCustomer(Customer* customer)
{
this->customer = customer;
}
void AddProduct(Product* product)
{
if (numProducts < 10)
{
products[numProducts] = product;
numProducts++;
}
else
{
cout << "Shopping cart is full." << endl;
}
}
void RemoveProduct(Product* product)
{
bool found = false;
for (int i = 0; i < numProducts; i++)
{
if (products[i] == product)
{
for (int j = i; j < numProducts - 1; j++)
{
products[j] = products[j + 1];
}
products[numProducts - 1] = nullptr;
numProducts--;
found = true;
cout << "Product removed from the shopping cart." << endl;
break;
}
}
if (!found)
{
cout << "Product not found in the shopping cart." << endl;
}
}
double CalculateTotalPrice()
{
double totalPrice = 0.0;
for (int i = 0; i < numProducts; i++)
{
if (products[i]->Getter_price() != 0 && products[i]->Getter_quantity() != 0)
{
totalPrice += products[i]->Getter_price() * products[i]->Getter_quantity();
}
}
return totalPrice;
}
void GenerateOrderSummary()
{
for (int i = 0; i < numProducts; i++)
{
cout << "Product: " << products[i]->Getter_Name() << endl;
cout << "Price: $" << products[i]->Getter_price() << endl;
cout << "Quantity: " << products[i]->Getter_quantity() << endl;
}
}
};
int main()
{
cout << " WELCOME TO OUR ONLINE SHOPPING STORE" << endl;
cout << endl;
ShoppingCart cart;
RegularCustomer customer1;
string name, email, address;
cout << "Please enter customer name: ";
getline(cin, name);
cout << "Enter customer email: ";
getline(cin, email);
cout << "Enter customer address: ";
getline(cin, address);
customer1.Setter(name, email, address);
system("CLS");
PremiumCustomer customer2;
Electronic electronic;
string productName, brand;
int price, quantity;
cout << endl;
cout << "If you want to buy any Electronic product then write its specificaions" << endl;
cout << "else leave it by a dash(-) no other special character" << endl;
cout << endl;
cout << "Enter electronic product name: ";
getline(cin, productName);
if (productName == "-")
{
price = 0;
quantity = 0;
}
else
{
cout << "Enter electronic product price: ";
cin >> price;
cout << "Enter electronic product quantity: ";
cin >> quantity;
cin.ignore();
electronic.Setter(productName, price, quantity);
cout << "Enter electronic product brand: ";
getline(cin, brand);
electronic.Setter_brand(brand);
cart.AddProduct(&electronic);
}
system("CLS");
Clothing clothing;
string size;
cout << endl;
cout << "If you want to buy any Clothing product then write its specificaions" << endl;
cout << "else leave it by a dash(-) no other special character" << endl;
cout << endl;
cout << "Enter clothing product name: ";
getline(cin, productName);
if (productName == "-")
{
price = 0;
quantity = 0;
}
else
{
cout << "Enter clothing product price: ";
cin >> price;
cout << "Enter clothing product quantity: ";
cin >> quantity;
cin.ignore();
clothing.Setter(productName, price, quantity);
cout << "Enter clothing product size: ";
getline(cin, size);
clothing.Setter_size(size);
cart.AddProduct(&clothing);
}
system("CLS");
Books book;
string author;
cout << endl;
cout << "If you want to buy any Clothing product then write its specificaions" << endl;
cout << "else leave it by a dash(-) no other special character" << endl;
cout << endl;
cout << "Enter book name: ";
getline(cin, productName);
if (productName == "-")
{
price = 0;
quantity = 0;
}
else
{
cout << "Enter book price: ";
cin >> price;
cout << "Enter book quantity: ";
cin >> quantity;
cin.ignore();
book.Setter(productName, price, quantity);
cout << "Enter book author: ";
getline(cin, author);
book.Setter_author(author);
cart.AddProduct(&book);
}
system("CLS");
int customerType;
cout << "Enter customer type (1 for Regular, 2 for Premium): ";
cin >> customerType;
cin.ignore();
if (customerType == 1)
{
cart.SetCustomer(&customer1);
}
else if (customerType == 2)
{
cart.SetCustomer(&customer2);
}
else
{
cout << "Invalid customer type." << endl;
return 0;
}
system("CLS");
cout << "Customer Name: " << customer1.Getter_Name() << endl;
cout << "Customer Email: " << customer1.Getter_email() << endl;
cout << "Customer Address: " <<customer1.Getter_address() << endl;
cout << endl;
cart.GenerateOrderSummary();
if (customerType == 1)
{
double totalPrice = cart.CalculateTotalPrice();
cout << "Total Price: $" << totalPrice << endl;
}
else if (customerType == 2)
{
double totalPrice = cart.CalculateTotalPrice();
cout << "Total Price: $" << totalPrice << endl;
cout << "After Having 20% discount as you are a Premium Customer" << endl;
double disc = totalPrice * 0.2;
cout << "Total Price after discount : $" << totalPrice - disc << endl;
}
else
{
cout << " Invalid number Entered " << endl;
double totalPrice = cart.CalculateTotalPrice();
cout << "Total Price: $" << totalPrice << endl;
}
return 0;
}