-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode9.c
2167 lines (1651 loc) · 60.8 KB
/
code9.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
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<div>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<%
selected[i].ac_t[x]=32;
char pass[15]={0},check[15]={0},ch;
char uname[30], pass[30],passwrd[30]={0},id[10],nam[30];
int c=0,cnt=0;
char ex,stime[9],etime[9];
char *fp,*fp1,*tfp; // char pointers
char uname[30], pass[30],passwrd[30]={0},id[10],nam[30];
char otr_date[13],ttime[10]; // These are global variables to store system otr_date and time
char *fp,*fp1,*tfp; // char pointers
struct user//Structure for storing User information
{
char uid[4];
char name[30] ,password[30];
} user;
struct account//Structure for storing account information
{
char ac_no[8];
char fname[30], lname[30];
char u_otr_date[15];
char dob[12];
char sex;
char address[50],contact[20];
char ac_type;
float c_bal,interest,t_bal;
};
struct trans//Structure for storing transaction information
{
char ac_no[8],ac_t[25],_otr_date[15],_ttime[10],usr[30];
float amt;
};
typedef struct dos//Structure for storing user log information
{
char id[4];
char name[30];
char otr_date[15]; //Log in otr_date
char stime[10];// Log in time
char etime[10];// Log out or exit time
}user_log;
int gbl_flag=0;
int main()
{
char c;
welcome(); //Welcome sreen at beginning
do
{
system("cls"); //Clears the screen
rectangle(8,9,70,13);
gotoxy(10,11); printf("Press A to Log in as ADMINISTRATOR or S to log in as STAFF\n\n\n\t\t\t\t\t");
c=getche(); //Variable c stores the key pressed by user
if(c=='A'||c=='a')
{
strcpy(user.name,"Admin");
admin();
break;
}
if (c=='S'||c=='s')
{
staff();
break;
}
if (c==27) exit(0); //27 is ASCII code of escape key, means program exits when user presses Esc key insted to A or S
}while(1); //infinite loop incase any key other than Esc, A, or S is pressed.
return 0;
}
void staff()
{
int i,ch;
//Log in Screen begins...
char uname[30], pass[30],passwrd[30]={0},id[10],nam[30];
int c=0,cnt=0;
char ex,stime[9],etime[9];
cnt=0;//This variable cnt counts the number of attempts of Log in
do
{
system("cls");
rectangle(10,8,70,15);
gotoxy(7,5);printf("Only THREE attempts shall be allowed to enter username and password.");
gotoxy(23,10); printf("Enter User name : "); scanf("%s",user.name);
gotoxy(23,12); printf("Password : ");
char passwrd[30]={0};//To nullify the string passwrd
_password(passwrd);
strcpy(user.password,passwrd);
cnt++;
if (cnt==3)// when no of attempts exceeds 3
{
title();
gotoxy(25,10); printf("Invalid User name or Password!\a");
gotoxy(22,12);printf("Press ENTER to exit the program...");
getch();
exit(0);
}
c=0;//Counts the no. of user for which the name and password matches
fp=fopen("USER.DAT","r");
while(fscanf(fp,"%s %s %s\n",id,nam,pass)!=EOF)
{
strcpy(nam,strupr(nam));//Changing all strings id, nam, pass into uppercase
strcpy(pass,strupr(pass));
strcpy(user.name,strupr(user.name));
strcpy(user.password,strupr(user.password));
if((strcmp(user.name,nam)==0)&&(strcmp(user.password,pass)==0)) //if the combination matches value of c is increased and user id of req user is stored in user.id
{
c++;
strcpy(user.uid,id);
}
}
fclose(fp);
title();
if (c==0)// when no records are found c=0
{
gotoxy(10,10); printf("Cannot find the given combination of USER NAME and PASSWORD!\a");
getch();
}
else break; //terminates do... while loop if record found
} while(1);//not exactly infinite as user is prompted only maximum three times but the terminating conditions are on line 146 and 176
_strtime(stime);
//Log in screen ends
//Main Menu begins//
uptootr_date(); // To upotr_date interests
do
{
title();
gotoxy(15,8);printf("1. Create New Account\n");
gotoxy(15,10);printf("2. Cash Deposit");
gotoxy(15,12);printf("3. Cash Withdrawl");
gotoxy(15,14);printf("4. Fund Transfer");
gotoxy(15,16);printf("5. Account information");
gotoxy(45,8);printf("6. Transaction information");
gotoxy(45,10); printf("7. Log out");
gotoxy(45,12);printf("8. Exit");
gotoxy(1,17); for(i=0;i<78;i++) printf("_");
gotoxy(23,19);printf("Press a choice between the range [1-8] ");
switch(getch()-48)
{
case 1:
add_ac();
break;
case 2:
deposit();
break;
case 3:
withdraw();
break;
case 4:
fund_transfer();
break;
case 5:
ac_info();
break;
case 6:
transaction();
break;
case 7:
title();
gotoxy(15,10); printf("Are you sure you want to Log out? <Y/N> : ");
ex=getche();
if (ex=='Y'||ex=='y')
{
//if user wants to log out all user log information are stored in LOG.DAT and the function staff() called again i.e. log in screen begins again
_strtime(etime);
fp=fopen("LOG.DAT","a");
fprintf(fp,"%s %s %s %s\n",user.uid,otr_date,stime,etime);
fclose(fp);
staff();
}
break;
case 8:
title();
gotoxy(15,10); printf("Are you sure you want to exit? <Y/N> : ");
ex=getche();
if (ex=='Y'||ex=='y')
{
//if user wants to exit, all user log information are stored in LOG.DAT and the program is terminated
_strtime(etime);
fp=fopen("LOG.DAT","a");
fprintf(fp,"%s %s %s %s\n",user.uid,otr_date,stime,etime);
fclose(fp);
exit(0);
}
break;
default://when entered characted is not between 1-8
title();
gotoxy(10,10); printf("Your input is out of range! Enter a choice between 1 to 8!");
gotoxy(15,12); printf("Press any key to return to main menu...");
getch();
}
}while(1);//infinite loop to return to main menu after execution of any function
//return 0;
}
void add_ac()
{
// struct account ac;//structure variable ac created
char acn[8],curr[35],ch;
int i;
float irate;
fp=fopen("ACCOUNT.DAT","r");
if(fp==NULL) strcpy(ac.ac_no,"AC00001");//if "ACCOUNT.DAT" does not exist i.e. there are no records at all then A/C no. is taken AC00001 for 1st rec
else //otherwise a/c no of last record is accessed and increased by unit value which becomes the new a/c no.
{
while(fscanf(fp,"%s %s %s %s %s %s %c %s %c %f %f %f\n",ac.ac_no,ac.fname,ac.lname,ac.dob,ac.address,ac.contact,&ac.sex,ac.u_otr_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF2){
}//note the while statement is terminated without any statement inside it. This helps in geting the last rec. of the data char
increase(ac.ac_no);
}
fclose(fp);
title();
gotoxy(8,8); printf("PERSONAL DETAILS");
gotoxy(7,9); for(i=0;i<18;i++) printf("%c",205);
gotoxy(10,11); printf("Full name : "); scanf("%s",ac.fname); scanf("%s",ac.lname);
gotoxy(10,13); printf("Gender <M/F> : "); scanf(" %c",&ac.sex);
int temp1,temp2;
do
{
gotoxy(10,15); printf("DOB (dd/mm/yyyy) : "); scanf(" %s",ac.dob);
temp1=(ac.dob[6]-48)*1000+(ac.dob[7]-48)*100+(ac.dob[8]-48)*10+(ac.dob[9]-48);
temp2=2000+(otr_date[6]-48)*10+(otr_date[7]-48);
if(otr_date_check(ac.dob)==0||temp1>temp2)//checks if dob format is correct, on invalid format screen is partially cleared, beep tone is produced and asked to re-enter otr_date
{
printf("\a");
cls(10,15,60,15);
}
}while(otr_date_check(ac.dob)==0||temp1>temp2);//asks otr_date unless format is correct
_strotr_date(otr_date);
otr_date_input(ac.dob);//to change dd/mm/yyyy format to mm/dd/yy format to store in char
gotoxy(10,17); printf("Address : "); scanf(" %[^\n]s",ac.address);
for(i=0;i<strlen(ac.address);i++)//User may enter a space key for address (eg. New Baneswor). bt on reading formatted data from char space is taken as terminating char (eg. "New" and "Baneswor" are taken as separate variables. To remove this error, spaces entered by user is replace by '+'. Now "New+Baneswor is single string
if (ac.address[i]==32) ac.address[i]='+';
int err;
do
{
gotoxy(10,19); printf("Contact number : "); scanf(" %s",ac.contact);
err=0;
for(i=0;i<strlen(ac.contact);i++)
if(!((ac.contact[i]>='0'&&ac.contact[i]<='9'||ac.contact[i]=='-'||ac.contact[i]=='+')&&strlen(ac.contact)>=6)) err++;
if (err!=0) {printf("\a"); cls(10,19,70,19);}
} while(err!=0);
title();
gotoxy(8,8); printf("ACCOUNT DETAILS");
gotoxy(7,9); for(i=0;i<17;i++) printf("%c",205);
gotoxy(10,11); printf("A/C number : %s",ac.ac_no);
int flag;
do {
gotoxy(10,13); printf("A/C type <S/C> : "); scanf(" %c",&ac.ac_type);
flag=0;
cls(45,13,78,13); //clears screen partially to display full account type. Eg. when user enters 's', "Saving Account" is displayed
if (ac.ac_type=='S'||ac.ac_type=='s')
{
irate=8; //interest rate 8% for saving a/c
gotoxy(45,13); printf("Saving Account");
}
else if (ac.ac_type=='C'||ac.ac_type=='c')
{
irate=4; //interest rate 4% for current saving
gotoxy(45,13); printf("Current Saving");
}
else
{
printf("\a");
flag=1;//note that flag was initially zero. on error, its turned to 1
}
} while(flag==1);//for repeated asking of a/c type unless user enters correct input
otr_date_output(otr_date);
gotoxy(10,15); printf("Account Opened otr_date : %s",otr_date);
_strotr_date(otr_date);
strcpy(ac.u_otr_date,otr_date);//copies current otr_date to last upotr_dated otr_date
gotoxy(10,17); printf("Interest rate : %.2f%c per annum", irate,37);
do
{
gotoxy(10,19); printf("Opening Balance (in NRs.) : "); scanf("%f",&ac.c_bal);
if (ac.c_bal<0) { printf("\a"); cls(10,19,70,19);}
}while(ac.c_bal<0);
ac.interest=0;
ac.t_bal=ac.c_bal+ac.interest;
title();
gotoxy(3,9); printf("Full name : %s %s",ac.fname,ac.lname);
gotoxy(3,11); printf("Gender <M/F> : %c",ac.sex);
gotoxy(3,13); printf("DOB (mm/dd/yy) : %s",ac.dob);
gotoxy(3,15); printf("Address : ");
for(i=0;i<strlen(ac.address);i++)//In order to display address, '+' is replaced by space
if (ac.address[i]=='+') putchar(32);
else putchar(ac.address[i]);
gotoxy(3,17); printf("Contact number : %s",ac.contact);
gotoxy(43,9); printf("A/C number : %s",ac.ac_no);
gotoxy(43,11); printf("A/C type : ");
if (ac.ac_type=='S'||ac.ac_type=='s') printf("Saving Account");
if (ac.ac_type=='C'||ac.ac_type=='c') printf("Current Saving");
gotoxy(43,13); printf("Current otr_date : %s",otr_date);
gotoxy(43,15); printf("Interest rate : %.2f%c per annum", irate,37);
currency(curr,ac.c_bal);
gotoxy(43,17); printf("Opening Balance : %s",curr);
gotoxy(2,19); for(i=0;i<75;i++) printf("%c",196);
gotoxy(15,21); printf("Are the informations above all correct? <Y/N> ");
ch=getche();
if (ch=='Y'||ch=='y')//On confirmation, new a/c (in account.dat) + transaction showing "A/C Opened" is added (in transaction.dat)
{
fp=fopen("ACCOUNT.DAT","a");
fp1=fopen("TRANSACTION.DAT","a");
_strtime(ttime);
fprintf(fp1,"%s %s %s %s %.2f %s\n",ac.ac_no,"A/C+Opened",otr_date,ttime,ac.c_bal,user.name);
fprintf(fp,"%s %s %s %s %s %s %c %s %c %.2f %.2f %.2f\n",ac.ac_no,ac.fname,ac.lname,ac.dob,ac.address,ac.contact,ac.sex,ac.u_otr_date,ac.ac_type,ac.c_bal,ac.interest,ac.t_bal);
fclose(fp);
fclose(fp1);
title();
gotoxy(20,10); printf("Record Added Successfully!");
getch();
}
}
void uptootr_date()
{
//struct account ac;
int i,no_of_yr,no_of_month,no_of_days,n1,n2;
float r;
fp=fopen("ACCOUNT.DAT","r");
if (fp!=NULL)//performs every thing only when char exists i.e. only wen pointer is not null
{
fp1=fopen("TEMP.DAT","w");
i=0;
while(fscanf(fp,"%s %s %s %s %s %s %c %s %c %f %f %f\n",ac.ac_no,ac.fname,ac.lname,ac.dob,ac.address,ac.contact,&ac.sex,ac.u_otr_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
{
//extracting no of days, months and yr of system otr_date
no_of_yr=(otr_date[6]-48)*10+(otr_date[7]-48);
no_of_month=(otr_date[0]-48)*10+(otr_date[1]-48);
no_of_days=(otr_date[3]-48)*10+(otr_date[4]-48);
n1=no_of_yr*365+no_of_month*30+no_of_days;//n1 is no. of days elasped
//extracting no of days, months and yr of otr_date stored in ACCOUNT.DAT
no_of_yr=(ac.u_otr_date[6]-48)*10+(ac.u_otr_date[7]-48);
no_of_month=(ac.u_otr_date[0]-48)*10+(ac.u_otr_date[1]-48);
no_of_days=(ac.u_otr_date[3]-48)*10+(ac.u_otr_date[4]-48);
n2=no_of_yr*365+no_of_month*30+no_of_days;//n2 is no. of days elasped on last upotr_dated otr_date
if (ac.ac_type=='S'||ac.ac_type=='s') r=8.0/365; else r=4.0/365;
ac.t_bal=ac.c_bal*pow((1+r/100),n1-n2);//calculation of compound interest
ac.interest+=ac.t_bal-ac.c_bal;//calculation and addition of interest
ac.t_bal=ac.c_bal+ac.interest;//calculation of total balance
strcpy(ac.u_otr_date,otr_date);
fprintf(fp1,"%s %s %s %s %s %s %c %s %c %.2f %.2f %.2f\n",ac.ac_no,ac.fname,ac.lname,ac.dob,ac.address,ac.contact,ac.sex,ac.u_otr_date,ac.ac_type,ac.c_bal,ac.interest,ac.t_bal);
}
fclose(fp);
fclose(fp1);
system("del ACCOUNT.DAT");
system("ren TEMP.DAT ACCOUNT.DAT");
}
}
void deposit()
{
title();
// struct account ac;
char acn[10],curr[35],ch,csh[80],temp[80],nam[35];
int c=0;
float amt;
gotoxy(5,10); printf("Deposit to A/C number : "); scanf("%s",acn);
strcpy(acn,strupr(acn)); //changing a/c no. to uppercase
fp=fopen("ACCOUNT.DAT","r");
while(fscanf(fp,"%s %s %s %s %s %s %c %s %c %f %f %f\n",ac.ac_no,ac.fname,ac.lname,ac.dob,ac.address,ac.contact,&ac.sex,ac.u_otr_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
if(strcmp(acn,ac.ac_no)==0) { c++; strcpy(nam,ac.fname); strcat(nam," "); strcat(nam,ac.lname); } //variable c counts if the given a/c no exist in data char or not. also if available, the full name is extracted
fclose(fp);
if(c==0)//c=0 means no given a/c no. in data char
{
title();
gotoxy(20,12); printf("Given A/C number does not exits!");
getch();
return;
}
gotoxy(50,10); printf("[ %s ]",nam);
gotoxy(5,12); printf("Amount to be Deposited (in NRs.) : "); scanf("%f",&amt);
title();
gotoxy(30,10); printf("Confirm Transaction");
currency(curr,amt);
gotoxy(3,12); printf("%s to be deposited in A/C number : %s [ %s ]",curr,acn,nam);
//num2word((double)amt,csh);
strcpy(temp,"[In words : ");
strcat(temp,csh);
strcat(temp,"]");
gotoxy(40-strlen(temp)/2,14); puts(temp);
gotoxy(8,17);printf("Are you sure you want to perform this tranasction? <Y/N>");
ch=getche();
if (ch=='Y'||ch=='y')
{
fp=fopen("ACCOUNT.DAT","r");
fp1=fopen("TEMP.DAT","a");
while(fscanf(fp,"%s %s %s %s %s %s %c %s %c %f %f %f\n",ac.ac_no,ac.fname,ac.lname,ac.dob,ac.address,ac.contact,&ac.sex,ac.u_otr_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
{
if (strcmp(ac.ac_no,acn)==0) ac.c_bal+=amt;//balance is increased
ac.t_bal=ac.c_bal+ac.interest;
fprintf(fp1,"%s %s %s %s %s %s %c %s %c %.2f %.2f %.2f\n",ac.ac_no,ac.fname,ac.lname,ac.dob,ac.address,ac.contact,ac.sex,ac.u_otr_date,ac.ac_type,ac.c_bal,ac.interest,ac.t_bal);
}
fclose(fp1);
fclose(fp);
system("del ACCOUNT.DAT");
system("ren TEMP.DAT ACCOUNT.DAT");
fp=fopen("TRANSACTION.DAT","a");//transaction is added
_strtime(ttime);
fprintf(fp,"%s %s %s %s %.2f %s\n",acn,"Cash+Deposited",otr_date,ttime,amt,user.name);
fclose(fp);
title();
gotoxy(20,12);printf("Transaction completed successfully!");
getch();
}
}
void withdraw()//exactly similar to deposit. only difference is amount is subtracted.
{
title();
//struct account ac;
char acn[10],ch,curr[35],csh[80],temp[80], nam[50];
int c=0;
float amt;
gotoxy(5,10); printf("Withdraw from A/C number : "); scanf("%s",acn);
strcpy(acn,strupr(acn));
fp=fopen("ACCOUNT.DAT","r");
while(fscanf(fp,"%s %s %s %s %s %s %c %s %c %f %f %f\n",ac.ac_no,ac.fname,ac.lname,ac.dob,ac.address,ac.contact,&ac.sex,ac.u_otr_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
if(strcmp(acn,ac.ac_no)==0) { c++; strcpy(nam,ac.fname); strcat(nam," "); strcat(nam,ac.lname); }
fclose(fp);
if(c==0)
{
title();
gotoxy(20,12); printf("Given A/C number does not exits!");
getch();
return;
}
gotoxy(50,10); printf("[ %s ]",nam);
gotoxy(5,12); printf("Amount to be Withdrawn (in NRs.) : "); scanf("%f",&amt);
fp=fopen("ACCOUNT.DAT","r");
c=0;
while(fscanf(fp,"%s %s %s %s %s %s %c %s %c %f %f %f\n",ac.ac_no,ac.fname,ac.lname,ac.dob,ac.address,ac.contact,&ac.sex,ac.u_otr_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
{
if (strcmp(ac.ac_no,acn)==0&&ac.t_bal<amt)// when given amount is higher than bank balance
{
title();
gotoxy(20,12); printf("Sorry, the current balance is Rs. %.2f only!",ac.t_bal);
gotoxy(25,14); printf("Transaction NOT completed!");
c=1;
getch();
return;
}
}
fclose(fp);
title();
gotoxy(30,10); printf("Confirm Transaction");
currency(curr,amt);
gotoxy(3,12); printf("%s to be Withdrawn from A/C number : %s [%s]",curr,acn,nam);
//num2word((double)amt,csh);
strcpy(temp,"[In words : ");
strcat(temp,csh);
strcat(temp,"]");
gotoxy(40-strlen(temp)/2,14); puts(temp);
gotoxy(8,17);printf("Are you sure you want to perform this tranasction? <Y/N>");
ch=getche();
if (ch=='Y'||ch=='y')
{
fp=fopen("ACCOUNT.DAT","r");
fp1=fopen("TEMP.DAT","w");
c=0;
while(fscanf(fp,"%s %s %s %s %s %s %c %s %c %f %f %f\n",ac.ac_no,ac.fname,ac.lname,ac.dob,ac.address,ac.contact,&ac.sex,ac.u_otr_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
{
if (strcmp(ac.ac_no,acn)==0) ac.c_bal-=amt;
if (ac.c_bal<0) { ac.interest+=ac.c_bal; ac.c_bal=0; }
ac.t_bal=ac.c_bal+ac.interest;
fprintf(fp1,"%s %s %s %s %s %s %c %s %c %.2f %.2f %.2f\n",ac.ac_no,ac.fname,ac.lname,ac.dob,ac.address,ac.contact,ac.sex,ac.u_otr_date,ac.ac_type,ac.c_bal,ac.interest,ac.t_bal);
}
fclose(fp1);
fclose(fp);
system("del ACCOUNT.DAT");
system("ren TEMP.DAT ACCOUNT.DAT");
fp=fopen("TRANSACTION.DAT","a");
_strtime(ttime);
fprintf(fp,"%s %s %s %s %.2f %s\n",acn,"Cash+Withdrawn",otr_date,ttime,amt,user.name);
fclose(fp);
title();
gotoxy(20,12);printf("Transaction completed successfully!");
getch();
}
}
void fund_transfer()
{
char f_acn[8],t_acn[8],ch,curr[35],rem[25],csh[80]={0},temp[80]={0},fnam[35],tnam[35];
// struct account ac;
float amt;
int c=0;
title();
gotoxy(3,8); printf("Transferred from (A/C no. ) : "); scanf("%s",f_acn);
strcpy(f_acn,strupr(f_acn));
fp=fopen("ACCOUNT.DAT","r");
c=0;
while(fscanf(fp,"%s %s %s %s %s %s %c %s %c %f %f %f\n",ac.ac_no,ac.fname,ac.lname,ac.dob,ac.address,ac.contact,&ac.sex,ac.u_otr_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
if(strcmp(f_acn,ac.ac_no)==0) { c++; strcpy(fnam,ac.fname); strcat(fnam," "); strcat(fnam,ac.lname); }
fclose(fp);
if (c==0)
{
title();
gotoxy(20,12); printf("Given A/C number does not exits!");
getch();
return;
}
gotoxy(50,8); printf("[ %s ]",fnam);
gotoxy(3,10); printf("Transferred to (A/C no. ) : "); scanf("%s",t_acn);
strcpy(t_acn,strupr(t_acn));
fp=fopen("ACCOUNT.DAT","r");
c=0;
while(fscanf(fp,"%s %s %s %s %s %s %c %s %c %f %f %f\n",ac.ac_no,ac.fname,ac.lname,ac.dob,ac.address,ac.contact,&ac.sex,ac.u_otr_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
if(strcmp(t_acn,ac.ac_no)==0) { c++; strcpy(tnam,ac.fname); strcat(tnam," "); strcat(tnam,ac.lname); }
fclose(fp);
if (c==0)
{
title();
gotoxy(20,12); printf("Given A/C number does not exits!");
getch();
return;
}
gotoxy(50,10); printf("[ %s ]",tnam);
gotoxy(3,12); printf("Amount to be transferred (in NRs.) : "); scanf("%f",&amt);
fp=fopen("ACCOUNT.DAT","r");
c=0;
while(fscanf(fp,"%s %s %s %s %s %s %c %s %c %f %f %f\n",ac.ac_no,ac.fname,ac.lname,ac.dob,ac.address,ac.contact,&ac.sex,ac.u_otr_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
{
if (strcmp(ac.ac_no,f_acn)==0)
{
if (ac.t_bal<amt)
{
title();
gotoxy(15,12); printf("Sorry, the current balance is Rs. %.2f only!",ac.t_bal);
gotoxy(28,14); printf("Transaction NOT completed!");
getch();
return;
}
}
}
fclose(fp);
title();
gotoxy(30,8); printf("Confirm Transaction");
currency(curr,amt);
gotoxy(25,10); printf("%s to be Transfered",curr);
// num2word((double)amt,csh);
strcpy(temp,"[In words : ");
strcat(temp,csh);
strcat(temp,"]");
gotoxy(40-strlen(temp)/2,12); puts(temp);
gotoxy(18,14); printf("FROM A/C number %s [ %s ]",f_acn,fnam);
gotoxy(18,16); printf("TO A/C number %s [ %s ]",t_acn,tnam);
gotoxy(12,19);printf("Are you sure you want to perform this tranasction? <Y/N>");
ch=getche();
if (ch=='Y'||ch=='y')
{
fp=fopen("ACCOUNT.DAT","r");
fp1=fopen("TEMP.DAT","w");
c=0;
while(fscanf(fp,"%s %s %s %s %s %s %c %s %c %f %f %f\n",ac.ac_no,ac.fname,ac.lname,ac.dob,ac.address,ac.contact,&ac.sex,ac.u_otr_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
{
if (strcmp(ac.ac_no,f_acn)==0) ac.c_bal-=amt;
if (ac.c_bal<0) { ac.interest+=ac.c_bal; ac.c_bal=0; }
ac.t_bal=ac.c_bal+ac.interest;
fprintf(fp1,"%s %s %s %s %s %s %c %s %c %.2f %.2f %.2f\n",ac.ac_no,ac.fname,ac.lname,ac.dob,ac.address,ac.contact,ac.sex,ac.u_otr_date,ac.ac_type,ac.c_bal,ac.interest,ac.t_bal);
}
fclose(fp1);
fclose(fp);
system("del ACCOUNT.DAT");
system("ren TEMP.DAT ACCOUNT.DAT");
fp=fopen("ACCOUNT.DAT","r");
fp1=fopen("TEMP.DAT","w");
c=0;
while(fscanf(fp,"%s %s %s %s %s %s %c %s %c %f %f %f\n",ac.ac_no,ac.fname,ac.lname,ac.dob,ac.address,ac.contact,&ac.sex,ac.u_otr_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
{
if (strcmp(ac.ac_no,t_acn)==0) ac.c_bal+=amt;
ac.t_bal=ac.c_bal+ac.interest;
fprintf(fp1,"%s %s %s %s %s %s %c %s %c %.2f %.2f %.2f\n",ac.ac_no,ac.fname,ac.lname,ac.dob,ac.address,ac.contact,ac.sex,ac.u_otr_date,ac.ac_type,ac.c_bal,ac.interest,ac.t_bal);
}
fclose(fp1);
fclose(fp);
system("del ACCOUNT.DAT");
system("ren TEMP.DAT ACCOUNT.DAT");
fp=fopen("TRANSACTION.DAT","a");
_strtime(ttime);
strcpy(rem,"Transfered+to+");
strcat(rem,t_acn);
fprintf(fp,"%s %s %s %s %.2f %s\n",f_acn,rem,otr_date,ttime,amt,user.name);
strcpy(rem,"Received+from+");
strcat(rem,f_acn);
fprintf(fp,"%s %s %s %s %.2f %s\n",t_acn,rem,otr_date,ttime,amt,user.name);
fclose(fp);
title();
gotoxy(20,12);printf("Transaction completed successfully!");
getch();
}
}
void ac_info()
{
int i;
char buffer[30]={0},curr[35],curr1[35],curr2[35];
// struct account ac,srh;//structure variable srh stores the matched data from data char
float irate;
char c,acn[8];
int pos = 0,n=0,m=0,cnt;
title();//sub menu to search records
gotoxy(27,8);printf("1. Search by A/C number");
gotoxy(27,10);printf("2. Search by Name");
gotoxy(27,12);printf("3. Return to main menu");
gotoxy(25,16); printf("Press a choice between 1-3 ");
c=getche();
switch(c-48)
{
case 1:
title();
gotoxy(5,8); printf("Enter A/C number : ");
scanf("%s",acn);
strcpy(acn,strupr(acn));
fp=fopen("ACCOUNT.DAT","r");
cnt = 0;
while(fscanf(fp,"%s %s %s %s %s %s %c %s %c %f %f %f\n",ac.ac_no,ac.fname,ac.lname,ac.dob,ac.address,ac.contact,&ac.sex,ac.u_otr_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
{
if (strcmp(acn,ac.ac_no)==0) { srh=ac; cnt++; }// if a/c no matches, srh stores all values of ac
}
if (cnt==0)
{
title();
gotoxy(20,12); printf("Given A/C number does not exits!");
getch();
return;
}
ac=srh;
title();
gotoxy(3,9); printf("Full name : %s %s",ac.fname,ac.lname);
gotoxy(3,11); printf("Gender <M/F> : %c",ac.sex);
gotoxy(3,13); printf("DOB (mm/dd/yy) : %s",ac.dob);
gotoxy(3,15); printf("Address : ");
for(i=0;i<strlen(ac.address);i++)
if (ac.address[i]=='+') putchar(32);
else putchar(ac.address[i]);
gotoxy(3,17); printf("Contact number : %s",ac.contact);
gotoxy(43,9); printf("A/C number : %s",ac.ac_no);
gotoxy(43,11); printf("A/C type <S/F> : ");
if (ac.ac_type=='S'||ac.ac_type=='s') { printf("Saving Account"); irate=8.0; }
if (ac.ac_type=='C'||ac.ac_type=='c') { printf("Current Saving"); irate=4.0; }
gotoxy(43,13); printf("Interest rate : %.2f%c per annum", irate,37);
currency(curr,ac.c_bal);
gotoxy(43,15); printf("Current Balance : %s",curr);
currency(curr1,ac.interest);
gotoxy(43,17); printf("Interset : %s",curr1);
currency(curr2,ac.t_bal);
gotoxy(43,19); printf("Total Balance : %s",curr2);
gotoxy(2,21); for(i=0;i<75;i++) printf("%c",196);
gotoxy(5,22); printf("Press ENTER to search again or ANY OTHER KEY to return to main menu");
c=getch();
if(c==13) ac_info();//13 ascii code of enter
else return;
break;
case 2:
title();
gotoxy(5,6); printf("Enter first name : ");
do
{
gotoxy(2,7); for(i=0;i<75;i++) printf("%c",196);
gotoxy(2,20); for(i=0;i<75;i++) printf("%c",196);
gotoxy(15,21); printf("Press ENTER to view detailed information of FIRST record");
gotoxy(18,22); printf(" or press ESCAPE to return to main menu");
gotoxy(25+n,6);
c = getch();
if( isprint(c) )
{
buffer[ pos++ ] = c;
printf("%c", c);
n++;
}
else if( c == 8 && pos )
{
buffer[ pos-- ] = '\0';
printf("%s", "\b \b");
n--;
}
cls(3,10,75,11+m);
m=0;
gotoxy(3,8); printf("A/C no.");
gotoxy(13,8); printf("Full name");
gotoxy(43,8); printf("Contact no.");
gotoxy(60,8); printf("Net Balance");
gotoxy(2,9); for(i=0;i<75;i++) printf("%c",196);
fp=fopen("ACCOUNT.DAT","r");
while(fscanf(fp,"%s %s %s %s %s %s %c %s %c %f %f %f\n",ac.ac_no,ac.fname,ac.lname,ac.dob,ac.address,ac.contact,&ac.sex,ac.u_otr_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
{
cnt=0;
for(i=0;i<strlen(buffer);i++)
{
if(buffer[i]>='a'&&buffer[i]<='z') buffer[i]=buffer[i]-32;
if(ac.fname[i]>='a'&&ac.fname[i]<='z') ac.fname[i]=ac.fname[i]-32;
if(buffer[i]!=ac.fname[i]) cnt++;
}
if(cnt==0)
{
if(m==0) srh=ac;
if(m<=9)
{
gotoxy(3,10+m); printf("%s",ac.ac_no);
gotoxy(13,10+m); printf("%s %s",ac.fname,ac.lname);
gotoxy(43,10+m); printf("%s",ac.contact);
currency(curr,ac.t_bal);
gotoxy(55,10+m); printf("%20s",curr);
m++;
}
}
}
fclose(fp);
}while( c != 13&&c!=27 );
if (c==13)
{
ac=srh;
title();
gotoxy(3,9); printf("Full name : %s %s",ac.fname,ac.lname);
gotoxy(3,11); printf("Gender <M/F> : %c",ac.sex);
gotoxy(3,13); printf("DOB (mm/dd/yy) : %s",ac.dob);
gotoxy(3,15); printf("Address : ");
for(i=0;i<strlen(ac.address);i++)
if (ac.address[i]=='+') putchar(32);
else putchar(ac.address[i]);
gotoxy(3,17); printf("Contact number : %s",ac.contact);
gotoxy(43,9); printf("A/C number : %s",ac.ac_no);
gotoxy(43,11); printf("A/C type <S/F> : ");
if (ac.ac_type=='S'||ac.ac_type=='s') { printf("Saving Account"); irate=8.0; }
if (ac.ac_type=='C'||ac.ac_type=='c') { printf("Current Saving"); irate=4.0; }
gotoxy(43,13); printf("Interest rate : %.2f%c per annum", irate,37);
currency(curr,ac.c_bal);
gotoxy(43,15); printf("Current Balance : %s",curr);
currency(curr1,ac.interest);
gotoxy(43,17); printf("Interset : %s",curr1);
currency(curr2,ac.t_bal);
gotoxy(43,19); printf("Total Balance : %s",curr2);
gotoxy(2,21); for(i=0;i<75;i++) printf("%c",196);
gotoxy(5,22); printf("Press ENTER to search again or ANY OTHER KEY to return to main menu");
c=getch();
if(c==13) ac_info();
else return;
}
break;
case 3:
return;
break;
default:
title();
gotoxy(10,10); printf("Your input is out of range! Enter a choice between 1 to 8!");
gotoxy(15,12); printf("Press any key to return to main menu...");
getch();
ac_info();
}