-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
524 lines (494 loc) · 18.6 KB
/
main.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
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
//stock
struct stock
{
char book_name[50];
int quantity;
struct stock *next;
int shelf;
int cost;
int sell;
}*start=NULL;
//purchase
struct node
{
char book_name[50];
int qty;
int sell;
int total;
int profit;
struct node *next,*prev;
}*top=NULL;
//stack program
//push a purchase
void push(struct stock *temp,int n)
{
struct node *newnode;
newnode=(struct node*)malloc(sizeof(struct node));
strcpy(newnode->book_name,temp->book_name);
newnode->qty=n;
newnode->sell=temp->sell;
newnode->total=n*temp->sell;
newnode->profit=(n*(temp->sell - temp->cost));
if(top==NULL)
{
top=newnode;
newnode->next=NULL;
newnode->prev=NULL;
}
else
{
newnode->prev=top;
newnode->next=NULL;
top->next=newnode;
top=newnode;
}
}
//display purchase list
void display_record()
{
struct node *temp,*temp1;
temp=top;
if(top==NULL)
{
printf("\n\n\n\n\t\t\t\t\t\tNo Records Found");
}
else
{
char b[20]="BOOKS",q[10]="QUANTITY",p[10]="PRICE",t[10]="TOTAL",e[10]="PROFIT";
printf("\n\n\n\t\t\t%-20s%-15s%-15s%-15s%-15s\n",b,q,p,t,e);
while(temp->prev!=NULL)
{
printf("%-20s%-15d%-15d%-15d%-15d\n",temp->book_name,temp->qty,temp->sell,temp->total,temp->profit);
temp1=temp;
temp=temp->prev;
free(temp1);
}
printf("\n\n\t\t\t%-20s%-15d%-15d%-15d%-15d\n",temp->book_name,temp->qty,temp->sell,temp->total,temp->profit);
free(temp1);
}
}
//stock program
//add new book
void insert_new_book()
{
struct stock *temp,*newnode;
char s[50];
int n,sh,cost,sell;
printf("\n\n\t\t\t\t\t\tEnter Book Name:");
scanf("%s",s);
printf("\n\t\t\t\t\t\tEnter Quantity:");
scanf("%d",&n);
printf("\n\t\t\t\t\t\tEnter Shelf No:");
scanf("%d",&sh);
printf("\n\t\t\t\t\t\tEnter Cost Price: Rs ");
scanf("%d",&cost);
printf("\n\t\t\t\t\t\tEnter Sell Price: Rs ");
scanf("%d",&sell);
newnode=(struct stock*)malloc(sizeof(struct stock));
strcpy(newnode->book_name,s);
newnode->quantity=n;
newnode->shelf=sh;
newnode->cost=cost;
newnode->sell=sell;
if(start==NULL)
{
start=newnode;
newnode->next=NULL;
}
else
{
temp=start;
while(temp->next!=NULL)
{
temp=temp->next;
}
temp->next=newnode;
newnode->next=NULL;
}
}
//search a book
struct stock *srch()
{
struct stock *temp;
printf("\n\n\n\t\t\t\t\t\tEnter Book Name :");
char s[50];
scanf("%s",s);
temp=start;
while(temp!=NULL)
{
if(strcmp(s,temp->book_name)==0)
{
break;
}
else
{
temp=temp->next;
}
}
return temp;
}
//display details of a book
void display_book(struct stock *temp)
{
printf("\n\n\t\t\t\t\t\tBook Name: %s\n",temp->book_name);
printf("\n\t\t\t\t\t\tQuantity Available: %d\n",temp->quantity);
printf("\n\t\t\t\t\t\tShelf No.: %d\n",temp->shelf);
printf("\n\t\t\t\t\t\tPrice : Rs %d",temp->sell);
}
//refill a book
void refill()
{
int q;
struct stock *temp;
temp=srch();
display_book(temp);
printf("\n\n\t\t\t\t\t\tEnter Quantity To Add : ");
scanf("%d",&q);
temp->quantity=temp->quantity+q;
printf("\n\t\t\t\t\t\tCurrent quantity : %d",temp->quantity);
}
// sell a book
int sell(struct stock *temp)
{
int n;
printf("\n\n\n\t\t\t\t\t\tEnter No. of Books : ");
scanf("%d",&n);
if(temp->quantity==0)
{
printf("\n\n\t\t\t\t\t\tStock Not Available");
return 0;
}
else if(n>(temp->quantity))
{
printf("\n\n\t\t\t\t\t\tStock Not Sufficient\n\t\t\t\t\t\tAvailable Stock : %d",temp->quantity);
return 0;
}
else
{
temp->quantity=temp->quantity-n;
push(temp,n);
printf("\n\n\n\t\t\t\t\t\tBooks sold successfully!\n");
return 0;
}
}
//Demand list
// A linked list (LL) node to store a queue entry
struct QNode {
char person_name[50];
char book_name[50];
int contact;
int units;
struct QNode* next;
};
// The queue, front stores the front node of LL and rear stores the
// last node of LL
struct Queue {
struct QNode *front, *rear;
};
// A function to create an empty queue
struct Queue* createQueue()
{
struct Queue* q = (struct Queue*)malloc(sizeof(struct Queue));
q->front = NULL;
q->rear = NULL;
return q;
}
// The function to add a value to q
void enQueue(struct Queue* q)
{
// Create a new LL node
struct QNode *newnode;
newnode= (struct QNode*)malloc(sizeof(struct QNode));
char p_name[50],b_name[50];
int num,unit_book;
printf("\n\n\n\t\t\t\t\tEnter the name of Person : ");
scanf("%s",p_name);
printf("\n\t\t\t\t\tEnter the required book : ");
scanf("%s",b_name);
printf("\n\t\t\t\t\tEnter no of units : ");
scanf("%d",&unit_book);
printf("\n\t\t\t\t\tEnter contact no : ");
scanf("%d",&num);
strcpy(newnode->person_name,p_name);
strcpy(newnode->book_name,b_name);
newnode->contact = num;
newnode->units = unit_book;
// If queue is empty, then new node is front and rear both
if (q->rear == NULL) {
q->front = q->rear = newnode;
}
else
{
q->rear->next = newnode;
q->rear = newnode;
}
}
// Function to remove a value from given queue q
void deQueue(struct Queue* q)
{
struct QNode *temp=q->front;
if(q->rear == q->front)
{
q->front=NULL;
q->rear=NULL;
}
else
{
q->front=q->front->next;
}
free(temp);
}
void displayList(struct Queue* q)
{
struct QNode *temp;
temp=q->front;
char n[10]="NAME",b[10]="BOOK",c[10]="CONTACT";
printf("\n\n\n\t\t\t\t\t%-20s%-20s%-20s\n",n,b,c);
while(temp!=NULL)
{
printf("\n\n\t\t\t\t\t%-20s%-20s%-20d\n",temp->person_name,temp->book_name,temp->contact);
temp=temp->next;
}
}
void store()
{
printf("\n\n\n\t\t\t\t\t\tSYMPHONY BOOK STORE");
printf("\n\n\t\t\t\tHigh Cliff Building, Sector 5,Vile Parle(West),Mumbai");
printf("\n\n\t\t\t\t\tContact no: 34980237823/82379202932");
printf("\n========================================================================================================================");
}
int main()
{
int option=0;
struct Queue* qp=createQueue();
while(option!=5)
{
system("cls");
system("COLOR F1");
printf("\n\n\n\t\t\t\t\t %c WELCOME TO SYMPHONY BOOK STORE %c \n ",(char)174,(char)175);
printf("\n\n\t\t\t\tHigh Cliff Building, Sector 5,Vile Parle(West),Mumbai");
printf("\n\n\t\t\t\t\tContact no: 34980237823/82379202932");
printf("\n\n\n************************************************************************************************************************");
printf("\n\n\t\t\t\t\t\t\tMAIN MENU\n\n");
printf("************************************************************************************************************************");
printf("\n\n\t\t\t\t\t\t\t1.SELL A BOOK\n");
printf("\t\t\t\t\t\t\t2.STOCK ANALYSIS\n");
printf("\t\t\t\t\t\t\t3.PURCHASE RECORD\n");
printf("\t\t\t\t\t\t\t4.DEMAND LIST\n");
printf("\t\t\t\t\t\t\t5.EXIT\n");
printf("\n\n\t\t\t\t\t\t\tENTER YOUR CHOICE : ");
scanf("%d",&option);
switch(option)
{
//case 1 sell
case 1:
{
system("cls");
system("COLOR 0D");
printf("\n\n\n\t\t\t\t\t\tSYMPHONY BOOK STORE");
printf("\n\n\t\t\t\tHigh Cliff Building, Sector 5,Vile Parle(West),Mumbai");
printf("\n\n\t\t\t\t\tContact no: 34980237823/82379202932");
printf("\n========================================================================================================================");
struct stock* var=srch();
if(var !=NULL)
{
sell(var);
}
else
{
printf("\n\n\n\t\t\t\t\t\tNot available");
}
}
//end of sell
printf("\n\n\n\t\t\t\t\t\tPress any key to continue");
getch();
break;
//case 2 stock
case 2:
{
system("cls");
system("COLOR F4");
printf("\n\n\n\t\t\t\t\t\tSYMPHONY BOOK STORE");
printf("\n\n\t\t\t\tHigh Cliff Building, Sector 5,Vile Parle(West),Mumbai");
printf("\n\n\t\t\t\t\tContact no: 34980237823/82379202932");
printf("\n========================================================================================================================");
printf("\n\n\n\t\t\t\t\t\t1.Insert a new book\n\n\t\t\t\t\t\t2.Search a book\n\n\t\t\t\t\t\t3.Refill books\n");
int opt1;
printf("\n\n\t\t\t\t\t\tENTER YOUR CHOICE : ");
scanf("%d",&opt1);
switch(opt1)
{
case 1:
{
system("cls");
printf("\n\n\n\t\t\t\t\t\tSYMPHONY BOOK STORE");
printf("\n\n\t\t\t\tHigh Cliff Building, Sector 5,Vile Parle(West),Mumbai");
printf("\n\n\t\t\t\t\tContact no: 34980237823/82379202932");
printf("\n========================================================================================================================");
insert_new_book();
printf("\n\n\t\t\t\t\t\tPress any key to continue");
getch();
}
break;
case 2:
{
system("cls");
printf("\n\n\n\t\t\t\t\t\tSYMPHONY BOOK STORE");
printf("\n\n\t\t\t\tHigh Cliff Building, Sector 5,Vile Parle(West),Mumbai");
printf("\n\n\t\t\t\t\tContact no: 34980237823/82379202932");
printf("\n========================================================================================================================");
struct stock *temp1=srch();
if (temp1!=NULL)
{
display_book(temp1);
}
else
{
printf("\n\t\t\t\t\t\tNot in stock");
}
printf("\n\n\t\t\t\t\t\tPress any key to continue");
getch();
}
break;
case 3:
{
system("cls");
printf("\n\n\n\t\t\t\t\t\tSYMPHONY BOOK STORE");
printf("\n\n\t\t\t\tHigh Cliff Building, Sector 5,Vile Parle(West),Mumbai");
printf("\n\n\t\t\t\t\tContact no: 34980237823/82379202932");
printf("\n========================================================================================================================");
refill();
printf("\n\n\t\t\t\t\t\tPress any key to continue");
getch();
}
}
}
//end of stock
break;
//case 3 purchase record
case 3:
{
system("cls");
system("COLOR 0E");
printf("\n\n\n\t\t\t\t\t\tSYMPHONY BOOK STORE");
printf("\n\n\t\t\t\tHigh Cliff Building, Sector 5,Vile Parle(West),Mumbai");
printf("\n\n\t\t\t\t\tContact no: 34980237823/82379202932");
printf("\n========================================================================================================================");
printf("\n\n\n\n\t\t\t\t\t\t\tSALES RECORD");
printf("\n\n\t\t\t\t\t\t1.Display records\n\n\t\t\t\t\t\t2.Insert in purchase\n");
int opt2;
printf("\n\t\t\t\t\t\tENTER YOUR CHOICE : ");
scanf("%d",&opt2);
switch(opt2)
{
case 1:
{
system("cls");
printf("\n\n\n\t\t\t\t\t\tSYMPHONY BOOK STORE");
printf("\n\n\t\t\t\tHigh Cliff Building, Sector 5,Vile Parle(West),Mumbai");
printf("\n\n\t\t\t\t\tContact no: 34980237823/82379202932");
printf("\n========================================================================================================================");
printf("\n\n\n\n\t\t\t\t\t\t\tSALES RECORD");
display_record();
printf("\n\n\t\t\t\t\t\tPress any key to continue");
getch();
}
break;
case 2:
{
system("cls");
int n_book;
printf("\n\n\n\t\t\t\t\t\tSYMPHONY BOOK STORE");
printf("\n\n\t\t\t\tHigh Cliff Building, Sector 5,Vile Parle(West),Mumbai");
printf("\n\n\t\t\t\t\tContact no: 34980237823/82379202932");
printf("\n========================================================================================================================");
struct stock *var2=srch();
printf("\n\n\t\t\t\t\t\tEnter the number of units : ");
scanf("%d",&n_book);
if(var2!=NULL)
push(var2,n_book);
else
{
printf("\n\n\t\t\t\t\t\tNot in stock\n");
}
printf("\n\n\t\t\t\t\t\tPress any key to continue");
getch();
}
}
}
//end of purchase
break;
//case 4 demand list
case 4:
{
system("cls");
system("COLOR F0");
printf("\n\n\n\t\t\t\t\t\tSYMPHONY BOOK STORE");
printf("\n\n\t\t\t\tHigh Cliff Building, Sector 5,Vile Parle(West),Mumbai");
printf("\n\n\t\t\t\t\tContact no: 34980237823/82379202932");
printf("\n========================================================================================================================");
printf("\n\n\n\t\t\t\t\t\t1.Display demand list\n\n\t\t\t\t\t\t2.Insert demand\n\n\t\t\t\t\t\t3.Clear demand\n");
int opt3;
printf("\n\n\t\t\t\t\t\tEnter your choice : ");
scanf("%d",&opt3);
switch(opt3)
{
case 1:
{
system("cls");
store();
displayList(qp);
printf("\n\n\t\t\t\t\t\tPress any key to continue");
getch();
}
break;
case 2:
{
system("cls");
store();
enQueue(qp);
printf("\n\n\t\t\t\t\t\tPress any key to continue");
getch();
}
break;
case 3:
{
system("cls");
store();
struct stock *temp3=start;
while(temp3!=NULL)
{
if(strcmp(qp->front->book_name,temp3->book_name)==0 )
{
if(temp3->quantity>= qp->front->units)
{
push(temp3,qp->front->units);
temp3->quantity=temp3->quantity-(qp->front->units);
deQueue(qp);
break;
}
else{
printf("\n\n\t\t\t\t\t\tPlease refill stock!\n");
break;
}
}
else
{
temp3=temp3->next;
}
}
printf("\n\n\t\t\t\t\t\tPress any key to continue");
getch();
break;
}
}
}
//end of demand list
}
//end of switch
}
}