-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.c
624 lines (535 loc) · 11.6 KB
/
run.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
#include <stdio.h>
#include <string.h>
#include<conio.h>
#include<stdlib.h>
#include<unistd.h>
#define BUFFER_SIZE 1000
#define INFINITY 9999
#define MAX 10
char name[40];
int amount;
void login();
void order();
void status();
void orders();
void deposits();
int indexOf(FILE *fptr, const char *word, int *line, int *col);
void dijkstra(int G[MAX][MAX],int n,int startnode);
int nom,noo,noi,nop,amount,count;
int dij(){
int G[MAX][MAX],i,j,n,u;
printf("Enter no. of vertices:");
scanf("%d",&n);
printf("\nEnter the cost matrix:\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&G[i][j]);
printf("\nEnter the starting node:");
scanf("%d",&u);
dijkstra(G,n,u);
return 0;
}
void dijkstra(int G[MAX][MAX],int n,int startnode)
{
int cost[MAX][MAX],distance[MAX],pred[MAX];
int visited[MAX],count,mindistance,nextnode,i,j;
//pred[] stores the predecessor of each node
//count gives the number of nodes seen so far
//create the cost matrix
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(G[i][j]==0)
cost[i][j]=INFINITY;
else
cost[i][j]=G[i][j];
//initialize pred[],distance[] and visited[]
for(i=0;i<n;i++)
{
distance[i]=cost[startnode][i];
pred[i]=startnode;
visited[i]=0;
}
distance[startnode]=0;
visited[startnode]=1;
count=1;
while(count<n-1)
{
mindistance=INFINITY;
//nextnode gives the node at minimum distance
for(i=0;i<n;i++)
if(distance[i]<mindistance&&!visited[i])
{
mindistance=distance[i];
nextnode=i;
}
//check if a better path exists through nextnode
visited[nextnode]=1;
for(i=0;i<n;i++)
if(!visited[i])
if(mindistance+cost[nextnode][i]<distance[i])
{
distance[i]=mindistance+cost[nextnode][i];
pred[i]=nextnode;
}
count++;
}
//print the path and distance of each node
for(i=0;i<n;i++)
if(i!=startnode)
{
printf("\nDistance of node%d=%d",i,distance[i]);
printf("\nPath=%d",i);
j=i;
do
{
j=pred[j];
printf("<-%d",j);
}while(j!=startnode);
}
}
void signup()
{
FILE *ptr;
// integer variable
long long int Phone_No; // This for large no.
// character variable
char name[40];
char veh[10];
char so[25];
char us[15];
char password[10];
// open the file in write mode
ptr = fopen("customer.txt", "a");
if (ptr != NULL) {
printf("File created successfully!\n");
}
else {
printf("Failed to create the file.\n");
}
FILE *wpr;
wpr = fopen("amount.txt", "a");
if (wpr != NULL) {
printf("total amount gained\n");
}
else {
printf("Failed to create the file.\n");
}
// get student detail
printf("Welcome! Please Enter your information\n");
printf("Enter your name: \n");
scanf("%s",&name);
printf("Enter Phone no: \n");
scanf("%lld",&Phone_No);
printf("Enter Vehcile no: \n");
scanf("%s",&veh);
printf("Enter source: \n");
scanf("%s",&so);
printf("\n --------------------------- ");
printf("\n ENTER USERNAME: \n");
scanf("%s",&us);
printf("\n ENTER PASSWORD: \n");
scanf("%s",&password);
// write data in file
fprintf(ptr, "name" "\t%s" "\tphone no" "\t%lld", name, Phone_No);
fprintf(ptr, "\t");
fprintf(ptr, "vehicle no" "\t%s" "\tsource" "\t%s", veh, so);
fprintf(ptr, "\t");
fprintf(ptr, "username" "\t%s" "\tsecurity" "\t%s", us, password);
fprintf(ptr, "\n");
fprintf(wpr, "name" "\t%s" "username" "\t%s", name, us);
fprintf(wpr, "\n");
fclose(wpr);
// close connection
fclose(ptr);
}
//==============================================================================================================================================
void Customer()
{
int ch;
printf("\n\n\t\t\t\t\t\t\t If you are new Customer Then first register yourself else signup");
printf("\n\n\t\t\t\t\t\t\t\t Would you like to log in or register yourself");
printf("\n[1] Login\n");
printf("[2] Register");
printf("\n[3] Exit\n");
scanf("%d",&ch);
switch (ch)
{
case 1:
login();
order();
break;
case 2:
signup();
order();
break;
case 3:
default:
printf("exit");
break;
case 4:
exit(0);
printf("Bye BYe HAve A GreAT DAY");
}
}
//=====================================================================//=====================================================================
void details()
{
int u;
printf("\n What would You like to see\n");
printf("\n[1] Orders\n");
//printf("\n[2] Deposits\n");
printf("\n[3] Status\n");
printf("Enter your choice");
scanf("%d",&u);
switch (u)
{
case 1:
orders();
break;
case 2:
deposits();
break;
case 3:
status();
break;
}
}
void status()
{
printf("status");
FILE *wpr;
wpr = fopen("amount.txt", "a");
if (wpr != NULL) {
printf("total amount gained\n");
fprintf(wpr, "name" "\t%s" "\tamount" "\t%lld", name, amount);
}
else {
printf("Failed to create the file.\n");
}
fclose(wpr);
}
void orders()
{
FILE*cptr;
printf("orders");
cptr = fopen("customer.txt", "r");
/* Exit if file not opened successfully */
if (cptr == NULL)
{
printf("Unable to open file.\n");
}
fclose(cptr);
}
/*void deposits()
{
printf("deposits");
}
*/
//============================================================================================================================================
void loginme()
{
char s1[8]="password";
char s2[8];
printf("Hello Administrator,Enter password");
scanf("%s",&s2);
if(!strcmp(s1,s2))
{
printf("Verified Authenticated");
details();
}
else
{ printf("wrong");
}
}
//============================================================================================================================================
int Administrator()
{
int z;
printf("\n Press 1 to login\n");
printf("\n[1] Login\n");
printf("\n[4] Exit\n");
scanf("%d",&z);
switch (z)
{
case 1:
loginme();
break;
default:
exit(0);
}
}
/*int show()
{int o;
printf("\nWhat Would you like to see\n [1]Details \n[2]Status \n[3]No of orders");
scanf("%d",&o);
switch (o)
{
case 1:
details();
break;
case 2:
status();
break;
case 3:
orders();
break;
default:
printf("exit");
}
}
*/
//==============================================================================================================================================
void login()
{
int i;
char name[20], password[20], ch;
printf("Enter your username");
scanf("%s", &name);
printf("password:\n");
int p=0;
do{
password[p]=getch();
if(password[p]!='\r'){
printf("*");
}
p++;
}while(password[p-1]!='\r');
password[p-1]='\0';
printf("Username : %s",name);
printf("\n Password :",password);
getch();
FILE *vptr;
vptr = fopen("customer.txt", "a");
fprintf(vptr, "%s %s", name, password);
fprintf(vptr, "\n");
FILE *fptr;
char path[100];
char word[50];
int line, col;
fptr = fopen("customer.txt", "r");
/* Exit if file not opened successfully */
if (fptr == NULL)
{
printf("Unable to open file.\n");
printf("Please check you have read/write previleges.\n");
exit(EXIT_FAILURE);
}
// Find index of word in fptr
indexOf(fptr, password, &line, &col);
if (line != -1)
{
printf("Verified");
}
else
{printf("'%s' does not exists.", password);
exit(0);
}
// Close file
fclose(fptr);
}
int indexOf(FILE *fptr, const char *password, int *line, int *col)
{
char str[BUFFER_SIZE];
char *pos;
*line = -1;
*col = -1;
while ((fgets(str, BUFFER_SIZE, fptr)) != NULL)
{
*line += 1;
// Find first occurrence of word in str
pos = strstr(str, password);
if (pos != NULL)
{
// First index of word in str is
// Memory address of pos - memory
// address of str.
*col = (pos - str);
break;
}
}
// If word is not found then set line to -1
if (*col == -1)
*line = -1;
return *col;
}
//printf("=======================================================");
int showstatus()
{
FILE *str;
str = fopen("customer.txt", "a");
if (str != NULL) {
printf("Order Written!\n Thankyou,Visit Again\n");
}
else {
printf("Failed to create the file.\n");
}
FILE *tpr;
tpr = fopen("amount.txt", "a");
if (tpr != NULL) {
printf("total amount gained\n");
}
else {
printf("Failed to create the file.\n");
}
printf("\n quantity of maggi=%d",nom);
printf("\n quantity of omlete=%d",noo);
printf("\n quantity of idli=%d",noi);
printf("\n quantity of paratha=%d",nop);
printf("\n quantity of total food ordered=%d",nom+noo+noi+nop);
printf("\n total amount gain=%d",amount);
fprintf(str, "\tmaggi" "\t%d" "\tomellete""\t%d" "\tidli""\t%d" "\tparatha""\t%d" "\tquantity""\t%d" "\ttotal""\t%d", nom, noo, noi, nop, nom+noo+noi+nop, amount);
fprintf(tpr,"\tamount" "\t%d", amount);
fprintf(tpr, "\n");
fprintf(str, "\n");
// close connection
fclose(str);
fclose(tpr);
}
int maggi()
{
printf("\n foodorder received");
nom++;
amount = amount+ 50;
count++;
}
int omlete()
{
printf("\n foodorder received");
noo++;
amount = amount+ 30;
count++;
}
int idli()
{
printf("\n foodorder received");
noi++;
amount = amount+ 35;
count++;
}
int paratha()
{
printf("\n foodorder received");
nop++;
amount = amount+ 40;
count++;
}
int reset()
{
int q;
printf("enter the choice you want to decrease");
scanf("%d",&q);
switch(q)
{
case 1:
nom=--nom;
amount=amount-50;
break;
case 2:
noo=--noo;
amount = amount- 30;
break;
case 3:
noi=--noi;
amount = amount- 35;
break;
case 4:
nop=--nop;
amount = amount- 40;
break;
case 5:
count=--count;
break;
default:
printf("bye bye");
break;
}
}
void order()
{
int j,i,p;
while(1)
{
//Choose food item from Menu
printf(" \n CHOOSE: ");
printf("\n Sno. Itemlist ");
printf("\n 1 maggi ");
printf("\n 2 omlete ");
printf("\n 3 idli ");
printf("\n 4 paratha ");
//printf("Other Options");
printf("\n 5 showstatus");
printf("\n 6 reset");
printf("\n 7 exit");
printf("\n 8 terminate");
printf("\nenter your choice");
scanf("%d",&j);
switch(j)
{
case 1:
maggi();
break;
case 2:
omlete();
break;
case 3:
idli();
break;
case 4:
paratha();
break;
case 5:
showstatus();
break;
case 6:
reset();
break;
case 7:
if (amount> 1)
{
dij();
}
else
{
printf("first order or terminate");
printf("press 1 for order and press 2 for terminate");
scanf("%d",&p);
if (p ==1)
{
order();
}
else
{
exit(0);
}
}
break;
case 8:
exit(0);
break;
default:
printf("\n Invalid choice");
break;
}
}
//return 0;
}
int main()
{
int w,y;
printf("\n\n\t\t\t\t\t\t\t\t Welcome to Drive & pick");
printf("\n\n\t\t\t\t\t\t\t Hello, Hope You are Doing Great");
printf("\n Who are you? \n[1]Adminstrator \n[2]Customer");
scanf("%d",&w);
switch(w)
{
case 1:
Administrator();
break;
case 2:
Customer();
break;
default:
exit(0);
}
return 0;
}