forked from prathamesh60/dspd_assi_4thsemester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdspd2_assignment.c
1055 lines (1028 loc) · 27.2 KB
/
dspd2_assignment.c
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 <stdio.h>
#include <string.h>
#include<stdlib.h>
typedef enum{FAILURE,SUCCESS} statuscode;
typedef enum{FALSE,TRUE} boolean;
typedef struct item_name_tag
{
char name[50];
int no_of_time;
struct item_name_tag *next;
}item_name;
typedef struct item_tag
{ char itemname[100];
float price;
}items;
typedef struct menu_tag
{
int no_of_items;
items item[100];
}menu;
typedef struct location_tag
{ char name[50];
char address[100];
char zone[50];
int no_of_seats;
menu *res_menu;
int category;//1 for restaurant 2 for cafe 3 for pub
int cuis_category;//1 for north indian 2 for south indian 3 for continental
//char sp_facilities[20][100];
struct location_tag *next;
}location;
typedef struct cat_tag{
char name[100];
char address[50];
struct cat_tag* next;
}cat_location;
typedef struct cuisine_tag{
char name[100];
char address[50];
struct cuisine_tag* next;
}cuis_location;
int agent_id_allocator=114;
typedef struct agent_tag
{ int id;
char name[50];
char phone_no[11];
char area[50];
boolean is_available;
char ord_id[21];
float curr_accu_commi;
struct agent_tag *next;
}agent;
typedef struct user_tag
{// char us_id[21];
char name[50];
char address[50];
char phone_no[11];
//orders *ord;
item_name *ordered_items;
struct user_tag *next;
}user;
int order_id_allocator=1000;
typedef struct order_tag
{ char res_name[50];
char res_address[50];
int ord_id;
int no_of_items;
int item_index[100];
int quantity_index[100];
/* char ag_id[21];
char ag_phone[11];
*/
agent *allocated_agent;
/* char us_name[50];
char us_address[50];
char us_phone_no[11];*/
user *username;
float total_price;
location *ordered_restaurant;
struct order_tag *next;
}orders;
menu* create_menu()
{
menu *lptr=(menu*)malloc(sizeof(menu));
int n;char name[100];float price;
printf("Enter the number of items\t:\n");
scanf("%d",&n);
lptr->no_of_items=n;
int i;
for(i=0;i<n;i++)
{
printf("Enter item name\t:\n");
scanf("%s",name);
printf("Enter the pricw\t:\n");
scanf("%f",&price);
strcpy(lptr->item[i].itemname,name);
lptr->item[i].price=price;
}
return lptr;
}
statuscode insert_cat_location(cat_location **nptr,char name[],char address[])
{
cat_location *lptr= (cat_location*)malloc(sizeof(cat_location));
statuscode sc=FAILURE;
if(lptr!=NULL)
{
sc=SUCCESS;
strcpy(lptr->name,name);
strcpy(lptr->address,address);
lptr->next=*nptr;
*nptr=lptr;
}
return sc;
}
statuscode insert_cuis_location(cuis_location **nptr,char name[],char address[])
{
cuis_location *lptr=(cuis_location*)malloc(sizeof(cuis_location));
statuscode sc=FAILURE;
if(lptr!=NULL)
{
sc=SUCCESS;
strcpy(lptr->name,name);
strcpy(lptr->address,address);
lptr->next=*nptr;
*nptr=lptr;
}
return sc;
}
statuscode insert_eat_location(location **all_eatspots,char name[],char address[],char zone[],int no_of_seats,menu *res_menu,int category,int cuis_category)
{
location *nptr= (location*)malloc(sizeof(location));
statuscode sc=FAILURE;
if(nptr!=NULL)
{
sc=SUCCESS;
strcpy(nptr->name,name);
strcpy(nptr->address,address);
strcpy(nptr->zone,zone);
nptr->no_of_seats=no_of_seats;
nptr->res_menu=res_menu;
nptr->category=category;
//insert_cat_location(ca_ptr,name,address);
nptr->cuis_category=cuis_category;
nptr->next=*all_eatspots;
*all_eatspots=nptr;
}
return sc;
}
void visit_menu(menu *lptr)
{
int i=0;
printf("MENU\n");
printf("No.of items\t:%d\n",lptr->no_of_items);
while(i<(lptr->no_of_items))
{
printf("%d. %s\n",i+1,lptr->item[i].itemname);
printf(" Price\t:%f\n",lptr->item[i].price);
i++;
}
}
void print_location(location *nptr)
{
printf("Eating spot name\t:%s\n",nptr->name);
printf("Address\t:%s\n",nptr->address);
printf("Zone\t:%s\n",nptr->zone);
if(nptr->category==1)
{
printf("Category\t:Restaurant\n");
}
else if(nptr->category==2)
{
printf("Category\t:Cafe\n");
}
else if(nptr->category==3)
{
printf("Category\t:Pub\n");
}
if(nptr->cuis_category==1)
{
printf("Cuisine\t:NORTH INDIAN\n");
}
else if(nptr->cuis_category==2)
{
printf("Cuisine\t:SOUTH INDIAN\n");
}
else if(nptr->cuis_category==3)
{
printf("Cuisine\t:CONTINENTAL\n");
}
printf("No. of seats\t:%d\n",nptr->no_of_seats);
menu *lptr=nptr->res_menu;
visit_menu(lptr);
}
void get_details(location *all_eatspots)
{
char name[50],address[100],flag=1;
location *nptr=all_eatspots;
printf("Enter the name of your restaurant\t:");
scanf("%s",name);
printf("Enter the address of your restaurant\t:");
scanf("%s",address);
while(nptr!=NULL&&flag==1)
{
if(strcmp(nptr->name,name)==0&&strcmp(nptr->address,address)==0)
{
print_location(nptr);
flag=0;
}
else
nptr=nptr->next;
}
}
void Traverse(location *all_eatspots)
{
location *nptr=all_eatspots;
while(nptr!=NULL)
{
print_location(nptr);
nptr=nptr->next;
}
}
void Traverse_cat(cat_location *lptr)
{ cat_location *nptr=lptr;
while(nptr!=NULL)
{
printf("Eating Spot Name\t:%s\nEating Spot Address\t:%s\n",nptr->name,nptr->address);
nptr=nptr->next;
}
}
void Traverse_cuis(cuis_location *lptr)
{ cuis_location *nptr=lptr;
while(nptr!=NULL)
{
printf("Eating Spot Name\t:%s\nEating Spot Address\t:%s\n",nptr->name,nptr->address);
nptr=nptr->next;
}
}
void search_category(cat_location *jptr,cat_location *kptr,cat_location *lptr)
{
int x;
printf("Enter the category of restaurant you are searching for\t:\n");
printf("PRESS 1 FOR RESTAURANT\nPRESS 2 FOR CAFE\nPRESS 3 FOR PUB\n");
scanf("%d",&x);
if(x==1)
{
Traverse_cat(jptr);
}
else if(x==2)
{
Traverse_cat(kptr);
}
else if(x==3)
{
Traverse_cat(lptr);
}
}
void search_cuisine(cuis_location *jptr,cuis_location *kptr,cuis_location *lptr)
{
int x;
printf("Enter the cuisine of restaurant you are searching for\t:\n");
printf("PRESS 1 FOR NORTH INDIAN\nPRESS 2 FOR SOUTH INDIAN\nPRESS 3 FOR CONTINENTAL\n");
scanf("%d",&x);
if(x==1)
{
Traverse_cuis(jptr);
}
else if(x==2)
{
Traverse_cuis(kptr);
}
else if(x==3)
{
Traverse_cuis(lptr);
}
}
void search_area(location* lptr)
{
int flag=0;
char x[100],y[50];
printf("Enter area: ");
scanf("%s",x);
printf("Enter zone: ");
scanf("%s",y);
location* nptr=lptr;
while(nptr!=NULL)
{
if(strcmp(nptr->address,x)==0)
{
if(flag==0)
{
printf("Restaurant in area:\n");
printf("%s\n",nptr->name);
flag=1;
}
else
{
printf("%s\n",nptr->name);
}
}
nptr=nptr->next;
}
if(flag==0)
printf("No restaurant found in area\n");
flag=0;
nptr=lptr;
while(nptr!=NULL)
{
if(strcmp(nptr->address,x)!=0&&strcmp(nptr->zone,y)==0)
{
if(flag==0)
{
printf("Restaurant in nearby area:\n");
printf("%s\n",nptr->name);
flag=1;
}
else
{
printf("%s\n",nptr->name);
}
}
nptr=nptr->next;
}
if(flag==0)
printf("No restaurant found in nearby areas\n");
}
statuscode insert_agent(agent **ag_ptr,int id,char name[50],char phone_no[11],char area[50],float curr_accu_comm)
{
statuscode sc=FAILURE;
agent *nptr=(agent*)malloc(sizeof(agent));
if(nptr!=NULL)
{ nptr->id=id;
strcpy(nptr->name,name);
strcpy(nptr->phone_no,phone_no);
strcpy(nptr->area,area);
nptr->curr_accu_commi=curr_accu_comm;
nptr->is_available=TRUE;
nptr->next=*ag_ptr;
*ag_ptr=nptr;
sc=SUCCESS;
}
}
void print_agents(agent *ag_ptr)
{
agent *nptr=ag_ptr;
while(nptr!=NULL)
{
printf("Agent Id\t:%d\n",nptr->id);
printf("Agent Name\t:%s\n",nptr->name);
printf("Agent Phone No.\t:%s\n",nptr->phone_no);
printf("Agent Area\t:%s\n",nptr->area);
printf("Accumulated Commission\t:%f\n",nptr->curr_accu_commi);
/*if(nptr->is_available==TRUE)
{
printf("Availability\t:Available\n\n");
}
else
{
printf("Availability\t:Not Available\n");
printf("Busy with Order ID\t:%s\n\n",nptr->ord_id);
}*/
nptr=nptr->next;
}
}
void print_live_orders(orders *optr)
{
int i;orders *nptr=optr;
while(nptr!=NULL)
{
printf("Order Id\t:%d\n",nptr->ord_id);
printf("Restaurant Name\t:%s\n",nptr->res_name);
printf("Restaurant Address\t:%s\n",nptr->res_address);
printf("No. of items\t:%d\n",nptr->no_of_items);
for(i=0;i<nptr->no_of_items;i++)
{
printf("%d. %s\n",i+1,nptr->ordered_restaurant->res_menu->item[nptr->item_index[i]].itemname);
printf(" Quantity\t:%d\n",nptr->quantity_index[i]);
printf(" Price\t:%f\n",nptr->ordered_restaurant->res_menu->item[nptr->item_index[i]].price);
}
printf("Username\t:%s\n",nptr->username->name);
printf("User Address\t:%s\n",nptr->username->address);
printf("User Phone No.\t:%s\n",nptr->username->phone_no);
printf("Total price to be paid\t:%f\n",nptr->total_price);
printf("Agent Name\t:%s\n",nptr->allocated_agent->name);
printf("Agent Phone No.\t:%s\n",nptr->allocated_agent->phone_no);
nptr=nptr->next;
}
}
statuscode takeorder(location *all_eatspots,orders **pending_order,cuis_location *north,cuis_location *south,cuis_location *cont,user **users,agent **agent_list,agent **agent_busy_list)
{
int temp=1;
int food_type;
char name[100],address[100];
statuscode sc=SUCCESS;
printf("Enter cuisine you want:1)North Indian 2)South Indian 3)Continental ");
scanf("%d",&food_type);
if(food_type==1)
{
if(north==NULL)
{ temp=0;
sc=FAILURE;
printf("No eating place available for required cuisine\n");
}
else
{ printf("Following are the places available\n");
Traverse_cuis(north);
}
}
else if(food_type==2)
{
if(south==NULL)
{ temp=0;
sc=FAILURE;
printf("No eating place available for required cuisine\n");
}
else
{ printf("Following are the places available\n");
Traverse_cuis(south);
}
}
else if(food_type==3)
{
if(cont==NULL)
{
temp=0;
sc=FAILURE;
printf("No eating place available for required cuisine\n");
}
else
{ printf("Following are the places available\n");
Traverse_cuis(cont);
}
}
if(temp==1)
{
printf("Enter name of the restaurant:");
scanf("%s",name);
printf("Enter address of the restaurant: ");
scanf("%s",address);
orders *orde=(orders*)malloc(sizeof(orders));
strcpy(orde->res_name,name);
strcpy(orde->res_address,address);
location *nptr=all_eatspots;
temp=0;
while(nptr!=NULL && temp==0)
{
if((strcmp(nptr->name,name)==0) && (strcmp(nptr->address,address)==0))
{ temp=1;
}
else
nptr=nptr->next;
}
if(temp==0)
{ printf("Invalid name and address: ");
}
else
{ printf("You can order now:\n ");
printf("Below is the menu: \n");
visit_menu(nptr->res_menu);
orde->ordered_restaurant=nptr;
printf("Enter no of items you want to order: ");
int n;
scanf("%d",&n);
int a[n];
printf("Enter choice nos :");
int i=0,p=0;
float price=0;
for(i=0;i<n;i++)
{ printf("ENTER YOUR CHOICE No %d: \n",i+1);
scanf("%d",&a[i]);
int x;
printf("Enter quantity: ");
scanf("%d",&x);
if(a[i]<=nptr->res_menu->no_of_items)
{
orde->item_index[p]=a[i]-1;
orde->quantity_index[p]=x;
price=price+(orde->ordered_restaurant->res_menu->item[a[i]-1].price)*x;
p++;
}
}
orde->no_of_items=p;
orde->total_price=price;
char us_phone[50];
printf("ENTER USER PHONE NO: ");
scanf("%s",us_phone);
user *kptr=*users;
temp=0;
while(kptr!=NULL && temp==0)
{ if(strcmp(kptr->phone_no,us_phone)==0)
{
temp=1;
}
else
{
kptr=kptr->next;
}
}
if(temp==0)
{ printf("Register new user:\n");
user* new_user=(user*)malloc(sizeof(user));
strcpy(new_user->phone_no,us_phone);
char us_name[50];
char us_address[50];
printf("Enter new user name: ");
scanf("%s",us_name);
printf("Enter new user address: ");
scanf("%s",us_address);
strcpy(new_user->name,us_name);
strcpy(new_user->address,us_address);
new_user->ordered_items=NULL;
new_user->next=*users;
*users=new_user;
kptr=new_user;
printf("New user registered successfully: ");
}
orde->username=kptr;
if(*agent_list!=NULL)
{ agent *alloc_agent;
alloc_agent=*agent_list;
*agent_list=(*agent_list)->next;
orde->allocated_agent=alloc_agent;
alloc_agent->next=*agent_busy_list;
*agent_busy_list=alloc_agent;
orde->ord_id=order_id_allocator;
order_id_allocator++;
orde->next=*pending_order;
*pending_order=orde;
printf("Your order is registered successfully: Agent %s is assigned to you.\nContact no of agent:%s",alloc_agent->name,alloc_agent->phone_no);
}
else
{ printf("No free agents available:");
}
}
}
return sc;
}
statuscode delivery(orders **pending_orders,agent **agent_list,agent **agent_busy_list,orders **archived_orders)
{ orders *nptr=*pending_orders,*kptr;
orders *prev=NULL;
statuscode sc=SUCCESS;
int order_id;
printf("Enter order id: ");
scanf("%d",&order_id);
int temp=0;
while(nptr!=NULL && temp==0)
{ if(nptr->ord_id==order_id)
{
temp=1;
}
else
{prev=nptr;
nptr=nptr->next;
}
}
if(temp==0)
{
printf("Order with given id does not exist:");
sc=FAILURE;
}
else
{
kptr=nptr;
printf("Price=%f",kptr->total_price);
if(prev==NULL)
{ *pending_orders=nptr->next;
}
else
{ prev->next=nptr->next;
}
kptr->next=NULL;
// kptr->allocated_agent->curr_accu_commi=(kptr->allocated_agent->curr_accu_commi)+0.10*kptr->total_price;
int i;
for(i=0;i<kptr->no_of_items;i++)
{ char itemname[50];
strcpy(itemname,nptr->ordered_restaurant->res_menu->item[nptr->item_index[i]].itemname);
item_name *xptr=kptr->username->ordered_items;
int temp1=0;
while(xptr!=NULL && temp1==0)
{ if(strcmp(xptr->name,itemname)==0)
{// printf("FOUND IT:\n ");
(xptr->no_of_time)++;
temp1=1;
}
xptr=xptr->next;
}
if(temp1==0)
{// printf("allocating space:\n");
item_name *xy=(item_name*)malloc(sizeof(item_name));
strcpy(xy->name,itemname);
xy->no_of_time=1;
xy->next=kptr->username->ordered_items;
kptr->username->ordered_items=xy;
}
}
agent *p=*agent_busy_list,*pr=NULL;
temp=0;
while(p!=NULL && temp==0)
{ if(p->id == kptr->allocated_agent->id)
{
temp=1;
}
else
{ pr=p;
p=p->next;
}
}
p->curr_accu_commi=(p->curr_accu_commi)+((1.0*kptr->total_price)/10);
//free(kptr);
kptr->next=*archived_orders;
*archived_orders=kptr;
if(temp==1)
{
if(pr==NULL)
{ *agent_busy_list=(*agent_busy_list)->next;
p->next=*agent_list;
*agent_list=p;
}
else
{ pr->next=p->next;
p->next=*agent_list;
*agent_list=p;
}
}
}
return sc;
}
statuscode cancel_order(orders **pending_orders,agent **agent_list,agent **agent_busy_list)
{ orders *nptr=*pending_orders,*kptr;
orders *prev=NULL;
statuscode sc=SUCCESS;
int order_id;
printf("Enter order id: ");
scanf("%d",&order_id);
int temp=0;
while(nptr!=NULL && temp==0)
{ if(nptr->ord_id==order_id)
{
temp=1;
}
else
{prev=nptr;
nptr=nptr->next;
}
}
if(temp==0)
{
printf("Order with given id does not exist:");
sc=FAILURE;
}
else
{ kptr=nptr;
printf("Price=%f",kptr->total_price);
if(prev==NULL)
{ *pending_orders=nptr->next;
}
else
{ prev->next=nptr->next;
}
kptr->next=NULL;
// kptr->allocated_agent->curr_accu_commi=(kptr->allocated_agent->curr_accu_commi)+0.10*kptr->total_price;
agent *p=*agent_busy_list,*pr=NULL;
temp=0;
while(p!=NULL && temp==0)
{ if(p->id == kptr->allocated_agent->id)
{
temp=1;
}
else
{ pr=p;
p=p->next;
}
}
//p->curr_accu_commi=(p->curr_accu_commi)+((1.0*kptr->total_price)/10);
free(kptr);
if(temp==1)
{
if(pr==NULL)
{ *agent_busy_list=(*agent_busy_list)->next;
p->next=*agent_list;
*agent_list=p;
}
else
{ pr->next=p->next;
p->next=*agent_list;
*agent_list=p;
}
}
}
return sc;
}
void areawise_agents(agent *ag_ptr,agent *bg_ptr)
{
char area[50];
printf("Enter the area you want to look for agents\t:");
scanf("%s",area);
agent *nptr=ag_ptr;
while(nptr!=NULL)
{
if(strcmp(nptr->area,area)==0)
{
printf("Agent Id\t:%d\n",nptr->id);
printf("Agent Name\t:%s\n",nptr->name);
printf("Agent Phone No.\t:%s\n",nptr->phone_no);
printf("Agent Area\t:%s\n",nptr->area);
printf("Accumulated Commission\t:%f\n",nptr->curr_accu_commi);
}
nptr=nptr->next;
}
agent *kptr=bg_ptr;
while(kptr!=NULL)
{
if(strcmp(kptr->area,area)==0)
{
printf("Agent Id\t:%d\n",kptr->id);
printf("Agent Name\t:%s\n",kptr->name);
printf("Agent Phone No.\t:%s\n",kptr->phone_no);
printf("Agent Area\t:%s\n",kptr->area);
printf("Accumulated Commission\t:%f\n",kptr->curr_accu_commi);
}
kptr=kptr->next;
}
}
void print_user_history(orders **archived_orders)
{ char phone[11];
int i;
printf("Enter phone no of user: ");
scanf("%s",phone);
orders *nptr=*archived_orders;
int temp=0;
while(nptr!=NULL)
{
if(strcmp(nptr->username->phone_no,phone)==0)
{ if(temp==0)
{
printf("Following are past orders with given user:\n ");
temp=1;
}
printf("Order Id\t:%d\n",nptr->ord_id);
printf("Restaurant Name\t:%s\n",nptr->res_name);
printf("Restaurant Address\t:%s\n",nptr->res_address);
printf("No. of items\t:%d\n",nptr->no_of_items);
for(i=0;i<nptr->no_of_items;i++)
{
printf("%d. %s\n",i+1,nptr->ordered_restaurant->res_menu->item[nptr->item_index[i]].itemname);
printf(" Price\t:%f\n",nptr->ordered_restaurant->res_menu->item[nptr->item_index[i]].price);
}
printf("Username\t:%s",nptr->username->name);
printf("User Address\t:%s",nptr->username->address);
printf("User Phone No.\t:%s",nptr->username->phone_no);
printf("Total price to be paid\t:%f",nptr->total_price);
printf("Agent Name\t:%s",nptr->allocated_agent->name);
printf("Agent Phone No.\t:%s",nptr->allocated_agent->phone_no);
}
nptr=nptr->next;
}
if(temp==0)
printf("No orders associated with given user: ");
}
statuscode insert_eating_location(location **all_eatspots, char res_zone[50],char res_name[50],char res_address[50],int res_no_of_seats,int res_category,int res_cuis_category, menu *res_res_menu,cat_location **res,cat_location **cafe,cat_location **pub,cuis_location **north,cuis_location **south,cuis_location **cont)
{
statuscode sc;
//strcpy(res_name,"PRATHAMESH");
printf("Enter the name of your restaurant\t:\n");
scanf("%s",res_name);
printf("Enter the address of your restaurant\t:\n");
//strcpy(res_address,"NAGPUR");
scanf("%s",res_address);
printf("Enter the zone of your restaurant\t:\n");
//strcpy(res_zone,"EAST");
scanf("%s",res_zone);
// res_no_of_seats=100;
printf("Enter the number of seats in your restaurant\t:\n");
scanf("%d",&res_no_of_seats);
res_res_menu=create_menu();
printf("Enter the category of your restaurant\t:\n");
printf("PRESS 1 FOR RESTAURANT\nPRESS 2 FOR CAFE\nPRESS 3 FOR PUB\n");
scanf("%d",&res_category);
printf("Enter the cuisine of your restaurant\t:\n");
printf("PRESS 1 FOR NORTH INDIAN\nPRESS 2 FOR SOUTH INDIAN\nPRESS 3 FOR CONTINENTAL\n");
scanf("%d",&res_cuis_category);
//res_category=1;
//res_cuis_category=2;
//fptr=all_eatspots;
sc=insert_eat_location(all_eatspots,res_name,res_address,res_zone,res_no_of_seats,res_res_menu,res_category,res_cuis_category);
if(res_category==1)
{
insert_cat_location(res,res_name,res_address);
}
else if(res_category==2)
{
insert_cat_location(cafe,res_name,res_address);
}
else
{
insert_cat_location(pub,res_name,res_address);
}
if(res_cuis_category==1)
{
insert_cuis_location(north,res_name,res_address);
}
else if(res_cuis_category==2)
{
insert_cuis_location(south,res_name,res_address);
}
else
{
insert_cuis_location(cont,res_name,res_address);
}
return sc;
}
statuscode insert_new_agent(agent **agent_list)
{ statuscode sc;
char ag_name[50];
char ag_phone_no[11];
char ag_area[50];
printf("Enter agent namer: ");
scanf("%s",ag_name);\
printf("Enter agent phone no: ");
scanf("%s",ag_phone_no);
printf("Enter agent area: ");
scanf("%s",ag_area);
sc=insert_agent(agent_list,agent_id_allocator,ag_name,ag_phone_no,ag_area,0.0);
agent_id_allocator++;
return sc;
}
void print_favourite_item(user* users)
{ char phone_no[11];
printf("Enter user phone no:\n");
scanf("%s",phone_no);
user *nptr=users;
int temp=0;
while(nptr!=NULL && temp==0)
{ if(strcmp(nptr->phone_no,phone_no)==0)
{
temp=1;
}
else
nptr=nptr->next;
}
if(temp==0)
printf("User not found\n");
else
{ if(nptr->ordered_items==NULL)
{ printf("User did not give any order yet:\n");
}
else
{int max=nptr->ordered_items->no_of_time;
char iname[50];
strcpy(iname,nptr->ordered_items->name);
item_name *xptr=nptr->ordered_items->next;
while(xptr!=NULL)
{ if(xptr->no_of_time>max)
{ strcpy(iname,xptr->name);
max=xptr->no_of_time;
}
xptr=xptr->next;
}
printf("The favourite items of user are \n");
xptr=nptr->ordered_items;
while(xptr!=NULL)
{ if(xptr->no_of_time==max)
{ printf("%s\n",xptr->name);
}
xptr=xptr->next;
}
}
}
}
void print_ordered_item(user *users)
{ char phone[11];
printf("Enter the phone no:\n");
scanf("%s",phone);
user *nptr=users;
int temp=0;
while(nptr!=NULL && temp==0)
{if(strcmp(nptr->phone_no,phone)==0)
{
temp=1;
}
else
{nptr=nptr->next;
}
}
if(temp==1)
{
item_name *xptr=nptr->ordered_items;
while(xptr!=NULL)
{ printf("Item name: ");
printf("%s ",xptr->name);
printf("No of times: %d\n",xptr->no_of_time);
xptr=xptr->next;
}
}
else
printf("User not found\n");
}
int main()
{ statuscode sc;
cat_location *res=NULL;
cat_location *pub=NULL;
cat_location *cafe=NULL;
cuis_location *north=NULL;
cuis_location *south=NULL;
cuis_location *cont=NULL;
location *all_eatspots=NULL;
location *fptr;
orders *pending_orders=NULL,*archived_orders=NULL;
user *users=NULL;
agent *agent_list=NULL,*agent_busy_list=NULL;
sc=insert_agent(&agent_list,111,"RAMU","912345678","NAGPUR",0.0);
sc=insert_agent(&agent_list,112,"SHAMU","912345678","AJNI",0.0);
sc=insert_agent(&agent_list,113,"GOLU","9423123458","NAGPUR",0.0);
char res_name[50];
char res_address[100];
char res_zone[50];
int res_no_of_seats;
menu *res_res_menu;
int res_category;
int res_cuis_category;
int i;
for(i=0;i<1;i++)
{
//strcpy(res_name,"PRATHAMESH");
printf("Enter the name of your restaurant\t:\n");
scanf("%s",res_name);
printf("Enter the address of your restaurant\t:\n");
//strcpy(res_address,"NAGPUR");
scanf("%s",res_address);
printf("Enter the zone of your restaurant\t:\n");
//strcpy(res_zone,"EAST");
scanf("%s",res_zone);
// res_no_of_seats=100;
printf("Enter the number of seats in your restaurant\t:\n");
scanf("%d",&res_no_of_seats);
res_res_menu=create_menu();
printf("Enter the category of your restaurant\t:\n");
printf("PRESS 1 FOR RESTAURANT\nPRESS 2 FOR CAFE\nPRESS 3 FOR PUB\n");
scanf("%d",&res_category);
printf("Enter the cuisine of your restaurant\t:\n");
printf("PRESS 1 FOR NORTH INDIAN\nPRESS 2 FOR SOUTH INDIAN\nPRESS 3 FOR CONTINENTAL\n");
scanf("%d",&res_cuis_category);
//res_category=1;
//res_cuis_category=2;
//fptr=all_eatspots;
sc=insert_eat_location(&all_eatspots,res_name,res_address,res_zone,res_no_of_seats,res_res_menu,res_category,res_cuis_category);
if(res_category==1)
{
insert_cat_location(&res,res_name,res_address);
}
else if(res_category==2)
{
insert_cat_location(&cafe,res_name,res_address);
}
else
{
insert_cat_location(&pub,res_name,res_address);
}
if(res_cuis_category==1)
{
insert_cuis_location(&north,res_name,res_address);
}
else if(res_cuis_category==2)
{
insert_cuis_location(&south,res_name,res_address);
}
else
{
insert_cuis_location(&cont,res_name,res_address);
}
}
// Traverse(all_eatspots);
/*Traverse_cat(res);
Traverse_cat(cafe);
Traverse_cat(pub);
//char sp_facilities[20][100];*/