-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBilling.cpp
More file actions
426 lines (364 loc) · 10.1 KB
/
Billing.cpp
File metadata and controls
426 lines (364 loc) · 10.1 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
#include<iostream>
#include<fstream>
using namespace std;
// creating class and declaring variables
class shopping
{
private:
int pcode;
float price;
float dis;
string pname;
public:
void menu();
void administrator();
void buyer();
void add();
void edit();
void rem();
void list();
void reciept();
};
//menu function
void shopping :: menu()
{
m:
int choice;
string email;
string password;
cout<<"\t\t\t\t______________________________________\n";
cout<<"\t\t\t\t \n";
cout<<"\t\t\t\t Supermarket Main Menu \n";
cout<<"\t\t\t\t \n";
cout<<"\t\t\t\t______________________________________\n";
cout<<"\t\t\t\t \n";
//menu to select whether the user is Administrator or buyer
cout<<"\t\t\t\t| 1) Administrator |\n";
cout<<"\t\t\t\t| |\n";
cout<<"\t\t\t\t| 2) Buyer |\n";
cout<<"\t\t\t\t| |\n";
cout<<"\t\t\t\t| 3) Exit |\n";
cout<<"\t\t\t\t| |\n";
cout<<"\t\t\t\t Please select! ";
cin>>choice;
// for making choice among choices
switch(choice)
{
case 1:
cout<<"\t\t\t Please Login \n";
cout<<"\t\t\t Enter Email \n";
cin>>email;
cout<<"\t\t\t Enetr Password \n";
cin>>password;
//condition for only admin login(setting password if it is admin)
if(email=="varsha@email.com" && password=="varsha@123")
{
administrator();
}
else{
cout<<"Invalid Email/Password";
}
break;
case 2: {
buyer();
}
case 3:
{
exit(0);
}
break;
default:
{
cout<<"Please Select from the given option";
}
}
//goto is a jump statement so it will help in jumping on the main menu again
goto m;
}
//administrator function
void shopping :: administrator()
{
m:
int choice;
cout<<"\n\n\n\t\t\t Administrator Menu";
cout<<"\n\t\t\t |________1) Add the Product___________|";
cout<<"\n\t\t\t | |";
cout<<"\n\t\t\t |________2) Modify the Product________|";
cout<<"\n\t\t\t | |";
cout<<"\n\t\t\t |________3) Delete the Product________|";
cout<<"\n\t\t\t | |";
cout<<"\n\t\t\t |________4) Back to Main Menu________ |";
cout<<"\n\n\tPlease Enter your choice";
cin>>choice;
switch(choice)
{
case 1:
add();
break;
case 2:
edit();
break;
case 3:
rem();
break;
case 4:
menu();
break;
default:
cout<<"Invalid Choice";
}
goto m;
}
//buyer function
void shopping :: buyer()
{
m:
int choice;
cout<<"\t\t\t Buyer \n";
cout<<"_____________________ \n";
cout<<" \n";
cout<<"\t\t\t 1) Buy Product \n";
cout<<" \n";
cout<<"\t\t\t 2) Go Back \n";
cout<<"\t\t\t Enter your choice";
cin>>choice;
switch(choice)
{
case 1:
reciept();
break;
case 2:
menu();
break;
default:
cout<<"Invalid Choice";
}
goto m;
}
//add function- using some file handling operations
void shopping :: add()
{
m:
fstream data;
int c;
int token=0;
float p;
float d;
string n;
cout<<"\n\n\t\t\t Add new Product";
cout<<"\n\n\t Product code of the product ";
cin>>pcode;
cout<<"\n\n\t Name of the Product";
cin>>pname;
cout<<"\n\n\t Price of the Product";
cin>>price;
cout<<"\n\n\t Discount on the Product";
cin>>dis;
data.open("database.txt", ios::in); //ios::in will open the file in reading mode and ios::out will open the file in writing mode
if(!data) //if the file do not exist
{
data.open("database.txt", ios::app |ios::out); //ios::app stands for append mode
data<<" "<<pcode<<" "<<pname<<" "<<price<<" "<<dis<<"\n";
data.close();
}
else{ // if the file exist
data>>c>>n>>p>>d; //read from the file here we are initializing the index of file cause after this we have to use the while loop to iterate through this file
while(data >> c >> n >> p >> d)
{
if(c == pcode)
{
token++;
}
}
data.close();
if(token==1) //if there is a duplicacy then it will go back to the menu
goto m;
else{ // if the token value is not incremented or if the product code is unique
data.open("database.txt", ios::app |ios::out); //ios::app stands for append mode
data<<" "<<pcode<<" "<<pname<<" "<<price<<" "<<dis<<"\n";
data.close();
}
}
cout<<"\n\n\t\t Record inserted!";
system("pause");
return;
}
//edit function
void shopping :: edit()
{
fstream data, data1; //2 objects of fstream class
int pkey;
int token = 0;
int c;
float p;
float d;
string n;
cout<<"\n\n\t\t Modify the Record";
cout<<"\n\n\t\t Enter the product code : ";
cin>>pkey;
data.open("database.txt",ios::in);
if(!data)
{
cout<<"\n\n File does not exist! ";
}
else{
data1.open("database1.txt", ios::app | ios::out);
data>>pcode>>pname>>price>>dis;
while(data >> pcode >> pname >> price >> dis)
{
if(pkey==pcode)
{
cout<<"\n\t\t Products new code";
cin>>c;
cout<<"\n\n\t Name of theProduct";
cin>>n;
cout<<"\n\n\t Price of the Product";
cin>>p;
cout<<"\n\n\t discount";
cin>>d;
data1<<" "<<c<<" "<<n<<" "<<p<<" "<<d<<"\n";
cout<<"\n\n\t Record edited!";
token++;
}
else{
data1<<" "<<pcode<<" "<<pname<<" "<<price<<" "<<dis<<"\n";
}
data>>pcode>>pname>>price>>dis;
}
data.close();
data1.close();
remove("database.txt");
rename("database1.txt", "database.txt");
if(token==0)
{
cout<<"\n\t\t Record not found !";
}
}
}
//remove function
void shopping :: rem()
{
fstream data, data1;
int pkey;
int token=0;
cout<<"\n\t\t Delete Product";
cout<<"\n\n\t Enter the product code ";
cin>>pkey;
data.open("database.txt", ios::in);
if(!data)
{
cout<<"\n\t\t File does not exist ! ";
}
else{
data1.open("database1.txt", ios::app|ios::out);
data>>pcode>>pname>>price>>dis;
while(data >> pcode >> pname >> price >> dis)
{
if(pcode==pkey)
{
cout<<"\n\n\t Product deleted successfully";
token++;
}
else{
data1<<" "<<pcode<<" "<<pname<<" "<<price<<" "<<dis<<"\n";
}
data>>pcode>>pname>>price>>dis;
}
data.close();
data1.close();
remove("database.txt");
rename("database1.txt","database.txt");
if (token==0)
{
cout<<"\n\n Record can not be found !";
}
}
}
void shopping :: list()
{
fstream data;
data.open("database.txt", ios::in);
cout<<"\n\n______________________________________________\n";
cout<<"ProNo<<\t\t Name\t\t Price\n";
cout<<"\n\n______________________________________________\n";
data>>pcode>>pname>>price>>dis;
while(data >> pcode >> pname >> price >> dis)
{
cout<<pcode<<"\t\t"<<pname<<"\t\t"<<price<<"\t\t"<<"\n";
data>>pcode>>pname>>price>>dis;
}
data.close();
}
//reciept function
void shopping :: reciept()
{
fstream data;
int arrc[100];
int arrq[100];
char choice;
int c=0;
float amount=0;
float dis=0;
float total=0;
cout<<"\n\n\t\t\t\t RRECIEPT ";
data.open("database.txt", ios::in);
if(!data)
{
cout<<"\n\n Empty database";
}
else{
data.close();
list();
cout<<"\n____________________________________________\n";
cout<<"\n| \n";
cout<<"\n Please palce the order \n";
cout<<"\n| \n";
cout<<"\n____________________________________________\n";
do
{
m:
cout<<"\n\n Enter Product code :";
cin>>arrc[c];
cout<<"\n\n Enter the quantity :";
cin>>arrq[c];
for(int i=0; i<c; i++)
{
if(arrc[c]==arrc[i])
{
cout<<"\n\n Duplicate Product code. PLease try again!";
goto m;
}
}
c++;
cout<<"\n\n Do you want to buy another product? if yes press y else n if no.";
cin>>choice;
}
while (choice =='y');
cout<<"\n\n\t\t\t_________________________________RECIEPT___________________________________\n";
cout<<"\n Product No \t Product Name \t Quantity \t Price \t Amount \t Amount after Discount\n";
for(int i=0; i<c; i++)
{
data.open("database.txt", ios::in);
while(data >> pcode >> pname >> price >> dis)
{
if(pcode == arrc[i])
{
amount = price * arrq[i];
float discountAmount = amount - (amount * dis / 100);
total = total + discountAmount;
cout<<"\n"<<pcode<<"\t\t"<<pname<<"\t\t"<<arrq[i]
<<"\t\t"<<price<<"\t\t"<<amount
<<"\t\t"<<discountAmount;
}
}
data.close();
}
cout<<"\n\n__________________________________________________________________";
cout<<"\n Total amount :"<<total;
}
}
int main()
{
shopping s;
s.menu();
}