-
Notifications
You must be signed in to change notification settings - Fork 0
/
MEDICINE STOREMANAGEMENT.CPP
530 lines (491 loc) · 13 KB
/
MEDICINE STOREMANAGEMENT.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
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
#include<iostream>
#include<string.h>
#include<vector>
#include<conio.h>
#include<math.h>
#include<fstream>
#include<stdlib.h>
#include<stdio.h>
#include<iomanip>
#include<windows.h>
using namespace std;
int i,n;
ifstream fin1,fin2;
ofstream fout1,fout2;
fstream fio;
class utility
{
public:
void addnew();
void disp();
void refill();
friend void remove();
void withdraw();
};
class medicine:public utility
{
char name[20],pass[10];
float pr;
int quant;
public:
void get();
void get2();
void show();
int stchk(char nm[30]);
void withd(int qty);
void refil(int qty);
} st;
void medicine::withd(int qty)
{
if(quant>=qty)
{
quant-=qty;
cout<<"\n\nStock updated.\n";
cout<<"\n\nTotal price to be paid : "<<pr<<"*"<<qty<<" = "<<pr*qty;
}
else{
cout<<"\n\nInsufficient stock";
}
getch();
}
void medicine::refil(int qty)
{
quant+=qty;
cout<<"\n\nStock updated.";
getch();
}
int medicine::stchk(char nm[30])
{
if(strcmp(nm,name)==0)
return 0;
else
return 1;
}
void medicine::get()
{
cout<<"Enter the Name of the Medicine --->\t\t"<<setw(10);
cin>>name;
cout<<"Enter the Price of the Medicine --->\t\t"<<setw(10);
cin>>pr;
cout<<"Enter the quantity of the Medicine --->\t\t"<<setw(10);
cin>>quant;
vector<int>v;
int w=0;
for(int i=0;i<quant;i++){
v.push_back(pr);
w=w+v[i];
}
cout<<endl<<"Your total Medical Bill Is :"<<endl<<w<<"Rs";
}
void medicine::get2()
{
cin>>name>>quant;
}
void medicine::show()
{
cout.setf(ios::left,ios::adjustfield);
cout.setf(ios::fixed,ios::floatfield);
cout<<"\n\t* "<<setw(15)<<name<<"\t\t "<<setw(15)<<quant<<setprecision(2)<<"\t"<<"Rs. "<<pr<<"/-\n";
}
void utility::addnew()
{
system("cls");
disp();
getch();
system("cls");
cout<<"\nEnter the No. of Products that you wish to add: ";
cin>>n;
if (n!=0)
{
int j,l,sum=0;
fout1.open("shop.dat",ios::binary|ios::app);
for(i=0; i<n; i++)
{
cout<<"\n\nEnter the details of item no. "<<i+1<<"\n\n";
st.get();
fout1.write((char*)&st,sizeof(st));
cout<<"\n\nItem Updated!";
cin.get();
}
cout<<"\n\nStock Updated!!";
fout1.close();
cin.get();
system("cls");
st.disp();
}
else
{
fout1.close();
cin.get();
system("cls");
cout<<"\n\nNo items to be added";
}
}
void utility::withdraw()
{
system("cls");
char temp[100];
int qty;
int count=0;
long pos=0;
st.disp();
cout<<"\n\nEnter the product's name to be purchased : \n"<<endl;
cin>>temp;
cout<<"\n\nHow much quantity you want to buy : \n"<<endl;
cin>>qty;
fio.open("shop.dat",ios::binary|ios::out|ios::in);
while(fio)
{
pos=fio.tellp();
fio.read((char*)&st,sizeof(st));
if(st.stchk(temp)==0)
{
st.withd(qty);
fio.seekp(pos);
fio.write((char*)&st,sizeof(st));
count=1;
break;
}
}
if(count!=1)
{
cout<<"\n\n!!Record not found!!";
getch();
}
fio.close();
cin.get();
system("cls");
st.disp();
}
void utility::disp()
{
int i=1;
cout<<"\n================================================================================";
cout<<"\n\n\t================\tTHE STOCK ITEMS ARE\t==============";
cout<<"\n\n\t==============================================================\n";
cout<<"\n\n MEDICINE NAME\t\t STOCK AVAILABLE\t PRICE(per piece)";
cout<<"\n\n ======================================================================\n";
fin1.open("shop.dat",ios::binary);
while(!fin1.eof())
{
fin1.read((char*)&st,sizeof st);
if(!fin1.eof())
{
if(fin1.tellg()<0)
{
i=0;
break;
}
st.show();
}
}
cout<<"\n\n ======================================================================\n\n\n";
if(i==0)
{
cout<<"\n\n\t\t\t!!Empty record room!!";
getch();
}
fin1.close();
}
void utility::refill()
{
system("cls");
char temp[100];
int qty;
int i=0;
long pos=0;
st.disp();
cout<<"\n\nEnter the products name \n"<<endl;
cin>>temp;
cout<<"\n\nEnter quantity: \n"<<endl;
cin>>qty;
fio.open("shop.dat",ios::binary|ios::out|ios::in);
while(fio)
{
pos=fio.tellp();
fio.read((char*)&st,sizeof st);
if(st.stchk(temp)==0)
{
st.refil(qty);
fio.seekp(pos);
fio.write((char*)&st,sizeof(st));
i++;
break;
}
}
if(i!=1)
{
cout<<"\n\n!!Record not found!!";
getch();
}
fio.close();
system("cls");
cin.get();
st.disp();
cin.get();
}
void remove()
{
system("cls");
int i=0;
char temp[30];
cout<<"\n\n\n\t\t\t\tDELETE RECORD";
cout<<"\n\n================================================================================\n";
cout<<"================================================================================\n\n";
st.disp();
cout<<"\n\nEnter the name of the product to be deleted : ";
cin>>temp;
fout2.open("tmp.dat",ios::binary|ios::out);
fin1.open("shop.dat",ios::binary|ios::in);
while(!fin1.eof())
{
fin1.read((char*)&st,sizeof(st));
if(!fin1.eof())
if(st.stchk(temp)==0)
{
st.show();
cout<<"\n\n\t\tRecord deleted";
i++;
}
else
fout2.write((char*)&st,sizeof(st));
}
if(i==0)
cout<<"\n\n!!Record not found!!";
fin1.close();
fout2.close();
remove("shop.dat");
int res=rename("tmp.dat","shop.dat");
if ( res == 0 )
puts ( "File successfully renamed" );
else
perror( "Error renaming file" );
getch();
}
int main()
{
vector<int>v;
int k=12;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, k);
char pass[10],pass2[10];
int i,j;
cout<<"\n\n\n\n\n\t\t\t |====================== WELCOME ======================|";
cout<<"\n\n\n\n\n\t\t\t!==================== JANTA MEDICAL STORE ====================!";
getch();
mainmenu:
system("cls");
k=10;
SetConsoleTextAttribute(hConsole, k);
cout<<"\n\n\n\n \t\t\t|============";
_sleep(400);
cout<<" WELCOME ";
_sleep(400);
cout<<" TO ";
_sleep(400);
cout<<"MEDICAL";
_sleep(400);
cout<<" STOREMANAGEMENT";
_sleep(400);
cout<<"============|"<<"\n";
_sleep(400);
getch();
system("cls");
for (int j = 0; j < 1; j++)
{
cout<<setw(18)<<"\r\t\t\t\t\t\tLoading";
for (int i = 0; i <7; i++)
{
cout << ".";
_sleep(100);
}
}
//cout<<"\t===========================================";
cout<<"\n\n\t\t\t 1. Dealer Menu\n\n\t\t\t 2. Customer Menu\n\n\t\t\t 3. Employee Menu\n\n\t\t\t 4. Exit";
cout<<"\n\n\t=============================================================\n";
cout<<"\n\nEnter Your Choice:";
cin>>j;
if(j==1)
{
int k=11;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, k);
system("cls");
cout<<"\n\n\n\n\nEnter the password letter by letter: ";
for(int z=0; z<6; z++)
{
pass[z]=getch();
system("cls");
cout<<"\n\n\n\n\n\n\nEnter the password letter by letter: ";
for(i=1; i<=(z+1); i++)
{
cout<<"*";
}
}
getch();
if(strncmp(pass,"dealer",6)== 0)
{
cout<<"\n\n\n\n\n\n\t\t Congrats!! Access Granted!!\n\n";
getch();
system("cls");
dealermenu:
system("cls");
cout<<"================================================================================";
cout<<"\n\n\t\t\t\t DEALER MENU\n\n 1. Add new product\n 2. Display stock\n 3. Refill Stock\n 4. Remove an item\n 5. Home\n 6. Exit";
cout<<"\n\n\n=================================END OF MENU====================================";
cout<<"\n\n Enter your Choice :\t";
cin>>i;
if(i==1)
{
st.addnew();
getch();
goto dealermenu;
}
else if(i==2)
{
system("cls");
st.disp();
getch();
goto dealermenu;
}
else if(i==3)
{
st.refill();
goto dealermenu;
}
else if(i==4)
{
remove();
getch();
goto dealermenu;
}
else if(i=5)
{
goto mainmenu;
}
else
{
cout<<"\n\n\t\t\tThank You!";
getch();
exit(0);
}
}
else
{
cout<<"\n\n\n\n\n\t\t\t\t WRONG PASSWORD!\n\n\t\t\t Only Authorized Personnel Allowed!\n\n";
getch();
exit(0);
}
}
else if(j==2)
{
int k=13;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, k);
custmenu:
system("cls");
cout<<"================================================================================";
cout<<"\n\n\t\t\t\t CUSTOMER MENU\n\n 1. Purchasing\n 2. Display stock\n 3. Home Screen\n 4. Exit";
cout<<"\n\n\n=================================END OF MENU====================================";
cout<<"\n\n Enter your Choice :\t";
cin>>i;
if (i==1)
{
st.withdraw();
getch();
goto custmenu;
}
else if(i==2)
{
system("cls");
st.disp();
getch();
goto custmenu;
}
else if(i==3)
{
goto mainmenu;
}
else
{
cout<<"\n\n\t\t\tThank You!";
getch();
exit(0);
}
}
else if(j==3)
{
int k=14;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, k);
system("cls");
cout<<"\n\n\n\n\nEnter the password letter by letter: ";
for(int z=0; z<3; z++)
{
pass[z]=getch();
system("cls");
cout<<"\n\n\n\n\n\n\nEnter the password letter by letter: ";
for(i=1; i<=(z+1); i++)
{
cout<<"*";
}
}
getch();
if(strncmp(pass,"emp",3)== 0)
{
cout<<"\n\n\n\n\n\n\t\t Congrats!! Access Granted!!\n\n";
getch();
system("cls");
empmenu:
system("cls");
cout<<"================================================================================";
cout<<"\n\n\t\t\t\t EMPLOYEE MENU\n\n 1. Refill stock\n 2. Display Stock\n 3. Home Screen\n 4. Exit";
cout<<"\n\n\n=================================END OF MENU====================================";
cout<<"\n\n Enter your Choice :\t";
cin>>i;
if(i==1)
{
st.refill();
goto empmenu;
}
if(i==2)
{
system("cls");
st.disp();
getch();
goto empmenu;
}
else if(i==3)
{
goto mainmenu;
}
else
{
system("cls");
cout<<"\n\n\n\t\t\tThank You!!";
getch();
exit(0);
}
}
else
{
cout<<"\n\n\n\n\n\t\t\t\t WRONG PASSWORD!\n\n\t\t\t Only Authorized Personnel Allowed!\n\n";
getch();
exit(0);
}
}
else if(j==4)
{
system("cls");
cout<<"\n\n\n\n\n\n\t\t\t\tThank You!!";
getch();
exit(0);
}
else
{
/*cout<<"\n\nSorry!! Access Denied..\n\n";
getch();*/
goto mainmenu;
}
getch();
}