-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
431 lines (364 loc) · 11.4 KB
/
main.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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
class Shopping
{
private:
int pCode;
double price, discount;
string productName;
public:
void mainMenu();
void administrator();
void buyer();
void add();
void edit();
void del();
void list();
void receipt();
};
void Shopping::mainMenu()
{
m:
system("Color 09");
int choice;
string email, password;
cout << "\n\n\n\n";
cout << "\t\t\t_________ Mini Shop Billing System ________" << endl << endl << endl << endl;
cout << "\t1 ] Administrator\n\n" ;
cout << "\t2 ] Buyer\n\n";
cout << "\t0 ] Exit Application\n\n";
cout <<"\nEnter your choice (0 to 2) : ";
cin >> choice;
switch(choice)
{
case 1:
system("cls");
system("Color 0A");
cout << "\n\t\t* * * Please Login to continue * * * ";
cout << "\n\n\nEnter admin email : ";
cin >> email;
cout << "\nEnter password : ";
cin >> password;
if(email == "[email protected]" && password == "admin123")
{
administrator();
}
else
cout << "\nInvalid Email or password !!! ";
break;
case 2:
system("cls");
system("Color 0A");
buyer();
break;
case 0:
exit(0);
cout << "\n\n\t\tThanks for using Mini Shop Billin Management System....\n\n";
break;
default:
cout << "\n\tPlease select from the given option.....\n";
}
goto m;
}
void Shopping::administrator()
{
m:
int choice;
cout << "\n\n\n\t________Admin Dashboard________\n\n";
cout << "\t| 1 ] Add record |\n";
cout << "\t| |\n";
cout << "\t| 2 ] Modify record |\n";
cout << "\t| |\n";
cout << "\t| 3 ] Delete record |\n";
cout << "\t| |\n";
cout << "\t| 4 ] Show record |\n";
cout << "\t| |\n";
cout << "\t| 5 ] Back to main menu |\n";
cout << "\n\nEnter your choice [1 to 4] : ";
cin >> choice;
switch(choice)
{
case 1:
system("cls");
add();
break;
case 2:
system("cls");
edit();
break;
case 3:
system("cls");
del();
break;
case 4:
system("cls");
cout << "\n\n\t\t\t\tProuct List\n\n";
list();
break;
case 5:
system("cls");
mainMenu();
break;
default:
cout << "\n\tInvalid choice !!!\n";
}
goto m;
}
void Shopping::buyer()
{
m:
int choice;
cout << "\n\n\t\t______Buyer______\n\n";
cout << "\t| 1 ] Buy Product |\n";
cout << "\t| |\n";
cout << "\t| 2 ] Go Back |\n";
cout << "\t| |\n";
cout << "\n\tEnter your choice [1 to 2] : ";
cin >> choice;
switch(choice)
{
case 1:
system("cls");
receipt();
break;
case 2:
system("cls");
mainMenu();
break;
default:
cout << "\n\tInvalid choice !!!\n";
}
goto m;
}
void Shopping::add()
{
m:
fstream data;
int c, token=0;
float p, d;
string n;
cout << "\n\t\t___Add New Record___\n";
cout << "\n\tEnter Product Code : ";
cin >> pCode;
cout << "\n\tEnter Product Price : ";
cin >> price;
cout << "\n\tEnter Product on discount : ";
cin >> discount;
cout << "\n\tEnter Product Name : ";
cin >> productName;
data.open("shopdata.txt", ios::in);
if(!data)
{
data.open("shopdata.txt", ios::app | ios::out);
data << pCode << " " << price << " " << discount << " " << productName << endl;
data.close();
}
else
{
data >> c >> p >> d >> n;
while(!data.eof())
{
if(c == pCode)
{
token++;
}
data >> c >> p >> d >> n;
}
data.close();
if(token == 1)
goto m;
else
{
data.open("shopdata.txt", ios::app | ios::out);
data << pCode << " " << price << " " << discount << " " << productName << endl;
data.close();
}
}
cout << "\n\n\tNew record is successfully inserted.\n\n";
}
void Shopping::edit()
{
fstream data, tempData;
int productKey, token = 0, c;
double p, d;
string n;
cout << "\n\n\t\t_______Edit Product________\n\n";
cout << "\n\tTo edit enter product code : ";
cin >> productKey;
data.open("shopdata.txt", ios::in);
if(!data)
{
cout << "\n\tFile does not exit.\n";
}
else
{
tempData.open("tempData.txt", ios::app | ios::out);
data >> pCode >> price >> discount >> productName;
while(!data.eof())
{
if(productKey == pCode)
{
cout << "\n\tEnter New Product Code : ";
cin >> c;
cout << "\n\tEnter New Prouduct Price : ";
cin >> p;
cout << "\n\tEnter Product Name : ";
cin >> n;
cout << "\n\tEnter Product Discount Range : ";
cin >> d;
tempData << " " << c << " " << p << " " << d << " " << n << "\n";
cout << "\n\n\tProduct update is successful ...\n";
token++;
}
else
{
tempData << " " << pCode << " " << price << " " << discount << " " << productName << "\n";
}
data >> pCode >> price >> discount >> productName;
}
data.close();
tempData.close();
remove("shopdata.txt");
rename("tempData.txt", "shopdata.txt");
if(token == 0)
cout << "\n\n\tSorry!.. no product found.\n";
}
}
void Shopping::del()
{
fstream data, tempData;
int productkey, token=0;
cout << "\n\n\t\t_________Delete Product_________\n\n";
cout << "\n\tEnter Product Code : ";
cin >> productkey;
data.open("shopdata.txt", ios::in);
if(!data)
{
cout << "\n\tFile does not exit\n";
}
else
{
tempData.open("tempData.txt", ios::app|ios::out);
data >> pCode >> price >> discount >> productName;
while(!data.eof())
{
if(pCode == productkey)
{
cout << "\n\tProduct deleted successful.\n";
token ++;
}
else
{
tempData << " " << pCode << " " << price << " " << discount << " " << productName << endl;
}
data >> pCode >> price >> discount >> productName;
}
data.close();
tempData.close();
remove("shopdata.txt");
rename("tempData.txt" , "shopdata.txt");
if(token == 0)
cout << "\n\n\tNo record found !!! \n";
}
}
void Shopping::list()
{
fstream data;
cout << "\t- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n";
cout << "\t| Product Code | Product Name | Price | Discount |\n";
cout << "\t- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n";
data.open("shopdata.txt", ios::in);
data >> pCode >> price >> discount >> productName;
while(!data.eof())
{
cout << "\n\t| " << pCode << "\t\t | " << productName << "\t\t | " << price << " | " << discount << " % |" << endl;
data >> pCode >> price >> discount >> productName;
}
cout << "\n\n\t- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n";
data.close();
}
void Shopping::receipt()
{
fstream data;
int arrCode[100], arrQuantity[100];
char choice;
int code=0;
double amount=0, disc=0, total=0;
cout << "\n\n\t\t\t\t__________PRODUCTS LIST__________\n\n";
data.open("shopdata.txt", ios::in);
if(!data)
{
cout << "\n\n\tData does not exit....\n";
}
else
{
data.close();
list();
cout << endl << endl << endl ;
cout << "\t- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n";
cout << "\t| |\n";
cout << "\t| * * * Place an order * * * |\n";
cout << "\t| |\n";
cout << "\t- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n";
do{
m:
cout << "\n\n\tEnter product code : ";
cin >> arrCode[code];
cout << "\n\tEnter product quantity : ";
cin >> arrQuantity[code];
for(int i=0; i<code; i++)
{
if(arrCode[code] == arrCode[i])
{
cout << "\n\tDuplicate product code. Please try again...\n";
goto m;
}
}
code++;
cout << "\n\tDo you want to buy another product ? Please choice ( y / n ) : ";
cin >> choice;
}while(choice == 'y');
///Test array
///cout << "\n\narrCode[100] members : " << endl;
///for(int i=0; i<code; i++){
///cout << "arrCode : " << arrCode[i] << endl;
///}
cout << "\n\n\t\t\t\tRECEIPT\n";
cout << "\t\t\t\t- - - - \n\n";
cout << "\t_______________________________________________________________________________________________\n";
cout << "\tProduct Code" << "\tProduct Name" << "\tQuantity" << "\tPrice" << "\t\tAmount" << "\t\tDiscount\n";
cout << "\t_______________________________________________________________________________________________\n";
for(int i=0; i<code; i++)
{
data.open("shopdata.txt", ios::in);
data >> pCode >> price >> discount >> productName;
while(!data.eof())
{
///test member of product code and member of array
///cout << "\npCode : " << pCode << endl;
///cout << "\narrCode : " << arrCode[i] << endl;
if( pCode == arrCode[i] )
{
amount = price * arrQuantity[i];
disc = amount - (amount * discount/100);
total = total + disc;
cout << "\n\t\t" << pCode << "\t" << productName << "\t\t " << arrQuantity[i] << "\t\t" << price << "\t\t" << amount << "\t\t" << disc;
}
data >> pCode >> price >> discount >> productName;
i++;
}
}
data.close();
}
cout << "\n\t_______________________________________________________________________________________________\n";
cout << "\n\n\tTotal is " << total << endl;
cout << "\n\t_______________________________________________________________________________________________\n";
}
int main()
{
Shopping shopping;
shopping.mainMenu();
return 0;
}