1
7
8 #include<stdio.h>
9 #include<stdlib.h>
10 #include<string.h>
11
12 struct node
13 {
14 char foodname[50];
15 int quantity;
16 float price;
17 int data;
18 struct node *prev;
19 struct node *next;
20 };
21
22 struct node *headc = NULL,*newnode,*tailc = NULL;
23 struct node *heada = NULL, *taila = NULL;
24 struct node *head_s;
25
26 void adminmenu()
27 {
28 printf("\n\t\t\t\t\t\t\t1. View total sales\n");
29 printf("\t\t\t\t\t\t\t2. Add new items in the order menu\n");
30 printf("\t\t\t\t\t\t\t3. Delete items from the order menu\n");
31 printf("\t\t\t\t\t\t\t4. Display order menu\n");
32 printf("\t\t\t\t\t\t\t5. Back To Main Menu \n\n");
33 printf("\t\t\t\t\t\t\t Enter Your Choice --->");
34 }
35
36 void customermenu()
37 {
38 printf("\n\t\t\t\t\t\t\t1. Place your order\n");
39 printf("\t\t\t\t\t\t\t2. View your ordered items\n");
40 printf("\t\t\t\t\t\t\t3. Delete an item from order\n");
41 printf("\t\t\t\t\t\t\t4. Display final bill\n");
42 printf("\t\t\t\t\t\t\t5. Back To Main Menu \n\n");
43 printf("\t\t\t\t\t\t\t Enter Your Choice --->");
44 }
45
46 struct node* createadmin(struct node *head,int data, char foodname[25], float price)
47 {
48 newnode = (struct node*)malloc(sizeof(struct node));
49
50 newnode->data = data;
51 newnode->price = price;
52 newnode-> quantity = 0;
53 strcpy(newnode->foodname,foodname);
54 newnode->next = NULL;
55 newnode->prev = NULL;
56
57 struct node *temp = head;
58
59 if(temp==NULL)
60 heada = taila = newnode;
61 else
62 {
63 while(temp->next!=NULL)
64 temp=temp->next;
65
66 temp->next=newnode;
67 newnode->prev = taila;
68 taila = newnode;
69 }
70
71 return heada;
72 }
73
74 struct node* createcustomer(struct node *head,int data,int quantity)
75 {
76 newnode = (struct node*)malloc(sizeof(struct node));
77
78 struct node *temp1 = heada;
79 int flag = 0;
80 while(temp1!=NULL)
81 {
82 if(temp1->data==data)
83 {
84 flag = 1;
85 break;
86 }
87 temp1 = temp1->next;
88 }
89
90 if(flag==1)
91 {
92 newnode->data = data;
93 newnode->price = quantity*(temp1->price);
94 newnode-> quantity = quantity;
95 strcpy(newnode->foodname,temp1->foodname);
96 newnode->next = NULL;
97 newnode->prev = NULL;
98
99 struct node *temp = head;
100
101 if(temp==NULL)
102 headc = tailc = newnode;
103 else
104 {
105 while(temp->next!=NULL)
106 temp=temp->next;
107
108 temp->next=newnode;
109 newnode->prev = tailc;
110 tailc = newnode;
111 }
112
113
114 }
115 else
116 {
117 printf("\n\t\t\t\t\t\t\tThis item is not present in the menu!\n");
118 }
119 return headc;
120 }
121
122 void displayList(struct node *head)
123 {
124 struct node *temp1 = head;
125 if(temp1==NULL)
126 {
127 printf("\n\t\t\t\t\t\t\t\tList is empty!!\n\n");
128 }
129 else
130 {
131 printf("\n");
132 while(temp1!=NULL)
133 {
134 if(temp1->quantity==0)
135 printf("\t\t\t\t\t\t\t%d\t%s\t%0.2f\n",temp1->data,temp1->foodname,temp1->price);
136 else
137 {
138 printf("\t\t\t\t\t\t\t%d\t%s\t%d\t%0.2f\n",temp1->data,temp1->foodname,temp1->quantity,temp1->price);
139 }
140
141 temp1 = temp1->next;
142 }
143 printf("\n");
144 }
145
146 }
147
148 struct node* totalsales(int data,int quantity)
149 {
150 newnode = (struct node*)malloc(sizeof(struct node));
151 int flag = 0;
152
153 struct node *temp1 = heada;
154 while(temp1->data!=data)
155 {
156 temp1 = temp1->next;
157 }
158
159 newnode->data = data;
160 newnode->price = quantity*(temp1->price);
161 newnode-> quantity = quantity;
162 strcpy(newnode->foodname,temp1->foodname);
163 newnode->next = NULL;
164 newnode->prev = NULL;
165
166 struct node *temp = head_s;
167
168 if(temp==NULL)
169 head_s = newnode;
170 else
171 {
172 while(temp->next!=NULL)
173 {
174 if(temp->data==data)
175 {
176 flag = 1;
177 break;
178 }
179 temp=temp->next;
180 }
181
182 if(flag==1)
183 {
184 temp->quantity += newnode-> quantity;
185 temp->price += newnode->price;
186 }
187 else
188 {
189 temp->next=newnode;
190 }
191 }
192
193 return head_s;
194 }
195
196 void calculatetotsales()
197 {
198 struct node *temp = headc;
199 while(temp!=NULL)
200 {
201 head_s = totalsales(temp->data, temp->quantity);
202 temp=temp->next;
203 }
204 }
205
206 struct node* delete(int data,struct node *head, struct node* tail)
207 {
208 if(head==NULL)
209 {
210 printf("\n\t\t\t\t\t\t\tList is empty\n");
211 }
212 else
213 {
214 struct node* temp;
215 if(data==head->data)
216 {
217 temp = head;
218 head = head->next;
219 if (head != NULL)
220 head->prev = NULL;
221 free(temp);
222 }
223 else if(data==tail->data)
224 {
225 temp = tail;
226 tail = tail->prev;
227 tail->next = NULL;
228 free(temp);
229 }
230 else
231 {
232 temp = head;
233 while(data!=temp->data)
234 {
235 temp = temp->next;
236 }
237 (temp->prev)->next = temp->next;
238 (temp->next)->prev = temp->prev;
239 free(temp);
240 }
241 }
242 return head;
243 }
244
245 int deleteadmin()
246 {
247 printf("\n\t\t\t\t\tEnter serial no. of the food item which is to be deleted: ");
248 int num;
249 scanf("%d",&num);
250
251 struct node* temp=heada;
252 while(temp!=NULL)
253 {
254 if (temp->data == num)
255 {
256 heada = delete(num, heada, taila);
257 return 1;
258 }
259 temp=temp->next;
260 }
261
262 return 0;
263 }
264
265 int deletecustomer()
266 {
267 printf("\n\t\t\t\t\tEnter serial no. of the food item which is to be deleted: ");
268 int num;
269 scanf("%d",&num);
270
271 struct node* temp=headc;
272 while(temp!=NULL)
273 {
274 if (temp->data == num)
275 {
276 headc = delete(num, headc, tailc);
277 return 1;
278 }
279 temp=temp->next;
280 }
281
282 return 0;
283 }
284
285 void displaybill()
286 {
287 displayList(headc);
288 struct node *temp = headc;
289 float total_price = 0;
290 while (temp!=NULL)
291 {
292 total_price +=temp->price;
293 temp = temp->next;
294 }
295
296 printf("\t\t\t\t\t\t\tTotal price: %0.02f\n",total_price);
297
298 }
299
300 struct node* deleteList(struct node* head)
301 {
302 if(head==NULL)
303 {
304 return NULL;
305 }
306 else
307 {
308 struct node* temp = head;
309 while(temp->next!=0)
310 {
311 temp = temp->next;
312 free(temp->prev);
313 }
314 free(temp);
315 head = NULL;
316 }
317
318 return head;
319 }
320
321 void admin()
322 {
323 printf("\n\t\t\t\t\t ----------------------------------------------\n");
324 printf("\t\t\t\t\t\t\t ADMIN SECTION\n");
325 printf("\t\t\t\t\t ----------------------------------------------\n");
326 while(1)
327 {
328 adminmenu();
329
330 int opt;
331 scanf("%d",&opt);
332
333 if(opt==5)
334 break;
335
336 switch (opt)
337 {
338 case 1:
339 displayList(head_s);
340 break;
341 case 2:
342
343 printf("\n\t\t\t\t\t\t\tEnter serial no. of the food item: ");
344 int num,flag = 0;
345 char name[50];
346 float price;
347 scanf("%d",&num);
348
349 struct node *temp = heada;
350
351 while(temp!=NULL)
352 {
353 if(temp->data==num)
354 {
355 printf("\n\t\t\t\t\t\tFood item with given serial number already exists!!\n\n");
356 flag = 1;
357 break;
358 }
359 temp = temp->next;
360 }
361
362 if(flag==1)
363 break;
364
365 printf("\t\t\t\t\t\t\tEnter food item name: ");
366 scanf("%s",name);
367 printf("\t\t\t\t\t\t\tEnter price: ");
368 scanf("%f",&price);
369 heada = createadmin(heada, num, name, price);
370 printf("\n\t\t\t\t\t\t\tNew food item added to the list!!\n\n");
371 break;
372 case 3:
373 if(deleteadmin())
374 {
375 printf("\n\t\t\t\t\t\t### Updated list of food items menu ###\n");
376 displayList(heada);
377 }
378 else
379 printf("\n\t\t\t\t\t\tFood item with given serial number doesn't exist!\n\n");
380
381 break;
382 case 4:
383 printf("\n\t\t\t\t\t\t\t ### Order menu ###\n");
384 displayList(heada);
385 break;
386
387 default:
388 printf("\n\t\t\t\t\t\tWrong Input !! PLease choose valid option\n");
389 break;
390 }
391 }
392 }
393
394 void customer()
395 {
396 int flag=0,j=1;
397 char ch;
398 printf("\n\t\t\t\t\t ----------------------------------------------\n");
399 printf("\t\t\t\t\t\t\t CUSTOMER SECTION\n");
400 printf("\t\t\t\t\t ----------------------------------------------\n");
401 while(1)
402 {
403 customermenu();
404
405 int opt;
406 scanf("%d",&opt);
407
408 if(opt==5)
409 break;
410
411 switch (opt)
412 {
413 case 1:
414 displayList(heada);
415 printf("\n\t\t\t\t\t\tEnter number corresponding to the item you want to order: ");
416 int n;
417 scanf("%d",&n);
418 printf("\t\t\t\t\t\tEnter quantity: ");
419 int quantity;
420 scanf("%d",&quantity);
421 headc = createcustomer(headc, n, quantity);
422 break;
423 case 2:
424 printf("\n\t\t\t\t\t\t\t ### List of ordered items ###\n");
425 displayList(headc);
426 break;
427 case 3:
428 if(deletecustomer())
429 {
430 printf("\n\t\t\t\t\t\t### Updated list of your ordered food items ###\n");
431 displayList(headc);
432 }
433 else
434 printf("\n\t\t\t\t\t\tFood item with given serial number doesn't exist!!\n");
435 break;
436 case 4:
437 calculatetotsales();
438 printf("\n\t\t\t\t\t\t\t ### Final Bill ###\n");
439 displaybill();
440 headc = deleteList(headc);
441 printf("\n\t\t\t\t\t\tPress any key to return to main menu:\n\t\t\t\t\t\t");
442 fflush(stdin);
443 ch=fgetc(stdin);
444 flag=1;
445 break;
446
447 default:
448 printf("\n\t\t\t\t\t\tWrong Input !! PLease choose valid option\n");
449 break;
450 }
451 if(flag==1)
452 break;
453 }
454 }
455
456 void mainnenu()
457 {
458 printf("\n **************************************************************************\n");
459 printf(" WELCOME TO RESTAURANT MANAGEMENT SYSTEM\n");
460 printf(" **************************************************************************\n\n\n");
461 printf("\t\t\t\t\t\t\t1. ADMIN SECTION--> \n");
462 printf("\t\t\t\t\t\t\t2. CUSTOMER SECTION--> \n");
463 printf("\t\t\t\t\t\t\t3. Exit--> \n\n");
464 printf("\t\t\t\t\t\t\tEnter Your Choice --->");
465 }
466
467 int main()
468 {
469 heada = createadmin(heada,1,"Hot and Sour Soup",100);
470 heada = createadmin(heada,2,"Manchow Soup",200);
471 heada = createadmin(heada,3,"Manchurian Noodles",150);
472 heada = createadmin(heada,4,"Fried Rice",180);
473 heada = createadmin(heada,5,"Hakka Noodles",80);
474
475 while(1)
476 {
477 mainnenu();
478 int choice;
479 scanf("%d",&choice);
480
481 if(choice==3)
482 {
483 printf("\n\n\t\t\t\t\t\t\t**********Thank you!!**********\n");
484 break;
485 }
486
487 switch (choice)
488 {
489 case 1:
490 admin();
491 break;
492 case 2:
493 customer();
494 break;
495 case 3:
496 break;
497
498 default:
499 printf("\n\t\t\t\t\t\tWrong Input !! PLease choose valid option\n");
500 break;
501 }
502 }
503 }
What I have tried:
struct node* delete(int data,struct node *head, struct node* tail)
{
line :206
not able to figure out the error. can anyone help me out