/*BANK PROJECT IN C */
# include <stdio.h>
# include <conio.h>
# define RECS 100
struct bank
{
int acc;
char aname[15];
float bal;
};
/* gloabal var */
struct bank b;
FILE *f;
char ch;
char chh;
char cho;
int acc;
getrec()
{
int acc;
printf("\nEnter A/C no :");
scanf("%d",&acc);
if(checkrec(acc)==-1)
{
printf("\nA/c No %5d Alredy Exist..",b.acc);
return -1;
}
b.acc=acc;
printf("\nEnter A/C Holder name :");
scanf("%s",&b.aname);
printf("\nEnter Open Balance :");
scanf("%f",&b.bal);
}
dis()
{
printf("\n%5d%20s%15.2f",b.acc,b.aname,b.bal);
}
addrec()
{
if(getrec()==-1)
{
fclose(f);
return -1;
}
printf("\nNew A/c Created....");
printf("\n%d.....",b.acc);
f=fopen("c:\\bank.dat","a");
fwrite((char*)&b,sizeof(struct bank),1,f);
fclose(f);
}
disrecs()
{
f=fopen("c:\\bank.dat","r");
printf("\nAll A/c Records....");
fread((char*)&b,sizeof(struct bank),1,f);
while(!feof(f))
{
dis();
fread((char*)&b,sizeof(struct bank),1,f);
}
fclose(f);
}
int searchrec(int ano)
{
struct bank bt;
f=fopen("c:\\bank.dat","r");
fread((char*)&bt,sizeof(struct bank),1,f);
while(!feof(f))
{
if(ano==bt.acc)
{
printf("\nNew A/c No : %d found",ano);
b=bt;
dis();
break;
}
fread((char*)&bt,sizeof(struct bank),1,f);
}
if(feof(f))
{
printf("\n A/C not exist...");
return -1;
}
fclose(f);
return 1;
}
updaterec(int ano)
{
int i,fs,recs,sa,chh,sz;
struct bank bt[RECS];
f=fopen("c:\\bank.dat","r");
/* finding records in file..*/
fseek(f,0,SEEK_END);
fs=ftell(f);
recs=fs/sizeof(struct bank);
sz=recs;
/* reding all recs */
fseek(f,0,SEEK_SET);
fread((char*)&bt,sizeof(struct bank),recs,f);
/*
for(i=0;i<recs;i++)
printf("\n%d",st[i].sno);
*/
printf("\nFile size : %d \nRecord Size : %d\nRecords : %d",fs,recs);
sz--;
while(sz>=0)
{
if(ano==bt[sz].acc)
{
printf("\nA/c No : %d found to update..",ano);
/* printf("\n1....Account no");
printf("\n2....A/C holder name");*/
printf("\n3....Balance Rs");
printf("\n0....E.X.I.T");
printf("\nChoice:");
scanf("%d",&chh);
switch(chh)
{
/* case 1:
printf("\nEnter New Sno:");
scanf("%d",&st[sz].sno);
break;
case 2:
printf("\nEnter New Stu name:");
scanf("%s",&st[sz].sname);
break;*/
case 3:
printf("\nEnter New BALANCE:");
scanf("%f",&bt[sz].bal);
break;
case 0:
printf("Return to main menu..");
return 0;
default:
printf("Return to main menu..");
return 0;
}
break;
}
sz--;
}
fclose(f);
/* remove the file */
remove("c:\\bank.dat");
f=fopen("c:\\bank.dat","w");
fwrite((char*)&bt,sizeof(struct bank),recs,f);
printf("\nUpdated...");
fclose(f);
printf("\nUpdated A/C Details...");
}
deleterec(int ano)
{
struct bank bt;
FILE*f1; /* for writing */
f=fopen("c:\\bank.dat","r");
f1=fopen("c:\\temp.dat","w");
fread((char*)&bt,sizeof(struct bank),1,f);
while(!feof(f))
{
if(ano!=bt.acc)
{
fwrite((char*)&bt,sizeof(struct bank),1,f1);
}
fread((char*)&bt,sizeof(struct bank),1,f);
}
fcloseall();
remove("c:\\bank.dat");
rename("c:\\temp.dat","c:\\bank.dat");
printf("\n Deleted...");
}
updatebal(int acc,char type)
{
int i,fs,recs,sa,chh,sz;
float amt;
struct bank bt[RECS];
f=fopen("c:\\bank.dat","r");
/* finding records in file..*/
fseek(f,0,SEEK_END);
fs=ftell(f);
recs=fs/sizeof(struct bank);
sz=recs;
/* reding all recs */
fseek(f,0,SEEK_SET);
fread((char*)&bt,sizeof(struct bank),recs,f);
sz--;
while(sz>=0)
{
rpt:
printf("\nA/c No : %d ",bt[sz].acc);
printf("\nA/c Name : %s ",bt[sz].aname);
printf("\nA/c Old Bal Rs/- : %.2f ",bt[sz].bal);
if(acc==bt[sz].acc)
{
if(type=='c')
{
printf("\n%Cr Balance Rs:");
scanf("%f",&amt);
bt[sz].bal+=amt;
}
else
{
printf("\nDebit Balance Rs:");
scanf("%f",&amt);
bt[sz].bal-=amt;
}
}
printf("\nA/c New Bal Rs/- : %.2f ",bt[sz].bal);
printf("\nyes/yo : ");
fflush(stdin);
cho=getchar();
if(cho=='y')
break;
else
{
if(type=='c')
bt[sz].bal-=amt;
else
bt[sz].bal+=amt;
goto rpt;
}
sz--;
}
fclose(f);
puts("\nProcessing.....wait");
delay(300);
/* remove the file */
remove("c:\\bank.dat");
f=fopen("c:\\bank.dat","w");
fwrite((char*)&bt,sizeof(struct bank),recs,f);
delay(300);
printf("\nUpdating Balance...wait");
delay(300);
printf("\nUpdating Ledger...");
fclose(f);
}
int transaction(int acc)
{
clrscr();
/* searching a/c */
if(searchrec(acc)==-1)
{
perror("\nA/c not Exist Contact Manager:");
return 0;
}
menu1();
switch(chh)
{
case '1':
updatebal(acc,'c');
break;
case '2':
updatebal(acc,'d');
break;
case '0':
break;
}
}
menu()
{
clrscr();
printf("\n\t\t\t RISE_BANK_MENU ");
printf("\n\t\t\t ");
printf("\n\t\t\t 1...Adding a new A/C ");
printf("\n\t\t\t 2...Display All A/C s ");
printf("\n\t\t\t 3...Search Account ");
printf("\n\t\t\t 4...Update Account ");
printf("\n\t\t\t 5...Delete Account ");
printf("\n\t\t\t 6...Transaction Menu ");
printf("\n\t\t\t 0...E.X.I.T ");
printf("\n\t\t\t ");
printf("\n\t\t\t \n\n");
printf("\n\t\t\t Choice:");
scanf("%c",&ch);
}
menu1()
{
clrscr();
printf("\n\t\t\t TRANS_BANK_MENU ");
printf("\n\t\t\t ");
printf("\n\t\t\t 1...C/r Bal Rs ");
printf("\n\t\t\t 2...D/b Bal Rs ");
printf("\n\t\t\t 0...E.X.I.T ");
printf("\n\t\t\t ");
printf("\n\t\t\t \n\n");
printf("\n\t\t\t Choice:");
fflush(stdin);
scanf("%c",&chh);
}
main()
{
int ano;
clrscr();
do
{
menu();
switch(ch)
{
case '1':
addrec();
break;
case '2':
disrecs();
break;
case '0':
exit(0);
case '3':
printf("\nEnter A/cno To Search?");
scanf("%d",&ano);
searchrec(ano);
break;
case '4':
printf("\nEnter A/cno To Update?");
scanf("%d",&ano);
updaterec(ano);
break;
case '5':
printf("\nEnter A/C no To Delete?");
scanf("%d",&ano);
deleterec(ano);
break;
case '6':
printf("\nEnter a/c no ?");
scanf("%d",&acc);
transaction(acc);
break;
default:
perror("\nEnter choice :1/2/0 Only..");
}
getch();
}while(ch!='0');
}
int checkrec(int ano)
{
struct bank bt;
f=fopen("c:\\bank.dat","r");
fread((char*)&bt,1,sizeof(struct bank),f);
while(!feof(f))
{
if(ano==bt.acc)
{
fclose(f);
return -1;
}
fread((char*)&bt,1,sizeof(struct bank),f);
}
fclose(f);
return 1;
}
# include <stdio.h>
# include <conio.h>
# define RECS 100
struct bank
{
int acc;
char aname[15];
float bal;
};
/* gloabal var */
struct bank b;
FILE *f;
char ch;
char chh;
char cho;
int acc;
getrec()
{
int acc;
printf("\nEnter A/C no :");
scanf("%d",&acc);
if(checkrec(acc)==-1)
{
printf("\nA/c No %5d Alredy Exist..",b.acc);
return -1;
}
b.acc=acc;
printf("\nEnter A/C Holder name :");
scanf("%s",&b.aname);
printf("\nEnter Open Balance :");
scanf("%f",&b.bal);
}
dis()
{
printf("\n%5d%20s%15.2f",b.acc,b.aname,b.bal);
}
addrec()
{
if(getrec()==-1)
{
fclose(f);
return -1;
}
printf("\nNew A/c Created....");
printf("\n%d.....",b.acc);
f=fopen("c:\\bank.dat","a");
fwrite((char*)&b,sizeof(struct bank),1,f);
fclose(f);
}
disrecs()
{
f=fopen("c:\\bank.dat","r");
printf("\nAll A/c Records....");
fread((char*)&b,sizeof(struct bank),1,f);
while(!feof(f))
{
dis();
fread((char*)&b,sizeof(struct bank),1,f);
}
fclose(f);
}
int searchrec(int ano)
{
struct bank bt;
f=fopen("c:\\bank.dat","r");
fread((char*)&bt,sizeof(struct bank),1,f);
while(!feof(f))
{
if(ano==bt.acc)
{
printf("\nNew A/c No : %d found",ano);
b=bt;
dis();
break;
}
fread((char*)&bt,sizeof(struct bank),1,f);
}
if(feof(f))
{
printf("\n A/C not exist...");
return -1;
}
fclose(f);
return 1;
}
updaterec(int ano)
{
int i,fs,recs,sa,chh,sz;
struct bank bt[RECS];
f=fopen("c:\\bank.dat","r");
/* finding records in file..*/
fseek(f,0,SEEK_END);
fs=ftell(f);
recs=fs/sizeof(struct bank);
sz=recs;
/* reding all recs */
fseek(f,0,SEEK_SET);
fread((char*)&bt,sizeof(struct bank),recs,f);
/*
for(i=0;i<recs;i++)
printf("\n%d",st[i].sno);
*/
printf("\nFile size : %d \nRecord Size : %d\nRecords : %d",fs,recs);
sz--;
while(sz>=0)
{
if(ano==bt[sz].acc)
{
printf("\nA/c No : %d found to update..",ano);
/* printf("\n1....Account no");
printf("\n2....A/C holder name");*/
printf("\n3....Balance Rs");
printf("\n0....E.X.I.T");
printf("\nChoice:");
scanf("%d",&chh);
switch(chh)
{
/* case 1:
printf("\nEnter New Sno:");
scanf("%d",&st[sz].sno);
break;
case 2:
printf("\nEnter New Stu name:");
scanf("%s",&st[sz].sname);
break;*/
case 3:
printf("\nEnter New BALANCE:");
scanf("%f",&bt[sz].bal);
break;
case 0:
printf("Return to main menu..");
return 0;
default:
printf("Return to main menu..");
return 0;
}
break;
}
sz--;
}
fclose(f);
/* remove the file */
remove("c:\\bank.dat");
f=fopen("c:\\bank.dat","w");
fwrite((char*)&bt,sizeof(struct bank),recs,f);
printf("\nUpdated...");
fclose(f);
printf("\nUpdated A/C Details...");
}
deleterec(int ano)
{
struct bank bt;
FILE*f1; /* for writing */
f=fopen("c:\\bank.dat","r");
f1=fopen("c:\\temp.dat","w");
fread((char*)&bt,sizeof(struct bank),1,f);
while(!feof(f))
{
if(ano!=bt.acc)
{
fwrite((char*)&bt,sizeof(struct bank),1,f1);
}
fread((char*)&bt,sizeof(struct bank),1,f);
}
fcloseall();
remove("c:\\bank.dat");
rename("c:\\temp.dat","c:\\bank.dat");
printf("\n Deleted...");
}
updatebal(int acc,char type)
{
int i,fs,recs,sa,chh,sz;
float amt;
struct bank bt[RECS];
f=fopen("c:\\bank.dat","r");
/* finding records in file..*/
fseek(f,0,SEEK_END);
fs=ftell(f);
recs=fs/sizeof(struct bank);
sz=recs;
/* reding all recs */
fseek(f,0,SEEK_SET);
fread((char*)&bt,sizeof(struct bank),recs,f);
sz--;
while(sz>=0)
{
rpt:
printf("\nA/c No : %d ",bt[sz].acc);
printf("\nA/c Name : %s ",bt[sz].aname);
printf("\nA/c Old Bal Rs/- : %.2f ",bt[sz].bal);
if(acc==bt[sz].acc)
{
if(type=='c')
{
printf("\n%Cr Balance Rs:");
scanf("%f",&amt);
bt[sz].bal+=amt;
}
else
{
printf("\nDebit Balance Rs:");
scanf("%f",&amt);
bt[sz].bal-=amt;
}
}
printf("\nA/c New Bal Rs/- : %.2f ",bt[sz].bal);
printf("\nyes/yo : ");
fflush(stdin);
cho=getchar();
if(cho=='y')
break;
else
{
if(type=='c')
bt[sz].bal-=amt;
else
bt[sz].bal+=amt;
goto rpt;
}
sz--;
}
fclose(f);
puts("\nProcessing.....wait");
delay(300);
/* remove the file */
remove("c:\\bank.dat");
f=fopen("c:\\bank.dat","w");
fwrite((char*)&bt,sizeof(struct bank),recs,f);
delay(300);
printf("\nUpdating Balance...wait");
delay(300);
printf("\nUpdating Ledger...");
fclose(f);
}
int transaction(int acc)
{
clrscr();
/* searching a/c */
if(searchrec(acc)==-1)
{
perror("\nA/c not Exist Contact Manager:");
return 0;
}
menu1();
switch(chh)
{
case '1':
updatebal(acc,'c');
break;
case '2':
updatebal(acc,'d');
break;
case '0':
break;
}
}
menu()
{
clrscr();
printf("\n\t\t\t RISE_BANK_MENU ");
printf("\n\t\t\t ");
printf("\n\t\t\t 1...Adding a new A/C ");
printf("\n\t\t\t 2...Display All A/C s ");
printf("\n\t\t\t 3...Search Account ");
printf("\n\t\t\t 4...Update Account ");
printf("\n\t\t\t 5...Delete Account ");
printf("\n\t\t\t 6...Transaction Menu ");
printf("\n\t\t\t 0...E.X.I.T ");
printf("\n\t\t\t ");
printf("\n\t\t\t \n\n");
printf("\n\t\t\t Choice:");
scanf("%c",&ch);
}
menu1()
{
clrscr();
printf("\n\t\t\t TRANS_BANK_MENU ");
printf("\n\t\t\t ");
printf("\n\t\t\t 1...C/r Bal Rs ");
printf("\n\t\t\t 2...D/b Bal Rs ");
printf("\n\t\t\t 0...E.X.I.T ");
printf("\n\t\t\t ");
printf("\n\t\t\t \n\n");
printf("\n\t\t\t Choice:");
fflush(stdin);
scanf("%c",&chh);
}
main()
{
int ano;
clrscr();
do
{
menu();
switch(ch)
{
case '1':
addrec();
break;
case '2':
disrecs();
break;
case '0':
exit(0);
case '3':
printf("\nEnter A/cno To Search?");
scanf("%d",&ano);
searchrec(ano);
break;
case '4':
printf("\nEnter A/cno To Update?");
scanf("%d",&ano);
updaterec(ano);
break;
case '5':
printf("\nEnter A/C no To Delete?");
scanf("%d",&ano);
deleterec(ano);
break;
case '6':
printf("\nEnter a/c no ?");
scanf("%d",&acc);
transaction(acc);
break;
default:
perror("\nEnter choice :1/2/0 Only..");
}
getch();
}while(ch!='0');
}
int checkrec(int ano)
{
struct bank bt;
f=fopen("c:\\bank.dat","r");
fread((char*)&bt,1,sizeof(struct bank),f);
while(!feof(f))
{
if(ano==bt.acc)
{
fclose(f);
return -1;
}
fread((char*)&bt,1,sizeof(struct bank),f);
}
fclose(f);
return 1;
}
No comments:
Post a Comment