-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSBS.cpp
374 lines (358 loc) · 7.43 KB
/
SBS.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
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
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 receipt();
};
void shopping :: menu()
{
m:
int choice;
string email;
string password;
cout<<"\t\t\t\t__________________________________________\n\n";
cout<<"\t\t\t\t Supermarket Main Menu \n\n";
cout<<"\t\t\t\t__________________________________________\n\n";
cout<<"\t\t\t\t\t| 1) Administrator |\n";
cout<<"\t\t\t\t\t| |\n";
cout<<"\t\t\t\t\t| 2) Buyer |\n";
cout<<"\t\t\t\t\t| |\n";
cout<<"\t\t\t\t\t| 3) Exit |\n";
cout<<"\t\t\t\t\t| |\n";
cout<<"\n\t\t\tPlease select! ";
cin>>choice;
switch(choice)
{
case 1:
{
cout<<"\n\n\t\t\tPlease login. \n";
cout<<"\t\t\tEnter Email address. ";
cin>>email;
cout<<"\t\t\tPassword. ";
cin>>password;
if(email=="project@gmail.com"&& password=="zero@123")
{
administrator();
}
else
{
cout<<"\t\t\tInvalid Email/Password.\n";
}
break;
}
case 2:
{
buyer();
}
case 3:
{
exit(0);
}
default:
{
cout<<"Please select from the given option";
}
}
goto m;
}
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________________|";
cout<<"\n\n\t Please 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;
}
void shopping::buyer()
{
m:
int choice;
cout<<"\t\t\t________________\n\n";
cout<<"\t\t\t 1) Buy product \n\n";
cout<<"\t\t\t 2) Go back \n\n";
cout<<"\t\t\t Enter your choice:";
cin>>choice;
switch(choice)
{
case 1:
{
receipt();
break;
}
case 2:
{
menu();
break;
}
default:
{
cout<<"Invalid choice";
break;
}
}
goto m;
}
void shopping :: add()
{
m:
fstream data;
int c;
int token=0;
float p;
float d;
string n;
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);
if(!data)
{
data.open("database.txt",ios::app|ios::out);
data<<" "<<pcode<<" "<<pname<<" "<<price<<" "<<dis<<"\n";
data.close();
}
else
{
data>>c>>n>>p>>d;
while(!data.eof())
{
if (c ==pcode)
token++;
data>>c>>n>>p>>d;
}
data.close();
if(token==1)
goto m;
else{
data.open("database.txt", ios:: app|ios:: out);
data<<" "<<pcode<<" "<<pname<<" "<<price<<" "<<dis<<"\n";
data.close();
}
}
cout<<"\n\n\t\t\tRecord inserted !";
}
void shopping ::edit()
{
fstream data, data1;
int pkey;
int token=0;
int c;
float p;
float d;
string n;
cout<<"\n\t\t\t Modify the record! ";
cout<<"\n\t\t\t Product code:";
cin>>pkey;
data.open("database.txt",ios::in);
if(!data)
cout<<"\n\nFile doesnot exist!";
else{
data1.open("database1.txt",ios::app|ios::out);
data>>pcode>>pname>>price>>dis;
while(!data.eof())
{
if(pkey==pcode)
{
cout<<"\n\t\t Product new code :";
cin>>c;
cout<<"\n\t\t Name of the product :";
cin>>n;
cout<<"\n\t\t Price:";
cin>>p;
cout<<"\n\t\t Discount :";
cin>>d;
data1<<" "<<c<<" "<<n<<" "<<p<<" "<<d<<"\n";
cout<<"\n\n\t\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\n\t\t\tRecord not found sorry!";
}
}
}
void shopping::rem()
{
fstream data,data1;
int pkey;
int token=0;
cout<<"\n\n\t Delete product";
cout<<"\n\n\t Product code:";
cin>>pkey;
data.open("database.txt",ios::in);
if(!data)
{
cout<<"File doesnot exist.";
}
else{
data1.open("database1.txt",ios::app|ios::out);
data>>pcode>>pname>>price>>dis;
while(!data.eof())
{
if(pcode==pkey)
{
cout<<"\n\n\tProduct deleted succesfully";
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 not found";
}
}
}
void shopping::list()
{
fstream data;
data.open("database.txt",ios::in);
cout<<"\n\n|______________________________________________________________________________\n";
cout<<"ProNo\t\t\t\tName\t\t\t\tPrice\n";
cout<<"\n\n|______________________________________________________________________________\n";
data>>pcode>>pname>>price>>dis;
while(!data.eof())
{
cout<<pcode<<setw(35)<<pname<<setw(32)<<price<<"\n";
data>>pcode>>pname>>price>>dis;
}
data.close();
}
void shopping::receipt()
{
fstream data;
int arrc[100];
int arrq[100];
int c=0;
float amount=0;
float dis=0;
float total=0;
char choice;
data.open("database.txt",ios::in);
if(!data)
cout<<"\n\nEmpty database";
else{
data.close();
list();
cout<<"\n__________________________________________\n";
cout<<"\n \n";
cout<<"\n Please place 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 product 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 then y else n.";
cin>>choice;
}
while(choice == 'y');
cout<<"\n\n_______________________________________________________RECEIPT_________________________________________________________________\n";
cout<<"\nProduct No\t\t Product Name\t\t Product Quantity\t Price \tAmount \tAmount with disount\n";
for(int i=0;i<c;i++)
{
data.open("database.txt",ios::in);
data>>pcode>>pname>>price>>dis;
while(!data.eof())
{
if(pcode==arrc[i])
{
amount=price*arrq[i];
dis=amount-(amount*dis/100);
total=total+dis;
cout<<"\n"<<pcode<<setw(35)<<pname<<setw(25)<<arrq[i]<<setw(17)<<price<<setw(14)<<amount<<setw(24)<<dis;
}
data>>pcode>>pname>>price>>dis;
}
data.close();
}
}
cout<<"\n_______________________________________________________________________________________________________________________________";
cout<<"\n Total Amount:"<<total;
}
int main()
{
shopping s;
s.menu();
}