-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsow.cpp
More file actions
632 lines (509 loc) · 15.9 KB
/
sow.cpp
File metadata and controls
632 lines (509 loc) · 15.9 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
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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
#include <bits/stdc++.h>
using namespace std;
// FUNCTIONS FOR "COLOURS"
int sales=0;
int amount=0;
void blue() {
cout << "\033[1;34m";
}
void red() {
cout << "\033[3;31m";
}
void yellow() {
cout << "\033[1;33m";
}
void purple() {
cout << "\033[4;35m";
}
void reset() {
cout << "\033[0m";
}
string cleanString(const string& str) {
string cleanedStr;
for (char c : str) {
if (isdigit(c) || c == '.' || c == ',') {
cleanedStr += c;
}
}
return cleanedStr;
}
// class for taking username and password
class Data {
public:
char username[25];
char password[25];
};
Data datalist[3] = {
{"Nikhil", "nikhil@123"},
{"Manikanta", "mani@123"},
{"Sowmith", "sowmith@123"},
};
// External variable for storing who is operating the system
char provider[20];
// Function for checking who is logging into the MSN-MART Login page
int checking() {
char user[25], login[25];
int i, k, n;
static int flag = 0, pass = 0;
cout << "USERNAME: ";
cin >> user;
strcpy(provider, user);
for (i = 0; i < 3; i++) {
k = strcmp(user, datalist[i].username);
if (k == 0) {
flag = 1;
break;
}
}
if (flag == 1) {
cout << "PASSWORD: ";
cin >> login;
for (i = 0; i < 3; i++) {
k = strcmp(login, datalist[i].password);
if (k >= 0) {
pass = 1;
break;
}
}
}
if (flag == 0 || pass == 0) {
red();
cout << "You entered an invalid USERNAME/PASSWORD\n";
cout << "1 - Try again\n2 - Exit\nPress any index: ";
reset();
cin >> n;
if (n == 1) {
checking();
} else if (n == 2) {
exit(9);
}
}
if (pass == 1 && flag == 1) {
return 1;
} else {
return 0;
}
}
// class for the main product list
class Product {
public:
string name;
int quantity;
float price;
};
// Function for checking the existing stock
int stock_checking() {
ifstream file("DMart.csv");
Product me[499];
int i = 0;
if (!file) {
cout << "Failed to open the file." << endl;
return 1;
}
string line;
while (i < 499 && getline(file, line)) {
istringstream iss(line);
string name, priceStr, quantityStr;
char comma;
if (getline(iss, name, ',') && getline(iss, priceStr, ',') && getline(iss, quantityStr, ',')) {
me[i].name = name;
try {
me[i].price = stof(cleanString(priceStr)); // Clean the "price" string
}
catch (const invalid_argument& e) {
// cerr << "Invalid price format: " << e.what() << endl;
continue; // Skip this entry if price conversion fails
}
try {
me[i].quantity = stoi(cleanString(quantityStr)); // Clean the "quantity" string and convert to int
}
catch (const invalid_argument& e) {
// cerr << "Invalid quantity format: " << e.what() << endl;
continue; // Skip this entry if quantity conversion fails
}
i++;
}
}
int check_product;
blue();
cout << "Enter the number of different products you want to check: " << endl;
reset();
cin >> check_product;
string check[check_product];
for (int h = 0; h < check_product; h++) {
cout << "Enter the name of the " << h + 1 << " product: " << endl;
cin >> check[h];
}
int h, g;
for (g = 0; g < check_product; g++) {
for (h = 0; h < 499; h++) {
int y = check[g].compare(me[h].name);
if (y == 0) {
yellow();
cout << "Stock of " << me[h].name << " product is " << me[h].quantity << endl;
reset();
break;
}
}
if (h == 499) {
red();
cout << "!!" << check[g] << " product is \"NOT FOUND\"!!" << endl;
reset();
}
}
file.close();
return 0;
}
// Function for adding new stock
int adding() {
ifstream file("DMart.csv");
Product me[499];
int i = 0;
if (!file) {
cout << "Failed to open the file." << endl;
return 1;
}
string line;
while (i < 499 && getline(file, line)) {
istringstream iss(line);
string name, priceStr, quantityStr;
char comma;
if (getline(iss, name, ',') && getline(iss, priceStr, ',') && getline(iss, quantityStr, ',')) {
me[i].name = name;
try {
me[i].price = stof(cleanString(priceStr)); // Clean the "price" string
}
catch (const invalid_argument& e) {
// cerr << "Invalid price format: " << e.what() << endl;
continue; // Skip this entry if price conversion fails
}
try {
me[i].quantity = stoi(cleanString(quantityStr)); // Clean the "quantity" string and convert to int
}
catch (const invalid_argument& e) {
// cerr << "Invalid quantity format: " << e.what() << endl;
continue; // Skip this entry if quantity conversion fails
}
i++;
}
}
int add_num;
blue();
cout << "Enter the number of different kinds of products you want to add: " << endl;
reset();
cin >> add_num;
string add[add_num];
int num_prod[add_num];
for (int h = 0; h < add_num; h++) {
cout << "Enter the name of " << h + 1 << " product" << endl;
cin >> add[h];
cout << "Enter the number to add of " << h + 1 << " product" << endl;
cin >> num_prod[h];
}
int h, g;
for (g = 0; g < add_num; g++) {
for (h = 0; h < 499; h++) {
int y = add[g].compare(me[h].name);
if (y == 0) {
me[h].quantity += num_prod[g];
purple();
cout << me[h].name << " --> " << me[h].quantity << endl;
reset();
break;
}
}
if (h == 499) {
red();
cout << "!!" << add[g] << " product is \"NOT FOUND\"!!" << endl;
reset();
}
}
file.close();
// Updating the new stock in the main list (file)
ofstream outFile("DMart.csv");
if (!outFile) {
cerr << "Error: File can't be opened." << endl;
exit(1);
}
int d = 0;
while (d < 499) {
outFile << me[d].name << ',' << me[d].price << ',' << me[d].quantity<< endl;
d++;
}
outFile.close();
return 0;
}
// External integer variable to find the index of the given product in the list
int index;
// Function for finding the index of the particular product
int searching(const string& str, Product me[499]) {
int k, i, ans;
for (i = 0; i < 499; i++) {
k = str.compare(me[i].name);
if (k == 0) {
index = i;
ans = 10;
break;
}
}
if (i == 499) {
ans = 1;
}
return ans;
}
// Function for finding the price of the given product
float find_price(const string& str, Product me[499]) {
int k, i;
float price;
for (i = 0; i < 499; i++) {
k = str.compare(me[i].name);
if (k == 0) {
price = me[i].price;
break;
}
}
return price;
}
// Function for calculating the length of a string
int length_of_name(const string& str) {
return str.length();
}
// Function for billing
int billing() {
ifstream file_1("DMart.csv");
Product me[499];
int i = 0;
if (!file_1) {
cout << "Failed to open the file." << endl;
return 1;
}
string line;
while (i < 499 && getline(file_1, line)) {
istringstream iss(line);
string name, priceStr, quantityStr;
char comma;
if (getline(iss, name, ',') && getline(iss, priceStr, ',') && getline(iss, quantityStr, ',')) {
me[i].name = name;
try {
me[i].price = stof(cleanString(priceStr)); // Clean the "price" string
}
catch (const invalid_argument& e) {
// cerr << "Invalid price format: " << e.what() << endl;
continue; // Skip this entry if price conversion fails
}
try {
me[i].quantity = stoi(cleanString(quantityStr)); // Clean the "quantity" string and convert to int
}
catch (const invalid_argument& e) {
// cerr << "Invalid quantity format: " << e.what() << endl;
continue; // Skip this entry if quantity conversion fails
}
i++;
}
}
string name_customer;
blue();
cout << "Enter the name of the customer: ";
reset();
cin >> name_customer;
int num_prod;
blue();
cout << "Enter the number of different products you need: ";
reset();
cin >> num_prod;
struct Prescription {
string items;
int quant;
};
float billing_amount[num_prod];
Prescription mem[num_prod];
int k;
for (int i = 0; i < num_prod; i++) {
cout << "Enter the name of the " << i + 1 << " product: ";
cin >> mem[i].items;
k = searching(mem[i].items, me);
if (k == 10) {
cout << "Enter the quantity you need: ";
cin >> mem[i].quant;
if (me[index].quantity >= mem[i].quant) {
billing_amount[i] = me[index].price * mem[i].quant;
me[index].quantity -= mem[i].quant;
} else {
red();
cout << mem[i].items << " Products's Stock is not available" << endl;
reset();
billing_amount[i] = 0.00;
}
} else {
red();
cout << mem[i].items << " Product is not available" << endl;
reset();
billing_amount[i] = 0.00;
}
}
float total_amount = 0;
for (int i = 0; i < num_prod; i++) {
total_amount += billing_amount[i];
}
file_1.close();
ofstream outFile("DMart.csv");
if (!outFile) {
cerr << "Error: File can't be opened." << endl;
exit(1);
}
int d = 0;
while (d < 499) {
outFile << me[d].name << ',' << me[d].price << ',' << me[d].quantity<< endl;
d++;
}
outFile.close();
// string nani=name_customer+".txt";
ofstream fp_bill(name_customer);
if (!fp_bill) {
cerr << "Error: File can't be opened." << endl;
exit(1);
}
fp_bill << "'''===================================MSN-MART===================================" << endl;
fp_bill << "Address:";
for (int z = 0; z < 61; z++) {
fp_bill << " ";
}
fp_bill << "DATE: " << __DATE__ << endl;
fp_bill << "MSN-mart,";
for (int z = 0; z < 60; z++) {
fp_bill << " ";
}
fp_bill << "TIME: " << __TIME__ << endl;
fp_bill << "Nagpur," << endl;
fp_bill << "Maharashtra,";
for (int z = 0; z < 57; z++) {
fp_bill << " ";
}
fp_bill << "P.No: 73044 41207" << endl;
fp_bill << "440006." << endl;
for (int z = 0; z < 86; z++) {
fp_bill << "_";
}
fp_bill << endl << endl;
fp_bill << "Name of customer: " << name_customer << endl;
fp_bill << "***** PRODUCTS LIST *****" << endl;
for (int z = 0; z < 22; z++) {
fp_bill << " ";
}
fp_bill << "NAME";
for (int z = 0; z < 22; z++) {
fp_bill << " ";
}
fp_bill << "| QUANTITY | PRICE | SUB_TOTAL" << endl;
int lth;
for (int z = 0; z < num_prod; z++) {
if (billing_amount[z] != 0) {
fp_bill << z + 1 << ") " << mem[z].items;
lth = length_of_name(mem[z].items);
for (int r = 0; r < 45 - lth; r++) {
fp_bill << " ";
}
fp_bill << "|";
fp_bill << " " << mem[z].quant << " |";
fp_bill << " " << find_price(mem[z].items, me) << " |";
fp_bill << " " << (mem[z].quant * find_price(mem[z].items, me)) << " " << endl;
}
fp_bill << endl;
}
for (int s = 0; s < 67; s++) {
fp_bill << " ";
}
fp_bill << "TOTAL: " << total_amount << endl;
for (int d = 0; d < 42; d++) {
fp_bill << "_ ";
}
fp_bill << endl;
for (int y = 0; y < 48; y++) {
fp_bill << " ";
}
fp_bill << "Bill Issued by: - " << provider << endl;
for (int y = 0; y < 31; y++) {
fp_bill << " ";
}
sales++;
amount+=total_amount;
fp_bill << "Thank You for visiting, VISIT AGAIN !!!!!'''" << endl << endl << endl;
fp_bill.close();
ifstream fp_bill_read(name_customer);
char ch;
purple();
cout << "****************************************BILL*****************************************" << endl;
reset();
while (1) {
ch = fp_bill_read.get();
if (fp_bill_read.eof()) {
break;
} else {
cout << ch;
}
}
cout << endl;
return 0;
}
void end_of_program()
{
cout <<"==================================MSN STORES Private Limited=================================" << endl;
cout<<"| |\n";
cout<<"| |\n";
cout<<"| ";
blue();
cout<<"The number of sales done today are "<<sales;
reset();
cout<<" |\n";
cout<<"| ";
purple();
cout<<"The amount earned today is "<<amount;
reset();
cout<<" |\n";
cout<<"| |\n";
cout<<"| |\n";
cout <<"==================================MSN STORES Private Limited=================================" << endl;
}
int main() {
blue();
cout << "==================================WELCOME TO MSN-MART LOGIN PAGE=================================" << endl;
reset();
red();
cout << "!!!***Kindly enter your login details***!!!" << endl;
reset();
int n;
int k = checking();
if (k == 0) {
return 100;
} else {
entry:
int b = 10;
while (b != 0) {
yellow();
cout << "\n1-Stock checking" << endl;
cout << "2-Add a new stock" << endl;
cout << "3-billing" << endl;
reset();
red();
cout << "Enter the input:";
reset();
cin >> n;
if (n == 1) {
stock_checking();
} else if (n == 2) {
adding();
} else if (n == 3) {
billing();
} else {
cout << "Entered an invalid input!!" << endl;
goto entry;
}
blue();
cout << "Enter any number to continue and for exit enter \"0\":" << endl;
reset();
cin >> b;
}
}
end_of_program();
return 0;
}