Note - Double Click to Copy Code Contact Us!

Bank Management using C

Tech Doubility
Bank Management using C

C Code
  1. #include <stdio.h>//For standard I/O Operation
  2. #include <stdlib.h>//To use functions like system(); system("dos command"); - this performs the dos command given. Eg. system("del abc.txt"); - This command deletes the file abc.txt from current location of project
  3. #include <windows.h>//Used in making gotoxy(int, int) function
  4. #include <conio.h>//For getch(); getche() type of functions
  5. #include <time.h>//To get system date and time
  6. #include <math.h>//To calculate mathematical problems, used esp. in interest calculation
  7.  
  8.  
  9. //I've divided our user defined functions into two parts: Minor Functions (which are used frequently to support execution of core porgram) and Major Functions (which are a part of core program). Minor function definition from Line 12-25. Major function definitions from Line 27-40.
  10.  
  11. void gotoxy(int x,int y); //To move the cursor to x column and y row of output screen
  12. void _password(char buffer[]);// To input password from user so that asterik (*) is displayed for each character entered. Similar to gets(string); function
  13. void rectangle(int x,int y,int l,int b);// To make a rectangle starting from (x,y) with length l and breadth b
  14. void cls(int x1,int y1,int x2, int y2); // To clear only certain portion of screen starting from (x1,y1) to (x2,y2). Notice this function has been used in date entry. When date is not in dd/mm/yyyy format, the wrong value is cleared on the screen
  15. void increase(char i_id[]); // To increase ID by unit value. Eg. U001 ---> U002 and AC00099 ---> AC00100. Since i_id is an array, it is passed by reference. So the input value and changed value is obtained from same variable i_id[]
  16. void date_input(char date[]); // To convert date in format dd/mm/yyyy (The format in which user is asked to enter date) to mm/dd/yyyy (The format in which date is stored in data file)
  17. void date_output(char date[]); //To convert date in format mm/dd/yy to dd MMM, yyyy. Eg. 01/01/11 is changed to 01 Jan, 2011
  18. void currency(char cur[], float n); // To convert a floating number n into currency format in Hindu Arabic Number system. Eg. on execution of the statement currency(cur,123456.789); the value of cur will be "1,23,456.78"
  19. void num2word(double n,char word[]);// To convert a floating (double) number n into word according to Hindu Arabic Number System
  20. void _one(int n, char one[]); // This function is a part of function num2word(). Simple function that stores "One " for 1, "Two " for 2, ... upto 19 in string varaible one[].
  21. void _ten(int n,char ten[]); // This function is a part of function num2word(). Simple function that stores "Ten " for 10, "Twenty " for 20, ... upto 90 in string varaible ten[].
  22. int date_check(char date[]);//Function to check if date is in format dd/mm/yyyy or not. Returns 0 if the format is not valid and 1 for valid format.
  23. void title();//Clears the screen and displays Program title, Current User and Current date on top of Screen
  24. void welcome();// Displays welcome screen that you see as soon as program is executed
  25.  
  26. void admin();// Main program for ADMIN portion to manage user
  27. void add_user();// To add a new user
  28. void del_user();// To delete an existing user
  29. void edit_user();// To edit user name and/or password of existing user
  30. void view_log();// To view log history of user
  31.  
  32. void staff();//Main program for STAFF portion to manage accounts
  33. void uptodate();// This function updates every account by calculating interest and stores the updated value. This function runs every time the program is executed.
  34. void add_ac();// To create a new account
  35. void deposit(); // To deposit cash in A/C
  36. void withdraw(); // To withdraw cash from A/C
  37. void fund_transfer();// To transfer cash from one account to another
  38. void ac_info();// To view informations about the A/C and account holder
  39. void transaction();// To view all the trasactions of an A/C
  40.  
  41.  
  42.  
  43. char date[13],ttime[10]; // These are global variables to store system date and time
  44.  
  45. FILE *fp,*fp1,*tfp; // File pointers
  46.  
  47. struct//Structure for storing User information
  48. {
  49. char uid[4];
  50. char name[30], password[30];
  51.  
  52. } user;
  53.  
  54. struct account//Structure for storing account information
  55. {
  56. char ac_no[8];
  57. char fname[30], lname[30];
  58. char u_date[15];
  59. char dob[12];
  60. char sex;
  61. char address[50],contact[20];
  62. char ac_type;
  63. float c_bal,interest,t_bal;
  64. };
  65.  
  66. struct trans//Structure for storing transaction information
  67. {
  68. char ac_no[8],ac_t[25],_date[15],_ttime[10],usr[30];
  69. float amt;
  70. };
  71.  
  72. typedef struct//Structure for storing user log information
  73. {
  74. char id[4];
  75. char name[30];
  76. char date[15]; //Log in date
  77. char stime[10];// Log in time
  78. char etime[10];// Log out or exit time
  79. }user_log;
  80.  
  81. int gbl_flag=0;
  82.  
  83. int main()
  84. {
  85. char c;
  86. welcome(); //Welcome sreen at beginning
  87. do
  88. {
  89. system("cls"); //Clears the screen
  90. rectangle(8,9,70,13);
  91. 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");
  92. c=getche(); //Variable c stores the key pressed by user
  93.  
  94. if(c=='A'||c=='a')
  95. {
  96. strcpy(user.name,"Admin");
  97. admin();
  98. break;
  99. }
  100. if (c=='S'||c=='s')
  101. {
  102. staff();
  103. break;
  104. }
  105. 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
  106.  
  107. }while(1); //infinite loop incase any key other than Esc, A, or S is pressed.
  108.  
  109.  
  110.  
  111. return 0;
  112. }
  113.  
  114.  
  115.  
  116.  
  117. void staff()
  118. {
  119. int i,ch;
  120. //Log in Screen begins...
  121.  
  122. char uname[30], pass[30],passwrd[30]={0},id[10],nam[30];
  123. int c=0,cnt=0;
  124. char ex,stime[9],etime[9];
  125.  
  126.  
  127. cnt=0;//This variable cnt counts the number of attempts of Log in
  128. do
  129. {
  130. system("cls");
  131. rectangle(10,8,70,15);
  132. gotoxy(7,5);printf("Only THREE attempts shall be allowed to enter username and password.");
  133. gotoxy(23,10); printf("Enter User name : "); scanf("%s",user.name);
  134. gotoxy(23,12); printf("Password : ");
  135. char passwrd[30]={0};//To nullify the string passwrd
  136. _password(passwrd);
  137. strcpy(user.password,passwrd);
  138. cnt++;
  139.  
  140. if (cnt==3)// when no of attempts exceeds 3
  141. {
  142. title();
  143. gotoxy(25,10); printf("Invalid User name or Password!\a");
  144. gotoxy(22,12);printf("Press ENTER to exit the program...");
  145. getch();
  146. exit(0);
  147. }
  148.  
  149.  
  150.  
  151. c=0;//Counts the no. of user for which the name and password matches
  152. fp=fopen("USER.DAT","r");
  153. while(fscanf(fp,"%s %s %s\n",id,nam,pass)!=EOF)
  154. {
  155. strcpy(nam,strupr(nam));//Changing all strings id, nam, pass into uppercase
  156. strcpy(pass,strupr(pass));
  157. strcpy(user.name,strupr(user.name));
  158. strcpy(user.password,strupr(user.password));
  159.  
  160. 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
  161. {
  162. c++;
  163. strcpy(user.uid,id);
  164. }
  165. }
  166.  
  167. fclose(fp);
  168.  
  169. title();
  170. if (c==0)// when no records are found c=0
  171. {
  172.  
  173. gotoxy(10,10); printf("Cannot find the given combination of USER NAME and PASSWORD!\a");
  174. getch();
  175. }
  176. else break; //terminates do... while loop if record found
  177.  
  178.  
  179.  
  180.  
  181. } while(1);//not exactly infinite as user is prompted only maximum three times but the terminating conditions are on line 146 and 176
  182.  
  183.  
  184. _strtime(stime);
  185.  
  186. //Log in screen ends
  187.  
  188.  
  189.  
  190.  
  191.  
  192. //Main Menu begins//
  193. uptodate(); // To update interests
  194. do
  195. {
  196. title();
  197.  
  198. gotoxy(15,8);printf("1. Create New Account\n");
  199. gotoxy(15,10);printf("2. Cash Deposit");
  200. gotoxy(15,12);printf("3. Cash Withdrawl");
  201. gotoxy(15,14);printf("4. Fund Transfer");
  202. gotoxy(15,16);printf("5. Account information");
  203. gotoxy(45,8);printf("6. Transaction information");
  204. gotoxy(45,10); printf("7. Log out");
  205. gotoxy(45,12);printf("8. Exit");
  206.  
  207.  
  208. gotoxy(1,17); for(i=0;i<78;i++) printf("_");
  209. gotoxy(23,19);printf("Press a choice between the range [1-8] ");
  210.  
  211. switch(getch()-48)
  212. {
  213. case 1:
  214.  
  215. add_ac();
  216.  
  217.  
  218. break;
  219. case 2:
  220.  
  221.  
  222. deposit();
  223.  
  224.  
  225. break;
  226. case 3:
  227.  
  228. withdraw();
  229.  
  230. break;
  231.  
  232. case 4:
  233.  
  234. fund_transfer();
  235. break;
  236. case 5:
  237. ac_info();
  238.  
  239. break;
  240. case 6:
  241. transaction();
  242.  
  243. break;
  244.  
  245.  
  246. case 7:
  247. title();
  248. gotoxy(15,10); printf("Are you sure you want to Log out? <Y/N> : ");
  249. ex=getche();
  250. if (ex=='Y'||ex=='y')
  251. {
  252. //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
  253. _strtime(etime);
  254. fp=fopen("LOG.DAT","a");
  255. fprintf(fp,"%s %s %s %s\n",user.uid,date,stime,etime);
  256. fclose(fp);
  257. staff();
  258. }
  259.  
  260.  
  261. break;
  262.  
  263.  
  264. case 8:
  265.  
  266. title();
  267. gotoxy(15,10); printf("Are you sure you want to exit? <Y/N> : ");
  268. ex=getche();
  269. if (ex=='Y'||ex=='y')
  270. {
  271. //if user wants to exit, all user log information are stored in LOG.DAT and the program is terminated
  272.  
  273. _strtime(etime);
  274. fp=fopen("LOG.DAT","a");
  275. fprintf(fp,"%s %s %s %s\n",user.uid,date,stime,etime);
  276. fclose(fp);
  277. exit(0);
  278. }
  279.  
  280.  
  281. break;
  282.  
  283. default://when entered characted is not between 1-8
  284. title();
  285. gotoxy(10,10); printf("Your input is out of range! Enter a choice between 1 to 8!");
  286. gotoxy(15,12); printf("Press any key to return to main menu...");
  287. getch();
  288.  
  289. }
  290.  
  291. }while(1);//infinite loop to return to main menu after execution of any function
  292.  
  293.  
  294. //return 0;
  295. }
  296.  
  297.  
  298.  
  299. void add_ac()
  300. {
  301. struct account ac;//structure variable ac created
  302. char acn[8],curr[35],ch;
  303. int i;
  304. float irate;
  305.  
  306. fp=fopen("ACCOUNT.DAT","r");
  307. 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
  308. else //otherwise a/c no of last record is accessed and increased by unit value which becomes the new a/c no.
  309. {
  310. 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_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF);//note the while statement is terminated without any statement inside it. This helps in geting the last rec. of the data file
  311. increase(ac.ac_no);
  312. }
  313.  
  314. fclose(fp);
  315.  
  316. title();
  317. gotoxy(8,8); printf("PERSONAL DETAILS");
  318. gotoxy(7,9); for(i=0;i<18;i++) printf("%c",205);
  319. gotoxy(10,11); printf("Full name : "); scanf("%s",ac.fname); scanf("%s",ac.lname);
  320. gotoxy(10,13); printf("Gender <M/F> : "); scanf(" %c",&ac.sex);
  321. int temp1,temp2;
  322. do
  323. {
  324. gotoxy(10,15); printf("DOB (dd/mm/yyyy) : "); scanf(" %s",ac.dob);
  325. temp1=(ac.dob[6]-48)*1000+(ac.dob[7]-48)*100+(ac.dob[8]-48)*10+(ac.dob[9]-48);
  326. temp2=2000+(date[6]-48)*10+(date[7]-48);
  327. if(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 date
  328. {
  329. printf("\a");
  330. cls(10,15,60,15);
  331.  
  332. }
  333. }while(date_check(ac.dob)==0||temp1>temp2);//asks date unless format is correct
  334.  
  335. _strdate(date);
  336. date_input(ac.dob);//to change dd/mm/yyyy format to mm/dd/yy format to store in file
  337. gotoxy(10,17); printf("Address : "); scanf(" %[^\n]s",ac.address);
  338. 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 file 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
  339. if (ac.address[i]==32) ac.address[i]='+';
  340. int err;
  341. do
  342. {
  343. gotoxy(10,19); printf("Contact number : "); scanf(" %s",ac.contact);
  344. err=0;
  345. for(i=0;i<strlen(ac.contact);i++)
  346. if(!((ac.contact[i]>='0'&&ac.contact[i]<='9'||ac.contact[i]=='-'||ac.contact[i]=='+')&&strlen(ac.contact)>=6)) err++;
  347. if (err!=0) {printf("\a"); cls(10,19,70,19);}
  348. } while(err!=0);
  349. title();
  350. gotoxy(8,8); printf("ACCOUNT DETAILS");
  351. gotoxy(7,9); for(i=0;i<17;i++) printf("%c",205);
  352. gotoxy(10,11); printf("A/C number : %s",ac.ac_no);
  353. int flag;
  354. do {
  355. gotoxy(10,13); printf("A/C type <S/C> : "); scanf(" %c",&ac.ac_type);
  356. flag=0;
  357. cls(45,13,78,13); //clears screen partially to display full account type. Eg. when user enters 's', "Saving Account" is displayed
  358. if (ac.ac_type=='S'||ac.ac_type=='s')
  359. {
  360. irate=8; //interest rate 8% for saving a/c
  361. gotoxy(45,13); printf("Saving Account");
  362. }
  363. else if (ac.ac_type=='C'||ac.ac_type=='c')
  364. {
  365. irate=4; //interest rate 4% for current saving
  366. gotoxy(45,13); printf("Current Saving");
  367. }
  368. else
  369. {
  370. printf("\a");
  371. flag=1;//note that flag was initially zero. on error, its turned to 1
  372. }
  373.  
  374. } while(flag==1);//for repeated asking of a/c type unless user enters correct input
  375.  
  376. date_output(date);
  377. gotoxy(10,15); printf("Account Opened Date : %s",date);
  378. _strdate(date);
  379. strcpy(ac.u_date,date);//copies current date to last updated date
  380. gotoxy(10,17); printf("Interest rate : %.2f%c per annum", irate,37);
  381. do
  382. {
  383. gotoxy(10,19); printf("Opening Balance (in NRs.) : "); scanf("%f",&ac.c_bal);
  384. if (ac.c_bal<0) { printf("\a"); cls(10,19,70,19);}
  385. }while(ac.c_bal<0);
  386. ac.interest=0;
  387. ac.t_bal=ac.c_bal+ac.interest;
  388.  
  389. title();
  390. gotoxy(3,9); printf("Full name : %s %s",ac.fname,ac.lname);
  391. gotoxy(3,11); printf("Gender <M/F> : %c",ac.sex);
  392. gotoxy(3,13); printf("DOB (mm/dd/yy) : %s",ac.dob);
  393. gotoxy(3,15); printf("Address : ");
  394. for(i=0;i<strlen(ac.address);i++)//In order to display address, '+' is replaced by space
  395. if (ac.address[i]=='+') putchar(32);
  396. else putchar(ac.address[i]);
  397.  
  398. gotoxy(3,17); printf("Contact number : %s",ac.contact);
  399.  
  400. gotoxy(43,9); printf("A/C number : %s",ac.ac_no);
  401. gotoxy(43,11); printf("A/C type : ");
  402. if (ac.ac_type=='S'||ac.ac_type=='s') printf("Saving Account");
  403. if (ac.ac_type=='C'||ac.ac_type=='c') printf("Current Saving");
  404.  
  405. gotoxy(43,13); printf("Current Date : %s",date);
  406. gotoxy(43,15); printf("Interest rate : %.2f%c per annum", irate,37);
  407. currency(curr,ac.c_bal);
  408. gotoxy(43,17); printf("Opening Balance : %s",curr);
  409. gotoxy(2,19); for(i=0;i<75;i++) printf("%c",196);
  410.  
  411. gotoxy(15,21); printf("Are the informations above all correct? <Y/N> ");
  412. ch=getche();
  413.  
  414. if (ch=='Y'||ch=='y')//On confirmation, new a/c (in account.dat) + transaction showing "A/C Opened" is added (in transaction.dat)
  415. {
  416. fp=fopen("ACCOUNT.DAT","a");
  417. fp1=fopen("TRANSACTION.DAT","a");
  418. _strtime(ttime);
  419. fprintf(fp1,"%s %s %s %s %.2f %s\n",ac.ac_no,"A/C+Opened",date,ttime,ac.c_bal,user.name);
  420. 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_date,ac.ac_type,ac.c_bal,ac.interest,ac.t_bal);
  421. fclose(fp);
  422. fclose(fp1);
  423. title();
  424. gotoxy(20,10); printf("Record Added Successfully!");
  425. getch();
  426. }
  427.  
  428.  
  429.  
  430. }
  431.  
  432. void uptodate()
  433. {
  434. struct account ac;
  435. int i,no_of_yr,no_of_month,no_of_days,n1,n2;
  436. float r;
  437. fp=fopen("ACCOUNT.DAT","r");
  438.  
  439. if (fp!=NULL)//performs every thing only when file exists i.e. only wen pointer is not null
  440. {
  441. fp1=fopen("TEMP.DAT","w");
  442. i=0;
  443. 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_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
  444. {
  445. //extracting no of days, months and yr of system date
  446. no_of_yr=(date[6]-48)*10+(date[7]-48);
  447. no_of_month=(date[0]-48)*10+(date[1]-48);
  448. no_of_days=(date[3]-48)*10+(date[4]-48);
  449.  
  450. n1=no_of_yr*365+no_of_month*30+no_of_days;//n1 is no. of days elasped
  451.  
  452. //extracting no of days, months and yr of date stored in ACCOUNT.DAT
  453. no_of_yr=(ac.u_date[6]-48)*10+(ac.u_date[7]-48);
  454. no_of_month=(ac.u_date[0]-48)*10+(ac.u_date[1]-48);
  455. no_of_days=(ac.u_date[3]-48)*10+(ac.u_date[4]-48);
  456. n2=no_of_yr*365+no_of_month*30+no_of_days;//n2 is no. of days elasped on last updated date
  457.  
  458. if (ac.ac_type=='S'||ac.ac_type=='s') r=8.0/365; else r=4.0/365;
  459.  
  460. ac.t_bal=ac.c_bal*pow((1+r/100),n1-n2);//calculation of compound interest
  461. ac.interest+=ac.t_bal-ac.c_bal;//calculation and addition of interest
  462. ac.t_bal=ac.c_bal+ac.interest;//calculation of total balance
  463. strcpy(ac.u_date,date);
  464. 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_date,ac.ac_type,ac.c_bal,ac.interest,ac.t_bal);
  465.  
  466. }
  467. fclose(fp);
  468. fclose(fp1);
  469. system("del ACCOUNT.DAT");
  470. system("ren TEMP.DAT ACCOUNT.DAT");
  471. }
  472.  
  473.  
  474. }
  475.  
  476. void deposit()
  477. {
  478. title();
  479. struct account ac;
  480. char acn[10],curr[35],ch,csh[80],temp[80],nam[35];
  481. int c=0;
  482. float amt;
  483.  
  484. gotoxy(5,10); printf("Deposit to A/C number : "); scanf("%s",acn);
  485. strcpy(acn,strupr(acn)); //changing a/c no. to uppercase
  486. fp=fopen("ACCOUNT.DAT","r");
  487. 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_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
  488. 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 file or not. also if available, the full name is extracted
  489.  
  490. fclose(fp);
  491.  
  492. if(c==0)//c=0 means no given a/c no. in data file
  493. {
  494. title();
  495. gotoxy(20,12); printf("Given A/C number does not exits!");
  496. getch();
  497. return;
  498. }
  499.  
  500. gotoxy(50,10); printf("[ %s ]",nam);
  501. gotoxy(5,12); printf("Amount to be Deposited (in NRs.) : "); scanf("%f",&amt);
  502. title();
  503. gotoxy(30,10); printf("Confirm Transaction");
  504. currency(curr,amt);
  505. gotoxy(3,12); printf("%s to be deposited in A/C number : %s [ %s ]",curr,acn,nam);
  506.  
  507. num2word((double)amt,csh);
  508. strcpy(temp,"[In words : ");
  509. strcat(temp,csh);
  510. strcat(temp,"]");
  511. gotoxy(40-strlen(temp)/2,14); puts(temp);
  512.  
  513. gotoxy(8,17);printf("Are you sure you want to perform this tranasction? <Y/N>");
  514. ch=getche();
  515. if (ch=='Y'||ch=='y')
  516. {
  517. fp=fopen("ACCOUNT.DAT","r");
  518. fp1=fopen("TEMP.DAT","a");
  519. 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_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
  520. {
  521. if (strcmp(ac.ac_no,acn)==0) ac.c_bal+=amt;//balance is increased
  522. ac.t_bal=ac.c_bal+ac.interest;
  523. 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_date,ac.ac_type,ac.c_bal,ac.interest,ac.t_bal);
  524. }
  525. fclose(fp1);
  526. fclose(fp);
  527. system("del ACCOUNT.DAT");
  528. system("ren TEMP.DAT ACCOUNT.DAT");
  529.  
  530. fp=fopen("TRANSACTION.DAT","a");//transaction is added
  531. _strtime(ttime);
  532. fprintf(fp,"%s %s %s %s %.2f %s\n",acn,"Cash+Deposited",date,ttime,amt,user.name);
  533. fclose(fp);
  534. title();
  535. gotoxy(20,12);printf("Transaction completed successfully!");
  536. getch();
  537.  
  538.  
  539. }
  540.  
  541.  
  542.  
  543. }
  544.  
  545. void withdraw()//exactly similar to deposit. only difference is amount is subtracted.
  546. {
  547. title();
  548. struct account ac;
  549. char acn[10],ch,curr[35],csh[80],temp[80], nam[50];
  550. int c=0;
  551. float amt;
  552.  
  553. gotoxy(5,10); printf("Withdraw from A/C number : "); scanf("%s",acn);
  554. strcpy(acn,strupr(acn));
  555. fp=fopen("ACCOUNT.DAT","r");
  556. 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_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
  557. if(strcmp(acn,ac.ac_no)==0) { c++; strcpy(nam,ac.fname); strcat(nam," "); strcat(nam,ac.lname); }
  558. fclose(fp);
  559.  
  560. if(c==0)
  561. {
  562. title();
  563. gotoxy(20,12); printf("Given A/C number does not exits!");
  564. getch();
  565. return;
  566. }
  567.  
  568. gotoxy(50,10); printf("[ %s ]",nam);
  569. gotoxy(5,12); printf("Amount to be Withdrawn (in NRs.) : "); scanf("%f",&amt);
  570.  
  571.  
  572.  
  573. fp=fopen("ACCOUNT.DAT","r");
  574.  
  575. c=0;
  576. 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_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
  577. {
  578.  
  579. if (strcmp(ac.ac_no,acn)==0&&ac.t_bal<amt)// when given amount is higher than bank balance
  580. {
  581. title();
  582. gotoxy(20,12); printf("Sorry, the current balance is Rs. %.2f only!",ac.t_bal);
  583. gotoxy(25,14); printf("Transaction NOT completed!");
  584. c=1;
  585. getch();
  586. return;
  587. }
  588.  
  589. }
  590. fclose(fp);
  591.  
  592.  
  593. title();
  594. gotoxy(30,10); printf("Confirm Transaction");
  595. currency(curr,amt);
  596. gotoxy(3,12); printf("%s to be Withdrawn from A/C number : %s [%s]",curr,acn,nam);
  597. num2word((double)amt,csh);
  598. strcpy(temp,"[In words : ");
  599. strcat(temp,csh);
  600. strcat(temp,"]");
  601. gotoxy(40-strlen(temp)/2,14); puts(temp);
  602. gotoxy(8,17);printf("Are you sure you want to perform this tranasction? <Y/N>");
  603. ch=getche();
  604.  
  605.  
  606. if (ch=='Y'||ch=='y')
  607. {
  608. fp=fopen("ACCOUNT.DAT","r");
  609. fp1=fopen("TEMP.DAT","w");
  610. c=0;
  611. 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_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
  612. {
  613. if (strcmp(ac.ac_no,acn)==0) ac.c_bal-=amt;
  614. if (ac.c_bal<0) { ac.interest+=ac.c_bal; ac.c_bal=0; }
  615. ac.t_bal=ac.c_bal+ac.interest;
  616.  
  617. 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_date,ac.ac_type,ac.c_bal,ac.interest,ac.t_bal);
  618. }
  619. fclose(fp1);
  620. fclose(fp);
  621. system("del ACCOUNT.DAT");
  622. system("ren TEMP.DAT ACCOUNT.DAT");
  623.  
  624.  
  625.  
  626.  
  627.  
  628. fp=fopen("TRANSACTION.DAT","a");
  629. _strtime(ttime);
  630. fprintf(fp,"%s %s %s %s %.2f %s\n",acn,"Cash+Withdrawn",date,ttime,amt,user.name);
  631. fclose(fp);
  632. title();
  633. gotoxy(20,12);printf("Transaction completed successfully!");
  634.  
  635. getch();
  636.  
  637.  
  638.  
  639.  
  640. }
  641.  
  642.  
  643.  
  644. }
  645.  
  646.  
  647. void fund_transfer()
  648. {
  649. char f_acn[8],t_acn[8],ch,curr[35],rem[25],csh[80]={0},temp[80]={0},fnam[35],tnam[35];
  650. struct account ac;
  651. float amt;
  652. int c=0;
  653.  
  654. title();
  655.  
  656. gotoxy(3,8); printf("Transferred from (A/C no. ) : "); scanf("%s",f_acn);
  657.  
  658. strcpy(f_acn,strupr(f_acn));
  659. fp=fopen("ACCOUNT.DAT","r");
  660. c=0;
  661. 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_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
  662. if(strcmp(f_acn,ac.ac_no)==0) { c++; strcpy(fnam,ac.fname); strcat(fnam," "); strcat(fnam,ac.lname); }
  663. fclose(fp);
  664.  
  665. if (c==0)
  666. {
  667. title();
  668. gotoxy(20,12); printf("Given A/C number does not exits!");
  669. getch();
  670. return;
  671. }
  672.  
  673. gotoxy(50,8); printf("[ %s ]",fnam);
  674. gotoxy(3,10); printf("Transferred to (A/C no. ) : "); scanf("%s",t_acn);
  675.  
  676. strcpy(t_acn,strupr(t_acn));
  677. fp=fopen("ACCOUNT.DAT","r");
  678. c=0;
  679. 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_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
  680. if(strcmp(t_acn,ac.ac_no)==0) { c++; strcpy(tnam,ac.fname); strcat(tnam," "); strcat(tnam,ac.lname); }
  681. fclose(fp);
  682.  
  683. if (c==0)
  684. {
  685. title();
  686. gotoxy(20,12); printf("Given A/C number does not exits!");
  687. getch();
  688. return;
  689. }
  690.  
  691.  
  692. gotoxy(50,10); printf("[ %s ]",tnam);
  693. gotoxy(3,12); printf("Amount to be transferred (in NRs.) : "); scanf("%f",&amt);
  694.  
  695.  
  696.  
  697.  
  698. fp=fopen("ACCOUNT.DAT","r");
  699.  
  700. c=0;
  701. 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_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
  702. {
  703. if (strcmp(ac.ac_no,f_acn)==0)
  704. {
  705. if (ac.t_bal<amt)
  706. {
  707. title();
  708. gotoxy(15,12); printf("Sorry, the current balance is Rs. %.2f only!",ac.t_bal);
  709. gotoxy(28,14); printf("Transaction NOT completed!");
  710. getch();
  711. return;
  712. }
  713. }
  714. }
  715. fclose(fp);
  716.  
  717.  
  718.  
  719. title();
  720. gotoxy(30,8); printf("Confirm Transaction");
  721. currency(curr,amt);
  722. gotoxy(25,10); printf("%s to be Transfered",curr);
  723. num2word((double)amt,csh);
  724. strcpy(temp,"[In words : ");
  725. strcat(temp,csh);
  726. strcat(temp,"]");
  727. gotoxy(40-strlen(temp)/2,12); puts(temp);
  728. gotoxy(18,14); printf("FROM A/C number %s [ %s ]",f_acn,fnam);
  729. gotoxy(18,16); printf("TO A/C number %s [ %s ]",t_acn,tnam);
  730. gotoxy(12,19);printf("Are you sure you want to perform this tranasction? <Y/N>");
  731. ch=getche();
  732.  
  733.  
  734. if (ch=='Y'||ch=='y')
  735. {
  736. fp=fopen("ACCOUNT.DAT","r");
  737. fp1=fopen("TEMP.DAT","w");
  738. c=0;
  739. 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_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
  740. {
  741. if (strcmp(ac.ac_no,f_acn)==0) ac.c_bal-=amt;
  742. if (ac.c_bal<0) { ac.interest+=ac.c_bal; ac.c_bal=0; }
  743. ac.t_bal=ac.c_bal+ac.interest;
  744.  
  745. 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_date,ac.ac_type,ac.c_bal,ac.interest,ac.t_bal);
  746. }
  747. fclose(fp1);
  748. fclose(fp);
  749. system("del ACCOUNT.DAT");
  750. system("ren TEMP.DAT ACCOUNT.DAT");
  751.  
  752. fp=fopen("ACCOUNT.DAT","r");
  753. fp1=fopen("TEMP.DAT","w");
  754. c=0;
  755. 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_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
  756. {
  757. if (strcmp(ac.ac_no,t_acn)==0) ac.c_bal+=amt;
  758. ac.t_bal=ac.c_bal+ac.interest;
  759.  
  760. 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_date,ac.ac_type,ac.c_bal,ac.interest,ac.t_bal);
  761. }
  762. fclose(fp1);
  763. fclose(fp);
  764. system("del ACCOUNT.DAT");
  765. system("ren TEMP.DAT ACCOUNT.DAT");
  766.  
  767.  
  768. fp=fopen("TRANSACTION.DAT","a");
  769. _strtime(ttime);
  770. strcpy(rem,"Transfered+to+");
  771. strcat(rem,t_acn);
  772. fprintf(fp,"%s %s %s %s %.2f %s\n",f_acn,rem,date,ttime,amt,user.name);
  773. strcpy(rem,"Received+from+");
  774. strcat(rem,f_acn);
  775. fprintf(fp,"%s %s %s %s %.2f %s\n",t_acn,rem,date,ttime,amt,user.name);
  776. fclose(fp);
  777. title();
  778. gotoxy(20,12);printf("Transaction completed successfully!");
  779. getch();
  780.  
  781.  
  782.  
  783.  
  784. }
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793. }
  794.  
  795.  
  796. void ac_info()
  797. {
  798.  
  799. int i;
  800.  
  801. char buffer[30]={0},curr[35],curr1[35],curr2[35];
  802. struct account ac,srh;//structure variable srh stores the matched data from data file
  803. float irate;
  804. char c,acn[8];
  805.  
  806. int pos = 0,n=0,m=0,cnt;
  807.  
  808. title();//sub menu to search records
  809. gotoxy(27,8);printf("1. Search by A/C number");
  810. gotoxy(27,10);printf("2. Search by Name");
  811. gotoxy(27,12);printf("3. Return to main menu");
  812. gotoxy(25,16); printf("Press a choice between 1-3 ");
  813. c=getche();
  814. switch(c-48)
  815. {
  816. case 1:
  817.  
  818. title();
  819. gotoxy(5,8); printf("Enter A/C number : ");
  820. scanf("%s",acn);
  821. strcpy(acn,strupr(acn));
  822. fp=fopen("ACCOUNT.DAT","r");
  823. cnt = 0;
  824.  
  825. 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_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
  826. {
  827. if (strcmp(acn,ac.ac_no)==0) { srh=ac; cnt++; }// if a/c no matches, srh stores all values of ac
  828. }
  829.  
  830. if (cnt==0)
  831. {
  832. title();
  833. gotoxy(20,12); printf("Given A/C number does not exits!");
  834. getch();
  835. return;
  836. }
  837.  
  838. ac=srh;
  839. title();
  840. gotoxy(3,9); printf("Full name : %s %s",ac.fname,ac.lname);
  841. gotoxy(3,11); printf("Gender <M/F> : %c",ac.sex);
  842. gotoxy(3,13); printf("DOB (mm/dd/yy) : %s",ac.dob);
  843. gotoxy(3,15); printf("Address : ");
  844. for(i=0;i<strlen(ac.address);i++)
  845. if (ac.address[i]=='+') putchar(32);
  846. else putchar(ac.address[i]);
  847.  
  848. gotoxy(3,17); printf("Contact number : %s",ac.contact);
  849.  
  850. gotoxy(43,9); printf("A/C number : %s",ac.ac_no);
  851. gotoxy(43,11); printf("A/C type <S/F> : ");
  852. if (ac.ac_type=='S'||ac.ac_type=='s') { printf("Saving Account"); irate=8.0; }
  853. if (ac.ac_type=='C'||ac.ac_type=='c') { printf("Current Saving"); irate=4.0; }
  854.  
  855.  
  856. gotoxy(43,13); printf("Interest rate : %.2f%c per annum", irate,37);
  857. currency(curr,ac.c_bal);
  858. gotoxy(43,15); printf("Current Balance : %s",curr);
  859. currency(curr1,ac.interest);
  860. gotoxy(43,17); printf("Interset : %s",curr1);
  861. currency(curr2,ac.t_bal);
  862. gotoxy(43,19); printf("Total Balance : %s",curr2);
  863.  
  864. gotoxy(2,21); for(i=0;i<75;i++) printf("%c",196);
  865. gotoxy(5,22); printf("Press ENTER to search again or ANY OTHER KEY to return to main menu");
  866. c=getch();
  867. if(c==13) ac_info();//13 ascii code of enter
  868. else return;
  869.  
  870.  
  871.  
  872.  
  873. break;
  874.  
  875. case 2:
  876.  
  877.  
  878. title();
  879. gotoxy(5,6); printf("Enter first name : ");
  880.  
  881. do
  882. {
  883.  
  884. gotoxy(2,7); for(i=0;i<75;i++) printf("%c",196);
  885. gotoxy(2,20); for(i=0;i<75;i++) printf("%c",196);
  886. gotoxy(15,21); printf("Press ENTER to view detailed information of FIRST record");
  887. gotoxy(18,22); printf(" or press ESCAPE to return to main menu");
  888.  
  889.  
  890.  
  891. gotoxy(25+n,6);
  892. c = getch();
  893. if( isprint(c) )
  894. {
  895. buffer[ pos++ ] = c;
  896. printf("%c", c);
  897. n++;
  898. }
  899. else if( c == 8 && pos )
  900. {
  901. buffer[ pos-- ] = '\0';
  902. printf("%s", "\b \b");
  903. n--;
  904. }
  905.  
  906. cls(3,10,75,11+m);
  907. m=0;
  908.  
  909.  
  910. gotoxy(3,8); printf("A/C no.");
  911. gotoxy(13,8); printf("Full name");
  912. gotoxy(43,8); printf("Contact no.");
  913. gotoxy(60,8); printf("Net Balance");
  914. gotoxy(2,9); for(i=0;i<75;i++) printf("%c",196);
  915.  
  916.  
  917.  
  918. fp=fopen("ACCOUNT.DAT","r");
  919.  
  920. 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_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
  921. {
  922. cnt=0;
  923. for(i=0;i<strlen(buffer);i++)
  924. {
  925. if(buffer[i]>='a'&&buffer[i]<='z') buffer[i]=buffer[i]-32;
  926. if(ac.fname[i]>='a'&&ac.fname[i]<='z') ac.fname[i]=ac.fname[i]-32;
  927. if(buffer[i]!=ac.fname[i]) cnt++;
  928. }
  929.  
  930.  
  931.  
  932. if(cnt==0)
  933. {
  934.  
  935. if(m==0) srh=ac;
  936.  
  937. if(m<=9)
  938. {
  939. gotoxy(3,10+m); printf("%s",ac.ac_no);
  940. gotoxy(13,10+m); printf("%s %s",ac.fname,ac.lname);
  941. gotoxy(43,10+m); printf("%s",ac.contact);
  942. currency(curr,ac.t_bal);
  943. gotoxy(55,10+m); printf("%20s",curr);
  944. m++;
  945. }
  946.  
  947. }
  948.  
  949. }
  950.  
  951.  
  952.  
  953.  
  954.  
  955. fclose(fp);
  956.  
  957.  
  958.  
  959.  
  960.  
  961. }while( c != 13&&c!=27 );
  962.  
  963. if (c==13)
  964. {
  965. ac=srh;
  966. title();
  967. gotoxy(3,9); printf("Full name : %s %s",ac.fname,ac.lname);
  968. gotoxy(3,11); printf("Gender <M/F> : %c",ac.sex);
  969. gotoxy(3,13); printf("DOB (mm/dd/yy) : %s",ac.dob);
  970. gotoxy(3,15); printf("Address : ");
  971. for(i=0;i<strlen(ac.address);i++)
  972. if (ac.address[i]=='+') putchar(32);
  973. else putchar(ac.address[i]);
  974.  
  975. gotoxy(3,17); printf("Contact number : %s",ac.contact);
  976.  
  977. gotoxy(43,9); printf("A/C number : %s",ac.ac_no);
  978. gotoxy(43,11); printf("A/C type <S/F> : ");
  979. if (ac.ac_type=='S'||ac.ac_type=='s') { printf("Saving Account"); irate=8.0; }
  980. if (ac.ac_type=='C'||ac.ac_type=='c') { printf("Current Saving"); irate=4.0; }
  981.  
  982.  
  983. gotoxy(43,13); printf("Interest rate : %.2f%c per annum", irate,37);
  984. currency(curr,ac.c_bal);
  985. gotoxy(43,15); printf("Current Balance : %s",curr);
  986. currency(curr1,ac.interest);
  987. gotoxy(43,17); printf("Interset : %s",curr1);
  988. currency(curr2,ac.t_bal);
  989. gotoxy(43,19); printf("Total Balance : %s",curr2);
  990.  
  991. gotoxy(2,21); for(i=0;i<75;i++) printf("%c",196);
  992. gotoxy(5,22); printf("Press ENTER to search again or ANY OTHER KEY to return to main menu");
  993. c=getch();
  994. if(c==13) ac_info();
  995. else return;
  996.  
  997.  
  998. }
  999.  
  1000. break;
  1001. case 3:
  1002. return;
  1003. break;
  1004. default:
  1005. title();
  1006. gotoxy(10,10); printf("Your input is out of range! Enter a choice between 1 to 8!");
  1007. gotoxy(15,12); printf("Press any key to return to main menu...");
  1008. getch();
  1009. ac_info();
  1010.  
  1011.  
  1012.  
  1013. }
  1014.  
  1015.  
  1016.  
  1017.  
  1018. }
  1019.  
  1020.  
  1021.  
  1022. void transaction()
  1023. {
  1024. char acn[8],mon[10],ch,camt[25],temp[40];
  1025. int c,i,j,l,n,x,pg=1;
  1026. int nr;
  1027. nr=num_of_rec("TRANSACTION.DAT",6);
  1028.  
  1029. struct trans t, *selected;
  1030. selected=(struct trans *)malloc(sizeof(struct trans)*nr);
  1031.  
  1032. struct account ac,sac;
  1033.  
  1034. title();
  1035. gotoxy(8,8); printf("A/C number : "); scanf("%s",acn);
  1036. strcpy(acn,strupr(acn));
  1037. fp=fopen("ACCOUNT.DAT","r");
  1038. c=0;
  1039. 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_date,&ac.ac_type,&ac.c_bal,&ac.interest,&ac.t_bal)!=EOF)
  1040. if(strcmp(acn,ac.ac_no)==0)
  1041. {
  1042. c++;
  1043. sac=ac;
  1044.  
  1045. }
  1046.  
  1047. fclose(fp);
  1048.  
  1049. if (c==0)
  1050. {
  1051. title();
  1052. gotoxy(20,12); printf("Given A/C number does not exits!");
  1053. getch();
  1054. }
  1055. else
  1056. {
  1057.  
  1058.  
  1059.  
  1060. fp=fopen("TRANSACTION.DAT","r");
  1061. i=0;
  1062. while(fscanf(fp,"%s %s %s %s %f %s\n",t.ac_no,t.ac_t,t._date,t._ttime,&t.amt,t.usr)!=EOF)
  1063. if(strcmp(acn,t.ac_no)==0) selected[i++]=t;
  1064. l=i;
  1065. fclose(fp);
  1066.  
  1067. strcpy(selected[l].ac_no,t.ac_no);
  1068. strcpy(selected[l].ac_t,"Interest");
  1069. strcpy(selected[l]._date,date);
  1070. _strtime(ttime);
  1071. strcpy(selected[l]._ttime,ttime);
  1072. selected[l].amt=sac.interest;
  1073. l++;
  1074. strcpy(selected[l].ac_no,t.ac_no);
  1075. strcpy(selected[l].ac_t,"Closing balance");
  1076. strcpy(selected[l]._date,date);
  1077. _strtime(ttime);
  1078. strcpy(selected[l]._ttime,ttime);
  1079. selected[l].amt=sac.c_bal+sac.interest;
  1080. l++;
  1081. n=0; c=0;
  1082. float dr=0,cr=0;
  1083. do
  1084. {
  1085. title();
  1086.  
  1087. gotoxy(2,6);puts("SN");
  1088. gotoxy(6,6);puts(" Details");
  1089. gotoxy(28,6); puts("Date");
  1090. gotoxy(44,6); puts("Time");
  1091. gotoxy(50,6);puts(" Dr. (NRs.)");
  1092. gotoxy(65,6);puts(" Cr. (NRs.)");
  1093. gotoxy(1,7); for(i=1;i<79;i++) printf("%c",196);
  1094. gotoxy(1,21); for(i=1;i<79;i++) printf("%c",196);
  1095. if(n>l) {n=0; pg=1;}
  1096. i=n;
  1097.  
  1098. gotoxy(2,22); printf("Page : %d out of %d",pg,(int)l/10+1);
  1099. if (l>9)
  1100. if (pg!=(int)l/10+1) { gotoxy(25,22); printf("Press SPACE BAR to view next page");}
  1101. else { gotoxy(25,22); printf("Press SPACE BAR to view first page");}
  1102. gotoxy(2,20); printf("A/C holder : %s %s",sac.fname,sac.lname);
  1103. currency(camt,sac.t_bal);
  1104. strcpy(temp,"Bank Balance : ");
  1105. strcat(temp,camt);
  1106. gotoxy(78-strlen(temp),20); printf("%s",temp);
  1107.  
  1108.  
  1109. for(j=0;j<10;j++)
  1110. {
  1111.  
  1112. gotoxy(2,8+j); printf("%d.",i+1);
  1113. for(x=0;x<strlen(selected[i].ac_t);x++) if(selected[i].ac_t[x]=='+') selected[i].ac_t[x]=32;
  1114. gotoxy(6,8+j); puts(selected[i].ac_t);
  1115. if (c==0) date_output(selected[i]._date);
  1116. gotoxy(28,8+j); puts(selected[i]._date);
  1117. selected[i]._ttime[5]='\0';
  1118. gotoxy(44,8+j); printf("%s",selected[i]._ttime);
  1119. if(selected[i].ac_t[0]=='T')
  1120. {
  1121. gotoxy(65,8+j);
  1122. printf("%13.2f",selected[i].amt);
  1123. cr+=selected[i].amt;
  1124. }
  1125. else if (selected[i].ac_t[0]=='C'&&(selected[i].ac_t[5]=='W'||selected[i].ac_t[1]=='l'))
  1126. {
  1127. gotoxy(65,8+j);
  1128. printf("%13.2f",selected[i].amt);
  1129. cr+=selected[i].amt;
  1130. }
  1131. else
  1132. {
  1133. gotoxy(50,8+j);
  1134. printf("%13.2f",selected[i].amt);
  1135. dr+=selected[i].amt;
  1136. }
  1137. i++;
  1138. if(i>=l) break;
  1139.  
  1140.  
  1141. }
  1142.  
  1143.  
  1144. n+=10;
  1145.  
  1146. if (i>=l)
  1147. {
  1148. gotoxy(1,9+j); for(x=1;x<79;x++) printf("%c",196);
  1149. gotoxy(40,10+j); printf("TOTAL");
  1150. gotoxy(50,10+j); printf("%13.2f",dr);
  1151. gotoxy(65,10+j); printf("%13.2f",cr);
  1152. dr=cr=0;
  1153. gotoxy(1,11+j); for(x=1;x<79;x++) printf("%c",196);
  1154. c++;
  1155. }
  1156. ch=getche();
  1157. if (ch==32) pg++;
  1158.  
  1159. } while(ch==32);
  1160.  
  1161.  
  1162.  
  1163.  
  1164.  
  1165.  
  1166.  
  1167.  
  1168.  
  1169.  
  1170.  
  1171. }
  1172.  
  1173.  
  1174.  
  1175.  
  1176.  
  1177. }
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183. //----------------------------------------------------------------------------------------------
  1184.  
  1185.  
  1186.  
  1187. void admin()
  1188. {
  1189. char uname[30], pass[30]={0};
  1190.  
  1191. int c=0,cnt=0;
  1192. do
  1193. {
  1194. c=0;
  1195. system("cls");
  1196. gotoxy(7,5);printf("Only THREE attempts shall be allowed to enter username and password.");
  1197. rectangle(10,8,70,15);
  1198. gotoxy(23,10); printf("Enter User name : "); scanf("%s",uname);
  1199. char pass[30]={0};
  1200. gotoxy(23,12); printf("Password : "); _password(pass);
  1201.  
  1202.  
  1203. strcpy(uname,strupr(uname)); //Changes string uname into uppercase
  1204. strcpy(pass,strupr(pass));
  1205.  
  1206. cnt++;//This variable counts the number of times the password is asked. Note that if cnt==3 then the program terminates after displaying error message
  1207. if (cnt==3)
  1208. {
  1209. title();
  1210. gotoxy(25,8); printf("Invalid User name or Password!\a");
  1211. gotoxy(22,11);printf("Press any key to exit the program...");
  1212. getch();
  1213.  
  1214.  
  1215. exit(0); //exits the program
  1216. }
  1217. if(strcmp(uname,"ADMIN")==0&&strcmp(pass,"IOE")==0) c=1;//if user name and passpord matches, the value of c is changed from 0 to 1. The purpose of changing value of c is seen @line 77 where the password is asked again if c!=0 i.e. if given password is invalid
  1218. else
  1219. {
  1220. title();
  1221. gotoxy(25,10); printf("Invalid User name or Password!\a");
  1222. getch();
  1223.  
  1224. }
  1225.  
  1226. } while(c!=1);
  1227.  
  1228. do
  1229. {
  1230. title();
  1231.  
  1232. int ch,i;
  1233. char ex,key;
  1234. gotoxy(30,8);printf("1. Add User");
  1235. gotoxy(30,10);printf("2. Delete User");
  1236. gotoxy(30,12);printf("3. Edit User name / Password");
  1237. gotoxy(30,14);printf("4. View User Log");
  1238. gotoxy(30,16);printf("5. Exit");
  1239. gotoxy(1,17); for(i=0;i<78;i++) printf("_");
  1240. gotoxy(23,19);printf(" Press a number between the range [1 -5] ");
  1241. key=getche();//Reads a character entered by user andstroes in char variable key
  1242. ch=key-48;//changes char key into integer ch eg. '1'(ascii value 49)--->49-48=1
  1243.  
  1244.  
  1245.  
  1246.  
  1247. switch(ch)
  1248. {
  1249. case 1:
  1250.  
  1251. add_user();
  1252.  
  1253.  
  1254. break;
  1255. case 2:
  1256.  
  1257.  
  1258. del_user();
  1259.  
  1260.  
  1261. break;
  1262. case 3:
  1263.  
  1264. edit_user();
  1265.  
  1266.  
  1267. break;
  1268.  
  1269. case 4:
  1270.  
  1271. view_log();
  1272. break;
  1273.  
  1274. case 5:
  1275. title();
  1276. gotoxy(15,10); printf("Are you sure you want to exit? <Y/N> : ");
  1277. ex=getche();
  1278. if (ex=='Y'||ex=='y') exit(0);
  1279.  
  1280.  
  1281. break;
  1282.  
  1283. default:
  1284. title();
  1285. gotoxy(10,10); printf("Your input is out of range! Enter a choice between 1 to 5!");
  1286. gotoxy(15,12); printf("Press ENTER to return to main menu...");
  1287. getch();
  1288.  
  1289. }
  1290.  
  1291. } while(1);//goes to main menu repeatedly unless user's choice is exit
  1292. return;
  1293. }
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299. void add_user()
  1300. {
  1301.  
  1302.  
  1303. int err1=0,c=0;
  1304. char passwrd1[30]={0};
  1305. char passwrd2[30]={0};
  1306. char nam[30],pass[30];
  1307. do{
  1308. title();
  1309. err1=0;
  1310. gotoxy(25,8);printf("User Name : ");
  1311. scanf("%s",user.name);
  1312. fp=fopen("USER.DAT","r");//opens the datafile USER.DAT to check if the user name already exits or not
  1313.  
  1314.  
  1315. c=0;
  1316. while(fscanf(fp,"%s %s %s\n",user.uid,nam,pass)!=EOF)
  1317. {
  1318. strcpy(nam,strupr(nam));
  1319. strcpy(user.name,strupr(user.name));
  1320. if(strcmp(nam,user.name)==0) c++;//if given username and the username of datafile matches, c is increased by 1
  1321. }
  1322.  
  1323. fclose(fp);
  1324. if(c!=0)//it is neccessary for c to be zero to avoid duplicate user name
  1325. {
  1326. gotoxy(10,10);
  1327. printf("User name already exists! Please enter a new user name.\a");
  1328. getch();
  1329. err1++;//this is an error flag. its signigicance is observed @line 216
  1330. continue;// skips all the commands below and go for next loop of do..while @line 174
  1331. }
  1332.  
  1333.  
  1334.  
  1335.  
  1336. gotoxy(25,10);printf("Password : ");
  1337. _password(passwrd1);
  1338. strcpy(user.password,passwrd1);
  1339. gotoxy(25,12);printf("Confirm Password : ");
  1340. _password(passwrd2);
  1341. if (strcmp(user.password,passwrd2)!=0)//checking if password and confirm password match
  1342. {
  1343. title();
  1344. gotoxy(10,10);
  1345. printf("Password and confirm password does not match!\a");
  1346. getch();
  1347. err1++;
  1348. }
  1349. }while(err1!=0);
  1350.  
  1351. fp=fopen("USER.DAT","r");//data file again opened to read the last user id
  1352.  
  1353. char id[4];
  1354.  
  1355. if (fp==NULL) strcpy(user.uid,"U01");//if USER.DAT does not exists userid is set to first i.e. U01
  1356. else
  1357. {
  1358. while(fscanf(fp,"%s %s %s\n",user.uid,nam,pass)!=EOF);//last user id is read
  1359. increase(user.uid);//userid is incread by 1. eg. U09-->U10. note that increase() is our user defined function
  1360.  
  1361.  
  1362.  
  1363. }
  1364. fclose(fp);
  1365.  
  1366. fp=fopen("USER.DAT","a");//data file open to append (add) record
  1367.  
  1368.  
  1369. fprintf(fp,"%s %s %s\n",user.uid,user.name,user.password); //record written in datafile
  1370. fclose(fp);
  1371.  
  1372. title();
  1373. gotoxy(25,10); printf("Record ADDED successfully!");
  1374. getch();
  1375.  
  1376. }
  1377.  
  1378. void del_user()
  1379. {
  1380. char nam[30], pass[30],ch,id[5],passwrd[30]={0};
  1381. int c=0;
  1382. user_log log;
  1383. title();
  1384.  
  1385. gotoxy(25,8);printf("User Name : ");
  1386. scanf("%s",user.name);
  1387. gotoxy(25,10);printf("Password : ");
  1388. _password(passwrd);
  1389. strcpy(user.password,passwrd);
  1390.  
  1391. fp=fopen("USER.DAT","r");//opening datafile to read in order to check if the given user name and password combination exists
  1392. while(fscanf(fp,"%s %s %s\n",user.uid,nam,pass)!=EOF)
  1393. {
  1394. strcpy(nam,strupr(nam));
  1395. strcpy(pass,strupr(pass));
  1396. strcpy(user.name,strupr(user.name));
  1397. strcpy(user.password,strupr(user.password));
  1398. if(strcmp(user.name,nam)==0&&strcmp(user.password,pass)==0) c++;
  1399. }
  1400.  
  1401. fclose(fp);
  1402. title();
  1403. if (c==0)//note that c must be 1 if given user name and password exists
  1404. {
  1405.  
  1406. gotoxy(10,10); printf("Cannot find the given combination of USER NAME and PASSWORD!\a");
  1407. getch();
  1408. return;
  1409. }
  1410.  
  1411. gotoxy(15,10); printf("Are you sure you want to DELETE this user? <Y/N> : ");
  1412. ch=getche();
  1413. if(ch=='Y'||ch=='y')
  1414. {
  1415. fp=fopen("USER.DAT","r");
  1416. tfp=fopen("temp.dat","a");//creating a temporary datafile where all the contents of USER.DAT is copied except the one entered by user to delete. Note that @line 292 and 293 we have first deleted our old datafile USER.DAT and renamed the duplicate copy temp.dat into USER.DAT. This concept has been used to delete and edit records of data file
  1417. while(fscanf(fp,"%s %s %s\n",user.uid,nam,pass)!=EOF)
  1418. {
  1419. strcpy(nam,strupr(nam));
  1420. strcpy(pass,strupr(pass));
  1421. if(strcmp(user.name,nam)!=0||strcmp(user.password,pass)!=0)
  1422. fprintf(tfp,"%s %s %s\n",user.uid,nam,pass);
  1423. else
  1424. strcpy(id,user.uid);
  1425. }
  1426. fclose(fp);
  1427. fclose(tfp);
  1428. system("del USER.DAT");
  1429. system("ren temp.dat USER.DAT");
  1430.  
  1431. fp=fopen("LOG.DAT","r");
  1432. tfp=fopen("temp.dat","w");//creating a temporary datafile where all the contents of USER.DAT is copied except the one entered by user to delete. Note that @line 292 and 293 we have first deleted our old datafile USER.DAT and renamed the duplicate copy temp.dat into USER.DAT. This concept has been used to delete and edit records of data file
  1433. while(fscanf(fp,"%s %s %s %s",log.id,log.date,log.stime,log.etime)!=EOF)
  1434. {
  1435. strupr(log.id);
  1436. strupr(id);
  1437. if(strcmp(log.id,id)!=0)
  1438. fprintf(tfp,"%s %s %s %s\n",log.id,log.date,log.stime,log.etime);
  1439. }
  1440. fclose(fp);
  1441. fclose(tfp);
  1442. system("del LOG.DAT");
  1443. system("ren temp.dat LOG.DAT");
  1444.  
  1445.  
  1446. title();
  1447. gotoxy(25,10); printf("Record DELETED successfully!");
  1448. getch();
  1449. }
  1450.  
  1451.  
  1452.  
  1453.  
  1454. }
  1455.  
  1456. void edit_user()
  1457. {
  1458. char nam[30], pass[30],ch, n_nam[30], n_pass[30]={0},passwrd[30]={0},n_pass1[30]={0};
  1459. int c=0,err=0;
  1460. title();
  1461.  
  1462. gotoxy(25,8);printf("User Name : ");
  1463. scanf("%s",user.name);
  1464. gotoxy(25,10);printf("Password : ");
  1465. _password(passwrd);
  1466. strcpy(user.password,passwrd);
  1467.  
  1468. fp=fopen("USER.DAT","r");
  1469. while(fscanf(fp,"%s %s %s\n",user.uid,nam,pass)!=EOF)
  1470. {
  1471. strcpy(nam,strupr(nam));
  1472. strcpy(pass,strupr(pass));
  1473. strcpy(user.name,strupr(user.name));
  1474. strcpy(user.password,strupr(user.password));
  1475. if(strcmp(user.name,nam)==0&&strcmp(user.password,pass)==0) c++;
  1476. }
  1477.  
  1478. fclose(fp);
  1479. title();
  1480. if (c==0)
  1481. {
  1482.  
  1483. gotoxy(10,10); printf("Cannot find the given combination of USER NAME and PASSWORD!\a");
  1484. getch();
  1485. }
  1486. else
  1487. {
  1488. gotoxy(8,10); printf("Are you sure you want to CHANGE user name and/or password? <Y/N> : ");
  1489. ch=getche();
  1490. if(ch=='Y'||ch=='y')
  1491. {
  1492. do
  1493. {
  1494. title();
  1495. err=0;
  1496. gotoxy(25,8);
  1497. printf("NEW User Name : ");
  1498. scanf("%s",n_nam);
  1499. gotoxy(25,10);
  1500. printf("NEW Password : ");
  1501. _password(n_pass);
  1502. gotoxy(25,12);
  1503. printf("Confirm NEW Password : ");
  1504. _password(n_pass1);
  1505.  
  1506. if (strcmp(n_pass,n_pass1)!=0)
  1507. {
  1508. title();
  1509. gotoxy(10,10);
  1510. printf("Password and confirm password does not match!\a");
  1511. getch();
  1512. err++;
  1513. }
  1514.  
  1515. } while(err!=0);
  1516.  
  1517. fp=fopen("USER.DAT","r");
  1518. tfp=fopen("temp.dat","a");
  1519. while(fscanf(fp,"%s %s %s\n",user.uid,nam,pass)!=EOF)
  1520. {
  1521. strcpy(nam,strupr(nam));
  1522. strcpy(pass,strupr(pass));
  1523. if(strcmp(user.name,nam)!=0||strcmp(user.password,pass)!=0)
  1524. fprintf(tfp,"%s %s %s\n",user.uid,nam,pass);
  1525. else
  1526. fprintf(tfp,"%s %s %s\n",user.uid,n_nam,n_pass);
  1527. }
  1528. fclose(fp);
  1529. fclose(tfp);
  1530. system("del USER.DAT");
  1531. system("ren temp.dat USER.DAT");
  1532.  
  1533. title();
  1534. gotoxy(25,10); printf("Record has been EDITED successfully!");
  1535. getch();
  1536. }
  1537.  
  1538.  
  1539. }
  1540.  
  1541. }
  1542.  
  1543.  
  1544.  
  1545. void view_log()
  1546. {
  1547. int nr;
  1548. nr=num_of_rec("LOG.DAT",4);
  1549. user_log *log,*selected,*temp;
  1550.  
  1551. log=(user_log *)malloc(sizeof(user_log)*nr);
  1552. selected=(user_log *)malloc(sizeof(user_log)*nr);
  1553. temp=(user_log *)malloc(sizeof(user_log)*nr);
  1554.  
  1555. int i=0,l,j,c=0,n=0,l1,cnt=0;
  1556. char uid[4],nam[30],pass[30],key,ch;
  1557.  
  1558. do {
  1559. i=0;c=0;n=0;cnt=0;
  1560. tfp=fopen("LOG.DAT","r");//note that 2 datafiles LOG.DAT and USER.DAT are opened to store necessary informations in structure variable log[] all informations are availeble on LOG.DAT but to access user name we have to open USER.DAT also. After storing necessary information in structure variable log, there is no need to further open these datafiles
  1561.  
  1562. while(fscanf(tfp,"%s %s %s %s\n",log[i].id,log[i].date,log[i].stime,log[i].etime)!=EOF)
  1563. {
  1564.  
  1565. fp=fopen("USER.DAT","r");
  1566. while(fscanf(fp,"%s %s %s\n",uid,nam,pass)!=EOF)
  1567.  
  1568. if(strcmp(log[i].id,uid)==0) strcpy(log[i].name,nam);
  1569.  
  1570.  
  1571. i++;
  1572. fclose(fp);
  1573. }
  1574. l=i;//thus l is num of rec.s
  1575.  
  1576. fclose(tfp);
  1577.  
  1578.  
  1579.  
  1580. title();
  1581. gotoxy(30,8);printf("1. View by USER NAME");
  1582. gotoxy(30,10);printf("2. View by DATE");
  1583. gotoxy(30,12);printf("3. View ALL User history");
  1584. gotoxy(30,14);printf("4. Return to main menu");
  1585. gotoxy(1,15); for(i=0;i<78;i++) printf("_");
  1586. gotoxy(23,17);printf(" Press a number between the range [1 -4] ");
  1587. key=getche()-48;
  1588. j=0;
  1589. title();
  1590. switch(key)
  1591. {
  1592. case 1:
  1593.  
  1594. gotoxy(30,10); printf("Enter user name : "); scanf(" %s",nam);
  1595. strcpy(nam,strupr(nam));
  1596. for(i=0;i<l;i++)
  1597. { strcpy(log[i].name,strupr(log[i].name));
  1598. if(strcmp(log[i].name,nam)==0) selected[j++]=log[i];//selected[] is a structure array variable that stores selected (that are to be displayed) data from log[]
  1599. }
  1600. l1=j;//l1 is number of selected (that are to be displayed) records
  1601. break;
  1602. case 2:
  1603.  
  1604. do
  1605. {
  1606. gotoxy(30,10); printf("Enter Date (dd/mm/yyyy) : "); scanf(" %s",nam);
  1607.  
  1608. if(date_check(nam)==0) { cls(30,10,70,10); printf("\a");}
  1609. }while(date_check(nam)==0);
  1610.  
  1611. date_input(nam);
  1612. for(i=0,j=0;i<l;i++)
  1613. if(strcmp(log[i].date,nam)==0) selected[j++]=log[i];
  1614. l1=j;
  1615. break;
  1616. case 3:
  1617.  
  1618. for(i=0;i<l;i++)
  1619. selected[j++]=log[i];
  1620. l1=j;
  1621. break;
  1622. case 4:
  1623.  
  1624. return;
  1625.  
  1626. break;
  1627. default:
  1628.  
  1629. title();
  1630. gotoxy(10,10); printf("Your input is out of range! Enter a choice between 1 to 4!");
  1631. gotoxy(15,12); printf("Press ENTER to return to main menu...");
  1632. getch();
  1633. c=1;
  1634. }
  1635.  
  1636.  
  1637. if(l1==0)//l1==0 means no supporing data available
  1638. {
  1639. title();
  1640. gotoxy(27,12); printf("No related record(s) found!\a");
  1641. getch();
  1642. view_log();
  1643. }
  1644.  
  1645.  
  1646.  
  1647. if(c==0)
  1648. {
  1649.  
  1650. for(i=0,j=l1-1;i<l1;i++,j--)
  1651. temp[i]=selected[j];
  1652. for(i=0;i<l1;i++)
  1653. selected[i]=temp[i];
  1654.  
  1655. do
  1656. {
  1657. title();
  1658. if (l1<12)
  1659. {
  1660. gotoxy(8,21); printf("Press S to toggle Sorting between ascending or descending order.");
  1661. }
  1662.  
  1663. else
  1664. {
  1665. gotoxy(15,21); printf("Press SPACE BAR to view more data");
  1666. }
  1667. gotoxy(5,8); printf("SN\t User Name\tDate\t\tStart time\tEnd Time");
  1668. gotoxy(4,9); for(i=0;i<70;i++) printf("%c",196);
  1669. if(cnt!=0)
  1670. {
  1671. for(i=l1-1;i>=0;i--)
  1672. temp[l1-i-1]=selected[i];
  1673. for(i=0;i<l1;i++)
  1674. selected[i]=temp[i];
  1675. }
  1676.  
  1677.  
  1678. if(n>l1) n=0;
  1679.  
  1680. for(i=n,j=0;i<l1;i++,j++)
  1681. {
  1682. gotoxy(5,10+j);printf("%d.",i+1);
  1683. selected[i].stime[5]='\0';
  1684. selected[i].etime[5]='\0';
  1685. if (strlen(selected[i].date)<10)
  1686. {
  1687. date_output(selected[i].date);
  1688.  
  1689. }
  1690. gotoxy(9,10+j); printf("%s\t\t%s\t%s\t\t%s",selected[i].name,selected[i].date,selected[i].stime,selected[i].etime);
  1691. if(i>=n+9) { n=n+10; break;}
  1692. }
  1693. ch=getche();
  1694. if(ch=='S'||ch=='s')cnt=1;
  1695. if(ch==32&&i==l1) n=0;
  1696.  
  1697. } while(ch=='S'||ch=='s'||ch==32);
  1698.  
  1699.  
  1700. }
  1701. else c=0;
  1702.  
  1703. } while(1);
  1704.  
  1705. }
  1706.  
  1707.  
  1708.  
  1709. //------------------------------------------------------------------------------------------------
  1710.  
  1711. void welcome()
  1712. {
  1713. int i;
  1714. system("cls");
  1715. rectangle(0,0,80,23);
  1716. gotoxy(27,4); printf("BANK MANAGEMENT SYSTEM");
  1717. gotoxy(25,5); for(i=0;i<27;i++) printf("%c",196);
  1718. gotoxy(25,8); printf("Designed and Programmed by:");
  1719. gotoxy(25,9);for(i=0;i<27;i++) printf("%c",196);
  1720. gotoxy(33,11); printf("Ravi Agrawal");
  1721. gotoxy(33,13); printf("Sagar Sharma");
  1722. gotoxy(33,15); printf("Sawal Maskey");
  1723. gotoxy(24,20);
  1724.  
  1725. printf("Press Any key to continue...");
  1726.  
  1727.  
  1728. getch();
  1729.  
  1730. }
  1731.  
  1732.  
  1733. void date_input(char date[]) // dd/mm/yyyy ----> mm/dd/yy
  1734. {
  1735. char temp[15];
  1736.  
  1737. temp[3]=date[0];
  1738. temp[4]=date[1];
  1739. temp[0]=date[3];
  1740. temp[1]=date[4];
  1741. temp[6]=date[8];
  1742. temp[7]=date[9];
  1743. temp[8]='\0';
  1744. temp[2]=temp[5]='/';
  1745.  
  1746. strcpy(date,temp);
  1747. }
  1748.  
  1749.  
  1750. void date_output(char date[]) //mm/dd/yy ---> dd MMM, yyyy
  1751. {
  1752. struct
  1753. {
  1754. int dd;
  1755. char mm[4];
  1756. int yyyy;
  1757. }_date;
  1758.  
  1759. char temp[15];
  1760. int mm,c,i;
  1761. _date.dd=(date[3]-48)*10+(date[4]-48);
  1762.  
  1763. mm=(date[0]-48)*10+(date[1]-48);
  1764. _date.yyyy=2000+(date[6]-48)*10+(date[7]-48);
  1765. switch(mm)
  1766. {
  1767. case 1: strcpy(_date.mm,"Jan"); break;
  1768. case 2: strcpy(_date.mm,"Feb"); break;
  1769. case 3: strcpy(_date.mm,"Mar"); break;
  1770. case 4: strcpy(_date.mm,"Apr"); break;
  1771. case 5: strcpy(_date.mm,"May"); break;
  1772. case 6: strcpy(_date.mm,"Jun"); break;
  1773. case 7: strcpy(_date.mm,"Jul"); break;
  1774. case 8: strcpy(_date.mm,"Aug"); break;
  1775. case 9: strcpy(_date.mm,"Sep"); break;
  1776. case 10: strcpy(_date.mm,"Oct"); break;
  1777. case 11: strcpy(_date.mm,"Nov"); break;
  1778. case 12: strcpy(_date.mm,"Dec"); break;
  1779. }
  1780.  
  1781. temp[0]=(int)(_date.dd/10)+48;
  1782. temp[1]=(int)(_date.dd%10)+48;
  1783. temp[2]=32;
  1784. temp[3]='\0';
  1785. strcat(temp,_date.mm);
  1786. temp[6]=',';
  1787. c=0;
  1788. temp[7]=32;
  1789. for(i=3;i>=0;i--)
  1790. {
  1791. temp[8+c]=(int)(_date.yyyy/pow(10,i))+48;
  1792. c++;
  1793. _date.yyyy%=(int)pow(10,i);
  1794. }
  1795. temp[12]='\0';
  1796. strcpy(date,temp);
  1797. }
  1798.  
  1799.  
  1800. int date_check(char _date[]) //_date[] is in format dd/mm/yyyy
  1801. {
  1802. int err=0,mm,dd,yyyy;
  1803. if(strlen(_date)!=10) err++;
  1804. if(_date[2]!='/'||_date[5]!='/') err++;
  1805. mm=(_date[3]-48)*10+(_date[4]-48);
  1806. if (mm>12) err++;
  1807. dd=(_date[0]-48)*10+(_date[1]-48);
  1808.  
  1809. yyyy=(_date[6]-48)*1000+(_date[7]-48)*100+(_date[8]-48)*10+(_date[9]-48);
  1810.  
  1811. switch(mm)
  1812. {
  1813. case 1: if (dd>31) err++; break;
  1814. case 2:
  1815. if (dd>28) err++;
  1816. if (yyyy%4==0&&dd==29) err--;
  1817. break;
  1818. case 3: if (dd>31) err++; break;
  1819. case 4: if (dd>30) err++; break;
  1820. case 5: if (dd>31) err++; break;
  1821. case 6: if (dd>30) err++; break;
  1822. case 7: if (dd>31) err++; break;
  1823. case 8: if (dd>31) err++; break;
  1824. case 9: if (dd>30) err++; break;
  1825. case 10: if (dd>31) err++; break;
  1826. case 11: if (dd>30) err++; break;
  1827. case 12: if (dd>31) err++; break;
  1828.  
  1829. }
  1830.  
  1831. if (err==0)
  1832. return 1;
  1833. else
  1834. return 0;
  1835.  
  1836. }
  1837.  
  1838.  
  1839.  
  1840. void num2word(double n,char word[])
  1841. {
  1842. long int num;
  1843. int a[6],i;
  1844.  
  1845. num=(int)n;
  1846.  
  1847. a[5]=num%1000;
  1848. num=num/1000;
  1849.  
  1850. for(i=4;i>=0;i--)
  1851. {
  1852. a[i]=num%100;
  1853. num=num/100;
  1854. }
  1855.  
  1856. //OK
  1857.  
  1858.  
  1859. int m,h,tt,t,o;
  1860. m=a[5];
  1861. h=m/100;
  1862. tt=m%100;
  1863. t=tt/10;
  1864. o=tt%10;
  1865.  
  1866. char one[10],ten[10],hh[20]={0};
  1867.  
  1868. if(tt<20&&h!=0)
  1869. {
  1870. _one(h,one);
  1871. strcpy(hh,one);
  1872. strcat(hh,"Hundred ");
  1873. _one(tt,one);
  1874. strcat(hh,one);
  1875. }
  1876.  
  1877. else if(tt<20&&h==0)
  1878. {
  1879. _one(tt,one);
  1880. strcpy(hh,one);
  1881. }
  1882. else if(tt>20&&h!=0)
  1883. {
  1884. _one(h,one);
  1885. strcpy(hh,one);
  1886. strcat(hh,"Hundred ");
  1887. _ten(t,ten);
  1888. strcat(hh,ten);
  1889. _one(o,one);
  1890. strcat(hh,one);
  1891. }
  1892. else
  1893. {
  1894. _ten(t,ten);
  1895. strcpy(hh,ten);
  1896. _one(o,one);
  1897. strcat(hh,one);
  1898. }
  1899.  
  1900.  
  1901. //ok
  1902.  
  1903. char aa[5][30];
  1904. for(i=4;i>=0;i--)
  1905. {
  1906. if (a[i]<20)
  1907. {
  1908. _one(a[i],one);
  1909. strcpy(aa[i],one);
  1910. }
  1911. else
  1912. {
  1913. _ten(a[i]/10,ten);
  1914. strcpy(aa[i],ten);
  1915. _one(a[i]%10,one);
  1916. strcat(aa[i],one);
  1917. }
  1918. }
  1919.  
  1920. char x[10]={0},w[50]={0};
  1921. int l;
  1922. for(i=0;i<5;i++)
  1923. {
  1924. l=strlen(aa[i]);
  1925. if(l!=0)
  1926. {
  1927. switch(i)
  1928. {
  1929. case 0: strcpy(x,"Kharab "); break;
  1930. case 1: strcpy(x,"Arab "); break;
  1931. case 2: strcpy(x,"Crore "); break;
  1932. case 3: strcpy(x,"Lakh "); break;
  1933. case 4: strcpy(x,"Thousand "); break;
  1934. }
  1935. strcat(w,aa[i]);
  1936. strcat(w,x);
  1937. }
  1938. }
  1939.  
  1940. strcpy(word,w);
  1941. strcat(word,hh);
  1942. word[strlen(word)-1]='\0';
  1943.  
  1944. }
  1945.  
  1946. void _ten(int n,char ten[])
  1947. {
  1948. switch(n)
  1949. {
  1950. case 2: strcpy(ten,"Twenty "); break;
  1951. case 3: strcpy(ten,"Thirty "); break;
  1952. case 4: strcpy(ten,"Forty "); break;
  1953. case 5: strcpy(ten,"Fifty "); break;
  1954. case 6: strcpy(ten,"Sixty "); break;
  1955. case 7: strcpy(ten,"Seventy "); break;
  1956. case 8: strcpy(ten,"Eighty "); break;
  1957. case 9: strcpy(ten,"Ninety "); break;
  1958. default:
  1959. strcpy(ten,"");
  1960. }
  1961. }
  1962.  
  1963. void _one(int n, char one[])
  1964. {
  1965. switch(n)
  1966. {
  1967. case 1: strcpy(one,"One "); break;
  1968. case 2: strcpy(one,"Two "); break;
  1969. case 3: strcpy(one,"Three "); break;
  1970. case 4: strcpy(one,"Four "); break;
  1971. case 5: strcpy(one,"Five "); break;
  1972. case 6: strcpy(one,"Six "); break;
  1973. case 7: strcpy(one,"Seven "); break;
  1974. case 8: strcpy(one,"Eight "); break;
  1975. case 9: strcpy(one,"Nine "); break;
  1976. case 10: strcpy(one,"Ten "); break;
  1977. case 11: strcpy(one,"Eleven "); break;
  1978. case 12: strcpy(one,"Tweleve "); break;
  1979. case 13: strcpy(one,"Thirteen "); break;
  1980. case 14: strcpy(one,"Fourteen "); break;
  1981. case 15: strcpy(one,"Fifteen "); break;
  1982. case 16: strcpy(one,"Sixteen "); break;
  1983. case 17: strcpy(one,"Seventeen "); break;
  1984. case 18: strcpy(one,"Eighteen "); break;
  1985. case 19: strcpy(one,"Nineteen "); break;
  1986. default:
  1987. strcpy(one,"");
  1988.  
  1989.  
  1990.  
  1991.  
  1992. }
  1993.  
  1994. }
  1995.  
  1996.  
  1997. void currency(char cur[], float n)
  1998. {
  1999.  
  2000. int num,i,x,c;
  2001. char temp[30];
  2002. num=(int)n;
  2003. int a[6];
  2004. a[5]=num%1000;
  2005. num=num/1000;
  2006.  
  2007. for(i=4;i>=0;i--)
  2008. {
  2009. a[i]=num%100;
  2010. num=num/100;
  2011. }
  2012.  
  2013.  
  2014.  
  2015. for(i=0;i<6;i++)
  2016. if (a[i]!=0) break;
  2017.  
  2018. x=i;
  2019. c=0;
  2020. for(i=x;i<6;i++)
  2021. {
  2022. if(i==5)
  2023. {
  2024. if (a[i]>=100||i!=x) cur[c++]=(a[i]/100)+48;
  2025. if (a[i]%100>=10||i!=x) cur[c++]=(a[i]%100)/10+48;
  2026. if (a[i]%100<10&&i==x) cur[c++]=48;
  2027. cur[c++]=(a[i]%100)%10+48;
  2028. }
  2029. else
  2030. {
  2031. if (a[i]>=10||i!=x) cur[c++]=(a[i]/10)+48;
  2032. cur[c++]=(a[i]%10)+48;
  2033. cur[c++]=',';
  2034. }
  2035.  
  2036. }
  2037.  
  2038. cur[c++]='.';
  2039. num=(n-(int)n)*100;
  2040. cur[c++]=num/10+48;
  2041. cur[c++]=num%10+48;
  2042. cur[c]='\0';
  2043. if (n==0) strcpy(cur,"0.00");
  2044. strcpy(temp,"Rs. ");
  2045. strcat(temp,cur);
  2046. strcpy(cur,temp);
  2047. }
  2048.  
  2049.  
  2050.  
  2051. void cls(int x1,int y1,int x2, int y2)
  2052. {
  2053. int i,j;
  2054. for(i=y1;i<=y2;i++)
  2055. for(j=x1;j<=x2;j++)
  2056. {
  2057. gotoxy(j,i); printf("%c",32);
  2058. }
  2059.  
  2060. }
  2061.  
  2062.  
  2063. void increase(char i_id[])
  2064. {
  2065. int l;
  2066. l=strlen(i_id)-1;
  2067. do
  2068. {
  2069. if(i_id[l]!='9') i_id[l]+=1;
  2070. else i_id[l]='0';
  2071. l--;
  2072.  
  2073. }while(i_id[l+1]=='0');
  2074.  
  2075.  
  2076. }
  2077.  
  2078. int num_of_rec(char file[],int n)
  2079. {
  2080. FILE *fptr;
  2081. char dat[200];
  2082. long int c=0;
  2083. fptr=fopen(file,"r");
  2084. while(fscanf(fptr,"%s",dat)!=EOF) c++;
  2085. fclose(fptr);
  2086. return c/n;
  2087.  
  2088. }
  2089.  
  2090.  
  2091. void _password(char buffer[])
  2092. {
  2093.  
  2094.  
  2095. char c;
  2096. int pos = 0;
  2097. do
  2098. {
  2099. c = getch();
  2100. if( isprint(c) )
  2101. {
  2102. buffer[ pos++ ] = c;
  2103. printf("%c", '*');
  2104. }
  2105. else if( c == 8 && pos )
  2106. {
  2107. buffer[ pos-- ] = '\0';
  2108. printf("%s", "\b \b");
  2109. }
  2110. }while( c != 13 );
  2111.  
  2112.  
  2113.  
  2114. }
  2115.  
  2116.  
  2117.  
  2118. void rectangle(int x,int y,int l,int b)
  2119. {
  2120. int i,m;
  2121. gotoxy(x,y); printf("%c",201);
  2122. for(i=x+1;i<l-1;i++)
  2123. {
  2124. gotoxy(i,y);
  2125. printf("%c",205);
  2126. }
  2127. gotoxy(i,y); printf("%c",187);
  2128.  
  2129. for (m=y+1;m<b;m++)
  2130. {
  2131. gotoxy(x,m);
  2132. for(i=x;i<l;i++)
  2133. {
  2134. if(i==x||i==l-1)
  2135. {
  2136. gotoxy(i,m); printf("%c",186);
  2137. }
  2138.  
  2139. }
  2140.  
  2141. }
  2142.  
  2143. gotoxy(x,m); printf("%c",200);
  2144. for(i=x+1;i<l-1;i++)
  2145. {
  2146. gotoxy(i,m);
  2147. printf("%c",205);
  2148. }
  2149. gotoxy(i,m); printf("%c",188);
  2150. }
  2151.  
  2152.  
  2153. void title()
  2154. {
  2155. int i;
  2156.  
  2157. system("cls");
  2158.  
  2159. rectangle(0,0,80,23);
  2160. gotoxy(25,1);
  2161. printf("Banking Management System");
  2162. gotoxy(5,3);
  2163. if (strcmp(user.name,"Admin")==0) gbl_flag=1;
  2164. if (gbl_flag) printf("Current User : Admin");
  2165. else printf("Current User : %s",user.name);
  2166. printf("\t\t\t\tDate : ");
  2167. _strdate(date);
  2168. date_output(date);
  2169. printf("%s",date);
  2170. _strdate(date);
  2171. gotoxy(1,5);
  2172. for(i=0;i<78;i++) printf("%c",196);
  2173.  
  2174. }
  2175.  
  2176.  
  2177. COORD coord = {0, 0};
  2178.  
  2179. void gotoxy (int x, int y)
  2180. {
  2181. coord.X = x;
  2182. coord.Y = y; // X and Y coordinates
  2183. SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
  2184. }

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.