-
Notifications
You must be signed in to change notification settings - Fork 0
/
pro_final.cpp
1127 lines (1040 loc) · 28.3 KB
/
pro_final.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
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
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#include<stdio.h>
using namespace std;
fstream fp;
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); // used for goto
COORD CursorPosition; // used for goto
void gotoXY(int x, int y)
{
CursorPosition.X = x;
CursorPosition.Y = y;
SetConsoleCursorPosition(console,CursorPosition);
}
#define V 9
// A utility function to find the vertex with minimum distance value, from
// the set of vertices not yet included in shortest path tree
int minDistance(int dist[], bool sptSet[])
{
// Initialize min value
int min = INT_MAX, min_index;
for (int v = 0; v < V; v++)
if (sptSet[v] == false && dist[v] <= min)
min = dist[v], min_index = v;
return min_index;
}
// A utility function to print the constructed distance array
int printSolution(int dist[])
{
int a[V][2];
for (int i = 0; i < V; i++)
{
a[i][0]=201304+i;
a[i][1]=dist[i];
}
cout<<"available pin code for delivery\n";
int j;
for(j=0;j<V;j++)
{
cout<<a[j][0];
cout<<" estimated delivery date for each pin code is "<<a[j][1]<<"\n";
}
int p;
cout<<"Enter your adderess pin code\n";
cin>>p;
for(j=0;j<V;j++)
{
if(a[j][0]==p)
{
cout<<"your order is placed and will be delivered within "<<a[j][1]<<" working days on pin code "<<a[j][0];
break;
}
}
}
// Function that implements Dijkstra's single source shortest path algorithm
// for a graph represented using adjacency matrix representation
void dijkstra(int graph[V][V], int src)
{
int dist[V]; // The output array. dist[i] will hold the shortest
// distance from src to i
bool sptSet[V]; // sptSet[i] will be true if vertex i is included in shortest
// path tree or shortest distance from src to i is finalized
// Initialize all distances as INFINITE and stpSet[] as false
for (int i = 0; i < V; i++)
dist[i] = INT_MAX, sptSet[i] = false;
// Distance of source vertex from itself is always 0
dist[src] = 0;
// Find shortest path for all vertices
for (int count = 0; count < V - 1; count++) {
// Pick the minimum distance vertex from the set of vertices not
// yet processed. u is always equal to src in the first iteration.
int u = minDistance(dist, sptSet);
// Mark the picked vertex as processed
sptSet[u] = true;
// Update dist value of the adjacent vertices of the picked vertex.
for (int v = 0; v < V; v++)
// Update dist[v] only if is not in sptSet, there is an edge from
// u to v, and total weight of path from src to v through u is
// smaller than current value of dist[v]
if (!sptSet[v] && graph[u][v] && dist[u] != INT_MAX
&& dist[u] + graph[u][v] < dist[v])
dist[v] = dist[u] + graph[u][v];
}
// print the constructed distance array
printSolution(dist);
}
class Products
{
int product_id;
float price;
string brand_name;
int eligible_for_cod;
string seller_name;
int quantity;
float discount;
public:
Product()
{
product_id=0;
price=0;
brand_name="NULL";
eligible_for_cod=0;
seller_name="NULL";
}
int return_product_id()
{
return product_id;
}
int return_price()
{
return price;
}
string return_bname()
{
return brand_name;
}
string return_sname()
{
return seller_name;
}
int return_eligible_for_cod()
{
return eligible_for_cod;
}
int return_quantity()
{
return quantity;
}
float return_discount()
{
return discount;
}
void get_product_details()
{
cout<<"Enter Product Id:\n";
cin>>product_id;
cout<<"Enter Price of the product:\n";
cin>>price;
cout<<"Enter the quantity required of the desired product:\n";
cin>>quantity;
cout<<"Enter Brand Name:\n";
cin>>brand_name;
cout<<"Enter Seller's Name:\n";
cin>>seller_name;
cout<<"Should the product be eligible for cash on delivery?(0 (for no)/ 1(for yes)):\n";
cin>>eligible_for_cod;
cout<<"Enter dicount percentage availed on this product:\n";
cin>>discount;
}
void show_product_details()
{
cout<<"Product Id:"<<product_id<<endl;
cout<<"Price of the product:"<<price<<endl;
cout<<"Quantity Demanded:"<<quantity<<endl;
cout<<"Brand Name:"<<brand_name<<endl;
cout<<"Seller's Name:"<<seller_name<<endl;
if(eligible_for_cod==0)
cout<<"Product demanded is not eligible for cod"<<endl;
else cout<<"Product is eligible for cod"<<endl;
cout<<"Discount given:"<<discount;
}
};
class Mobile: public Products
{
string Performance;
int FrontCamera;
int RearCamera;
int Touch_avail;
string Security_Connectivity;
public:
Mobile()
{
Performance="NULL";
FrontCamera=0;
RearCamera=0;
Touch_avail=0;
Security_Connectivity="NULL";
}
string return_Performance()
{
return Performance;
}
string return_Security_Connectivity()
{
return Security_Connectivity;
}
int return_RearCamera()
{
return RearCamera;
}
int return_FrontCamera()
{
return FrontCamera;
}
int return_Touch_avail()
{
return Touch_avail;
}
void get_data()
{
get_product_details();
cout<<"Enter Performance:\n";
cin>>Performance;
cout<<"Enter specifications for front camera (MP mega pixels):\n";
cin>>FrontCamera;
cout<<"Enter specifications for rear camera (MP mega pixels):\n";
cin>>RearCamera;
cout<<"Touch required (Enter 0 for no and 1 for yes):\n";
cin>>Touch_avail;
cout<<"Enter other Security and connections preferred:\n";
cin>>Security_Connectivity;
}
void show_data()
{
show_product_details();
cout<<"Performance:"<<Performance<<endl;
cout<<"Front Camera(MP):"<<FrontCamera<<endl;
cout<<"Rear Camera(MP):"<<RearCamera<<endl;
if(Touch_avail==0)
cout<<"Youch is not available for this device"<<endl;
else cout<<"Touch is available for the device"<<endl;
cout<<"Security and Connectivity:"<<Security_Connectivity<<endl;
}
};
class Kids_Clothing: public Products
{
int Age;
string PlazzoSet_Style;
string AnarkaliSuit_Style;
string DhotiKurta_Style;
string ShirtJean_Style;
public:
Kids_Clothing()
{
Age=0;
PlazzoSet_Style="NULL";
AnarkaliSuit_Style="NULL";
DhotiKurta_Style="NULL";
ShirtJean_Style="NULL";
}
int return_Age()
{
return Age;
}
string return_PlazzoSet_Style()
{
return PlazzoSet_Style;
}
string return_AnarkaliSuit_Style()
{
return AnarkaliSuit_Style;
}
string return_DhotiKurta_Style()
{
return DhotiKurta_Style;
}
string return_ShirtJean_Style()
{
return ShirtJean_Style;
}
void get_data()
{
get_product_details();
cout<<"Enter NIL if you don't want to purchase the product"<<endl;
cout<<"Enter PlazzoSet style:\n";
cin>>PlazzoSet_Style;
cout<<"Enter Anarkali Suit type:\n";
cin>>AnarkaliSuit_Style;
cout<<"Enter Dhoti Kurta Type:\n";
cin>>DhotiKurta_Style;
cout<<"Enter Shirt Jean combo Type:\n";
cin>>ShirtJean_Style;
}
void show_data()
{
show_product_details();
cout<<"Plazzo-Set:"<<PlazzoSet_Style<<endl;
cout<<"Anarkali Suit:"<<AnarkaliSuit_Style<<endl;
cout<<"Dhoti Kurta:"<<DhotiKurta_Style<<endl;
cout<<"Shirt Jean Combo:"<<ShirtJean_Style<<endl;
}
};
class Gardening_Products: public Products
{
string Seed_Type;
string Indoor_Plants_Type;
string Wind_Chimes_Type;
string BarbequeGrills_Type;
string Solar_Lights_Type;
public:
Gardening_Products()
{
Seed_Type="NULL";
Indoor_Plants_Type="NULL";
Wind_Chimes_Type="NULL";
BarbequeGrills_Type="NULL";
Solar_Lights_Type="NULL";
}
string return_Seed_Type()
{
return Seed_Type;
}
string return_Indoor_Plants_Type()
{
return Indoor_Plants_Type;
}
string return_Wind_Chimes_Type()
{
return Wind_Chimes_Type;
}
string return_BarbequeGrills_Type()
{
return BarbequeGrills_Type;
}
string return_Solar_Lights_Type()
{
return Solar_Lights_Type;
}
void get_data()
{
get_product_details();
cout<<"Enter NIL if you don't want to purchase the product"<<endl;
cout<<"Enter Seed Type:\n";
cin>>Seed_Type;
cout<<"Enter Indoor Plants Type:\n";
cin>>Indoor_Plants_Type;
cout<<"Enter Wind Chimes Type:\n";
cin>>Wind_Chimes_Type;
cout<<"Enter Barbeque Grills Type:\n";
cin>>BarbequeGrills_Type;
cout<<"Enter Solar Lights Type:\n";
cin>>Solar_Lights_Type;
}
void show_data()
{
show_product_details();
cout<<"Seed:"<<Seed_Type<<endl;
cout<<"Indoor Plants:"<<Indoor_Plants_Type<<endl;
cout<<"Wind Chimes:"<<Wind_Chimes_Type<<endl;
cout<<"Barbeque Grills:"<<BarbequeGrills_Type<<endl;
cout<<"Solar Lights:"<<Solar_Lights_Type<<endl;
}
};
Mobile m;
Kids_Clothing k;
Gardening_Products g;
class Customer
{
string name;
long phone_number;
string address;
int pincode;
public:
void get_info()
{
cout<<"Enter Name:\n";
cin>>name;
cout<<"Enter Phone Number\n:";
cin>>phone_number;
cout<<"Enter Address:";
cin>>address;
cout<<"Enter Area pincode:";
cin>>pincode;
}
void show_info()
{
cout<<"Name:"<<name<<endl;
cout<<"Phone Number:"<<phone_number<<endl;
cout<<"Address:"<<address<<endl;
cout<<"Pincode:"<<pincode<<endl;
}
void place_order(char a[20]);
};
void menu(char a[20])
{
//clrscr();
fp.open(a,ios::in);
if(strcmp(a,"ShopifyKids.dat")==0)
{
if(!fp)
{
cout<<"ERROR!!! FILE COULD NOT BE OPEN\n\n\n Go To Admin Menu to create File";
cout<<"\n\n\n Program is closing ....";
getch();
exit(0);
}
cout<<"\n\n\t\tProduct MENU\n\n";
cout<<"====================================================\n";
cout<<"P.NO.\t\tNAME\t\tPRICE\n";
cout<<"====================================================\n";
while(fp.read((char*)&k,sizeof(k)))
{
cout<<k.return_product_id()<<"\t\t"<<k.return_bname()<<"\t\t"<<k.return_price()<<endl;
}
fp.close();
}
else if(strcmp(a,"ShopifyGarden.dat")==0)
{
if(!fp)
{
cout<<"ERROR!!! FILE COULD NOT BE OPEN\n\n\n Go To Admin Menu to create File";
cout<<"\n\n\n Program is closing ....";
getch();
exit(0);
}
cout<<"\n\n\t\tProduct MENU\n\n";
cout<<"====================================================\n";
cout<<"P.NO.\t\tNAME\t\tPRICE\n";
cout<<"====================================================\n";
while(fp.read((char*)&g,sizeof(g)))
{
cout<<g.return_product_id()<<"\t\t"<<g.return_bname()<<"\t\t"<<g.return_price()<<endl;
}
fp.close();
}
else if(strcmp(a,"ShopifyMobile.dat")==0)
{
if(!fp)
{
cout<<"ERROR!!! FILE COULD NOT BE OPEN\n\n\n Go To Admin Menu to create File";
cout<<"\n\n\n Program is closing ....";
getch();
exit(0);
}
cout<<"\n\n\t\tProduct MENU\n\n";
cout<<"====================================================\n";
cout<<"P.NO.\t\tNAME\t\tPRICE\n";
cout<<"====================================================\n";
while(fp.read((char*)&m,sizeof(m)))
{
cout<<m.return_product_id()<<"\t\t"<<m.return_bname()<<"\t\t"<<m.return_price()<<endl;
}
fp.close();
}
}
void Customer::place_order(char a[20]){
int order_arr[50],quan[50],c=0;
float amt,damt,total=0;
char ch='Y';
menu(a);
if(strcmp(a,"ShopifyKids.dat")==0)
{
cout<<"\n============================";
cout<<"\n PLACE YOUR ORDER";
cout<<"\n============================\n";
do{
cout<<"\n\nEnter The Product No. Of The Product : ";
cin>>order_arr[c];
cout<<"\nQuantity in number : ";
cin>>quan[c];
c++;
cout<<"\nDo You Want To Order Another Product ? (y/n)";
cin>>ch;
}while(ch=='y' ||ch=='Y');
cout<<"\n\nThank You For Placing The Order";getch();//clrscr();
cout<<"\n\n********************************INVOICE************************\n";
cout<<"\nPr No.\tPr Name\tQuantity \tPrice \tAmount \tAmount after discount\n";
for(int x=0;x<=c;x++)
{
fp.open(a,ios::in);
fp.read((char*)&k,sizeof(k));
while(!fp.eof())
{
if(k.return_product_id()==order_arr[x])
{
amt=k.return_price()*quan[x];
damt=amt-(amt*k.return_discount()/100);
cout<<"\n"<<order_arr[x]<<"\t"<<k.return_bname()<<"\t"<<quan[x]<<"\t\t"<<k.return_price()<<"\t"<<amt<<"\t\t"<<damt;
total+=damt;
}
fp.read((char*)&k,sizeof(k));
}
fp.close();
}
cout<<"\n\n\t\t\t\t\tTOTAL = "<<total;
int graph[V][V] = { { 0, 4, 0, 0, 0, 0, 0, 8, 0 },
{ 4, 0, 8, 0, 0, 0, 0, 11, 0 },
{ 0, 8, 0, 7, 0, 4, 0, 0, 2 },
{ 0, 0, 7, 0, 9, 14, 0, 0, 0 },
{ 0, 0, 0, 9, 0, 10, 0, 0, 0 },
{ 0, 0, 4, 14, 10, 0, 2, 0, 0 },
{ 0, 0, 0, 0, 0, 2, 0, 1, 6 },
{ 8, 11, 0, 0, 0, 0, 1, 0, 7 },
{ 0, 0, 2, 0, 0, 0, 6, 7, 0 } };
dijkstra(graph, 0);
}
else if(strcmp(a,"ShopifyGarden.dat")==0)
{
cout<<"\n============================";
cout<<"\n PLACE YOUR ORDER";
cout<<"\n============================\n";
do{
cout<<"\n\nEnter The Product No. Of The Product : ";
cin>>order_arr[c];
cout<<"\nQuantity in number : ";
cin>>quan[c];
c++;
cout<<"\nDo You Want To Order Another Product ? (y/n)";
cin>>ch;
}while(ch=='y' ||ch=='Y');
cout<<"\n\nThank You For Placing The Order";getch();//clrscr();
cout<<"\n\n********************************INVOICE************************\n";
cout<<"\nPr No.\tPr Name\tQuantity \tPrice \tAmount \tAmount after discount\n";
for(int x=0;x<=c;x++)
{
fp.open(a,ios::in);
fp.read((char*)&g,sizeof(g));
while(!fp.eof())
{
if(g.return_product_id()==order_arr[x])
{
amt=g.return_price()*quan[x];
damt=amt-(amt*g.return_discount()/100);
cout<<"\n"<<order_arr[x]<<"\t"<<g.return_bname()<<"\t"<<quan[x]<<"\t\t"<<g.return_price()<<"\t"<<amt<<"\t\t"<<damt;
total+=damt;
}
fp.read((char*)&g,sizeof(g));
}
fp.close();
}
cout<<"\n\n\t\t\t\t\tTOTAL = "<<total;
int graph[V][V] = { { 0, 4, 0, 0, 0, 0, 0, 8, 0 },
{ 4, 0, 8, 0, 0, 0, 0, 11, 0 },
{ 0, 8, 0, 7, 0, 4, 0, 0, 2 },
{ 0, 0, 7, 0, 9, 14, 0, 0, 0 },
{ 0, 0, 0, 9, 0, 10, 0, 0, 0 },
{ 0, 0, 4, 14, 10, 0, 2, 0, 0 },
{ 0, 0, 0, 0, 0, 2, 0, 1, 6 },
{ 8, 11, 0, 0, 0, 0, 1, 0, 7 },
{ 0, 0, 2, 0, 0, 0, 6, 7, 0 } };
dijkstra(graph, 0);
}
else if(strcmp(a,"ShopifyMobile.dat")==0)
{
cout<<"\n============================";
cout<<"\n PLACE YOUR ORDER";
cout<<"\n============================\n";
do{
cout<<"\n\nEnter The Product No. Of The Product : ";
cin>>order_arr[c];
cout<<"\nQuantity in number : ";
cin>>quan[c];
c++;
cout<<"\nDo You Want To Order Another Product ? (y/n)";
cin>>ch;
}while(ch=='y' ||ch=='Y');
cout<<"\n\nThank You For Placing The Order";getch();//clrscr();
cout<<"\n\n********************************INVOICE************************\n";
cout<<"\nPr No.\tPr Name\tQuantity \tPrice \tAmount \tAmount after discount\n";
for(int x=0;x<=c;x++)
{
fp.open(a,ios::in);
fp.read((char*)&m,sizeof(m));
while(!fp.eof())
{
if(m.return_product_id()==order_arr[x])
{
amt=m.return_price()*quan[x];
damt=amt-(amt*m.return_discount()/100);
cout<<"\n"<<order_arr[x]<<"\t"<<m.return_bname()<<"\t"<<quan[x]<<"\t\t"<<m.return_price()<<"\t"<<amt<<"\t\t"<<damt;
total+=damt;
}
fp.read((char*)&m,sizeof(m));
}
fp.close();
}
cout<<"\n\n\t\t\t\t\tTOTAL = "<<total;
int graph[V][V] = { { 0, 4, 0, 0, 0, 0, 0, 8, 0 },
{ 4, 0, 8, 0, 0, 0, 0, 11, 0 },
{ 0, 8, 0, 7, 0, 4, 0, 0, 2 },
{ 0, 0, 7, 0, 9, 14, 0, 0, 0 },
{ 0, 0, 0, 9, 0, 10, 0, 0, 0 },
{ 0, 0, 4, 14, 10, 0, 2, 0, 0 },
{ 0, 0, 0, 0, 0, 2, 0, 1, 6 },
{ 8, 11, 0, 0, 0, 0, 1, 0, 7 },
{ 0, 0, 2, 0, 0, 0, 6, 7, 0 } };
dijkstra(graph, 0);
}
getch();
}
void write_product(char filename[50])
{
fp.open(filename,ios::out|ios::app);
//pr.create_product();
if(strcmp(filename,"ShopifyKids.dat")==0)
{
k.get_data();
fp.write((char*)&k,sizeof(k));
fp.close();
}
else if(strcmp(filename,"ShopifyGarden.dat")==0)
{
g.get_data();
fp.write((char*)&g,sizeof(g));
fp.close();
}
else if(strcmp(filename,"ShopifyMobile.dat")==0)
{
m.get_data();
fp.write((char*)&m,sizeof(m));
fp.close();
}
cout<<"\n\nThe Product Has Been Created ";
getch();
}
//***************************************************************
// function to read all records from file
//****************************************************************
void display_all(char filename[50])
{
//clrscr();
cout<<"\n\n\n\t\tDISPLAY ALL RECORD !!!\n\n";
fp.open(filename,ios::in);
if(strcmp(filename,"ShopifyKids.dat")==0)
{
while(fp.read((char*)&k,sizeof(k)))
{
k.show_data();
cout<<"\n\n====================================\n";
getch();
}
fp.close();
}
else if(strcmp(filename,"ShopifyGarden.dat")==0)
{
while(fp.read((char*)&g,sizeof(g)))
{
g.show_data();
cout<<"\n\n====================================\n";
getch();
}
fp.close();
}
else if(strcmp(filename,"ShopifyMobile.dat")==0)
{
while(fp.read((char*)&m,sizeof(m)))
{
m.show_data();
cout<<"\n\n====================================\n";
getch();
}
fp.close();
}
getch();
}
//***************************************************************
// function to read specific record from file
//****************************************************************
void display_sp(char filename[50],int n)
{
int flag=0;
fp.open(filename,ios::in);
if(strcmp(filename,"ShopifyKids.dat")==0)
{
while(fp.read((char*)&k,sizeof(k)))
{
if(k.return_product_id()==n)
{
// clrscr();
k.show_data();
flag=1;
}
}
fp.close();
if(flag==0)
cout<<"\n\nrecord not exist";
getch();
}
else if(strcmp(filename,"ShopifyGarden.dat")==0)
{
while(fp.read((char*)&g,sizeof(g)))
{
if(g.return_product_id()==n)
{
// clrscr();
g.show_data();
flag=1;
}
}
fp.close();
if(flag==0)
cout<<"\n\nrecord not exist";
getch();
}
else if(strcmp(filename,"ShopifyMobile.dat")==0)
{
while(fp.read((char*)&m,sizeof(m)))
{
if(m.return_product_id()==n)
{
// clrscr();
m.show_data();
flag=1;
}
}
fp.close();
if(flag==0)
cout<<"\n\nrecord not exist";
getch();
}
getch();
}
//***************************************************************
// function to modify record of file
//****************************************************************
void modify_product(char filename[50])
{
int no,found=0;
// clrscr();
if(strcmp(filename,"ShopifyKids.dat")==0)
{
cout<<"\n\n\tTo Modify ";
cout<<"\n\n\tPlease Enter The Product No. of The Product";
cin>>no;
fp.open(filename,ios::in|ios::out);
while(fp.read((char*)&k,sizeof(k)) && found==0)
{
if(k.return_product_id()==no)
{
k.show_data();
cout<<"\nPlease Enter The New Details of Product"<<endl;
k.get_data();
int pos=-1*sizeof(k);
fp.seekp(pos,ios::cur);
fp.write((char*)&k,sizeof(k));
cout<<"\n\n\t Record Updated";
found=1;
}
}
fp.close();
if(found==0)
cout<<"\n\n Record Not Found ";
getch();
}
else if(strcmp(filename,"ShopifyGarden.dat")==0)
{
cout<<"\n\n\tTo Modify ";
cout<<"\n\n\tPlease Enter The Product No. of The Product";
cin>>no;
fp.open(filename,ios::in|ios::out);
while(fp.read((char*)&g,sizeof(g)) && found==0)
{
if(g.return_product_id()==no)
{
k.show_data();
cout<<"\nPlease Enter The New Details of Product"<<endl;
k.get_data();
int pos=-1*sizeof(g);
fp.seekp(pos,ios::cur);
fp.write((char*)&g,sizeof(g));
cout<<"\n\n\t Record Updated";
found=1;
}
}
fp.close();
if(found==0)
cout<<"\n\n Record Not Found ";
getch();
}
else if(strcmp(filename,"ShopifyMobile.dat")==0)
{
cout<<"\n\n\tTo Modify ";
cout<<"\n\n\tPlease Enter The Product No. of The Product";
cin>>no;
fp.open(filename,ios::in|ios::out);
while(fp.read((char*)&m,sizeof(m)) && found==0)
{
if(k.return_product_id()==no)
{
m.show_data();
cout<<"\nPlease Enter The New Details of Product"<<endl;
m.get_data();
int pos=-1*sizeof(m);
fp.seekp(pos,ios::cur);
fp.write((char*)&m,sizeof(m));
cout<<"\n\n\t Record Updated";
found=1;
}
}
fp.close();
if(found==0)
cout<<"\n\n Record Not Found ";
getch();
}
}
//***************************************************************
// function to delete record of file
//****************************************************************
void delete_product(char filename[50])
{
int no;
if(strcmp(filename,"ShopifyKids.dat")==0)
{
cout<<"\n\n\n\tDelete Record";
cout<<"\n\nPlease Enter The product no. of The Product You Want To Delete";
cin>>no;
fp.open(filename,ios::in|ios::out);
fstream fp2;
fp2.open("Temp.dat",ios::out);
fp.seekg(0,ios::beg);
while(fp.read((char*)&k,sizeof(k)))
{
if(k.return_product_id()!=no)
{
fp2.write((char*)&k,sizeof(k));
}
}
fp2.close();
fp.close();
remove(filename);
rename("Temp.dat",filename);
cout<<"\n\n\tRecord Deleted ..";
getch();
}
else if(strcmp(filename,"ShopifyGarden.dat")==0)
{
cout<<"\n\n\n\tDelete Record";
cout<<"\n\nPlease Enter The product no. of The Product You Want To Delete";
cin>>no;
fp.open(filename,ios::in|ios::out);
fstream fp2;
fp2.open("Temp.dat",ios::out);
fp.seekg(0,ios::beg);
while(fp.read((char*)&g,sizeof(g)))
{
if(g.return_product_id()!=no)
{
fp2.write((char*)&g,sizeof(g));
}
}
fp2.close();
fp.close();
remove(filename);
rename("Temp.dat",filename);
cout<<"\n\n\tRecord Deleted ..";
getch();
}
else if(strcmp(filename,"ShopifyMobile.dat")==0)
{
cout<<"\n\n\n\tDelete Record";
cout<<"\n\nPlease Enter The product no. of The Product You Want To Delete";
cin>>no;
fp.open(filename,ios::in|ios::out);
fstream fp2;
fp2.open("Temp.dat",ios::out);
fp.seekg(0,ios::beg);
while(fp.read((char*)&m,sizeof(m)))
{
if(m.return_product_id()!=no)
{
fp2.write((char*)&m,sizeof(m));
}
}
fp2.close();
fp.close();
remove(filename);
rename("Temp.dat",filename);
cout<<"\n\n\tRecord Deleted ..";
getch();
}
}
void admin_menu()
{
//clrscr();
char ch2;
cout<<"\n\n\n\tADMIN MENU";
cout<<"\n\n\t1.CREATE PRODUCT";
cout<<"\n\n\t2.DISPLAY ALL PRODUCTS";
cout<<"\n\n\t3.QUERY ";
cout<<"\n\n\t4.MODIFY PRODUCT";
cout<<"\n\n\t5.DELETE PRODUCT";
cout<<"\n\n\t6.VIEW PRODUCT MENU";
cout<<"\n\n\t7.BACK TO MAIN MENU";
cout<<"\n\n\tPlease Enter Your Choice (1-7) ";
ch2=getche();
char filename[50];
switch(ch2)
{
case '1': //clrscr();
cout<<"Enter name of the file to be written:"<<endl;
cin>>filename;
write_product(filename);
break;
case '2':
cout<<"Enter name of the file to be displayed:"<<endl;
cin>>filename;
display_all(filename);break;
case '3':
int num;
//clrscr();
cout<<"Enter name of the file to be searched:"<<endl;
cin>>filename;
cout<<"\n\n\tPlease Enter The Product No. ";
cin>>num;
display_sp(filename,num);
break;
case '4':
cout<<"Enter name of the file to be modified:"<<endl;
cin>>filename;
modify_product(filename);break;
case '5': cout<<"Enter name of the file of which product is to be deleted:"<<endl;
cin>>filename;
delete_product(filename);break;
case '6': menu(filename);
getch();
case '7': break;
default:cout<<"\a";admin_menu();
}
}
void intro()
{
// clrscr();
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFOEX info;
GetConsoleScreenBufferInfoEx(hConsole,&info);
CONSOLE_FONT_INFOEX cfi;
cfi.cbSize = sizeof(cfi);
cfi.nFont = 0;
cfi.dwFontSize.X = 10; // Width of each character in the font
cfi.dwFontSize.Y = 24; // Height
cfi.FontFamily = FF_DONTCARE;
cfi.FontWeight = FW_NORMAL;
wcscpy(cfi.FaceName, L"Gigi"); // Choose your font
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);
// info.ColorTable[3]=RGB(135,206,235);
// info.ColorTable[2]=RGB(25,0,120);
// stack<Gardening_Products> gp;
// stack<Kitchen_Furnishings> kf;
// stack<Male_Clothing>m;