//A PROJECT BY LAKSHAY NAGPAL
//Creating and Modifing an Account in the bank
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<fstream.h>
#include<stdio.h> //rename() , remove()
#include<string.h>
class AVR
{
long accno; //account number
char name[40]; //customer name
char add[50]; //address of customer
float amount; //total amount in account
public:
void accept();
void display();
void search();
void modify();
void del();
void readfile();
void writefile();
}S;
fstream f;
void AVR::accept()
{
cout<<"\nEnter The Name Of Customer :\n\n\n\n";
gets(name);
cout<<"\nEnter The Address Of Customer :\n\n\n\n";
gets(add);
cout<<"\nEnter The Account Number :\n\n\n\n";
cin>>accno;
cout<<"\nEnter Total Amount In Customer's Account :\n\n\n\n";
cin>>amount;
getch();
}
void AVR::display()
{
cout<<"\n\t\t\tThe Name Of The Customer Is :\n\n\n\n\t\t\t";
puts(name);
cout<<"\n\t\t\tThe Address Of The Customer Is :\n\n\n\n\t\t\t";
puts(add);
cout<<"\n\t\t\tCustomers Account Number Is :\n\n\n\n\t\t\t";
cout<<accno;
cout<<"\n\t\t\tPresent Ammount In Customer's Account Is :\n\n\n\n\t\t\t";
cout<<amount;
getch();
}
void AVR::writefile()
{
f.open("AVR.DAT",ios::app|ios::binary);
accept();
f.write((char*)&S,sizeof(S));
f.close();
}
void AVR::readfile()
{
f.open("AVR.DAT",ios::in|ios::binary);
if(!f)
{
cout<<"****EMPTY FILE****";
getch();
return;
}
while(f.read((char*)&S,sizeof(S)))
{
display();
getch();
clrscr();
}
f.close();
}
void AVR::search()
{
long taccno;
int flag=0;
cout<<"Enter The Account Number To Be Searched :\n";
cin>>taccno;
f.open("AVR.DAT",ios::in|ios::binary);
while(!f.eof())
{
f.read((char*)&S,sizeof(S));
if(f.eof())
break;
if(S.accno==taccno)
{
S.display();
getch();
flag=1;
}
}
if(flag==0)
{
cout<<"The Account Number Does Not Exist\n";
getch();
}
f.close();
}
void AVR::del()
{
long taccno;
int check=0;
fstream f1;
cout<<"Enter The Account Number To Close The Account :\n";
cin>>taccno;
f.open("AVR.DAT",ios::in|ios::binary);
f1.open("RAV.DAT",ios::out|ios::binary);
f.seekg(0);
while(!f.eof())
{
f.read((char*)&S,sizeof(S));
if(taccno!=accno)
{
if(!f.eof())
f1.write((char*)&S,sizeof(S));
}
else if(taccno==accno)
check=1;
}
f.close();
f1.close();
remove("AVR.DAT");
rename("RAV.DAT","AVR.DAT");
if(check==0)
cout<<"\t\t\t***Account Number Not Found***\n";
else
cout<<"\n\n\n\n\t\t ****Account Closed Successfully****\n";
getch();
}
void AVR::modify()
{
long taccno;
int tamount;
float withdraw,deposit;
char tadd[55];
int choice,t=0,flag=0,n=0;
cout<<"\n\n\n\nEnter The Customer's Account Number :\n";
cin>>taccno;
f.open("AVR.DAT",ios::in|ios::out|ios::binary);
while(!f.eof())
{
n++;
f.read((char*)&S,sizeof(S));
if(f.eof())
break;
if(S.accno==taccno)
{
flag=1;
S.display();
cout<<"\n\n\n1.Modify Customer's Address.";
cout<<"\n\n\n2.Enter Amount Withdrawl.";
cout<<"\n\n\n3.Enter Amount Deposited.";
cout<<"\n\n\n4.Exit";
cout<<"\n\n\nEnter your choice :";
cin>>choice;
switch(choice)
{
case 1:t=(n-1)*sizeof(S);
cout<<"\n\nEnter Customer's New Address :\n";
gets(tadd);
strcpy(add,tadd);
f.seekp(t,ios::beg);
f.write((char*)&S,sizeof(S));
cout<<"\n\n\t\t\t\tAddress Is Modified";
getch();
break;
case 2:t=(n-1)*sizeof(S);
cout<<"\n\nEnter The Withdrawl Amount :\n";
cin>>withdraw;
if(withdraw>0)
{
amount=amount-withdraw;
f.seekp(t,ios::beg);
f.write((char*)&S,sizeof(S));
cout<<"\n\n\n\t\t\t\tAmount Modified";
getch();
}
break;
case 3:t=(n-1)*sizeof(S);
cout<<"\n\n\nEnter The Deposited Amount :\n";
cin>>deposit;
if(deposit>0)
{
amount=amount+deposit;
f.seekp(t,ios::beg);
f.write((char*)&S,sizeof(S));
cout<<"\n\n\t\t\t\t\tAmount Modified";
getch();
}
break;
case 4:return;
default:cout<<"\n Wrong Choice";
}
}
}
if(flag==0)
{
cout<<"\n****Account Number Not Found****";
getch();
}
f.close();
}
void main()
{
clrscr();
int ch=1;
cout<<"\n\n\n\n\n\n\n\n\n\n\t\t\t____________________________\n\n";
cout<<"\t\t\tWELCOME TO AVR BANK OF INDIA";
cout<<"\n\t\t\t____________________________";
cout<<"\n\n\n\n\n\n\n\n\n\n\n\t\t\t PRESS ENTER TO CONTINUE";
getch();
while(ch!=6)
{
clrscr();
cout<<"\n\n\t\t\t\t MAIN MENU\n";
cout<<"\n\n\n\n\n\n\n\t\t\t1.Enter Records";
cout<<"\n\n\n\n\t\t\t2.Display Records";
cout<<"\n\n\n\n\t\t\t3.Search Records";
cout<<"\n\n\n\n\t\t\t4.Modify Account Records";
cout<<"\n\n\n\n\t\t\t5.Close Account";
cout<<"\n\n\n\n\t\t\t6.EXIT";
cout<<"\n\n\n\n\n\n\nEnter Your Choice :\n";
cin>>ch;
switch(ch)
{
case 1:clrscr();
cout<<"\n\n\t\t\t\t***ADD RECORD***\n\n\n\n";
S.writefile();
break;
case 2:clrscr();
cout<<"\n\n\t\t\t\t***DISPLAY RECORD***\n\n\n\n\n";
S.readfile();
break;
case 3:clrscr();
cout<<"\n\n\t\t\t\t***SEARCH RECORD***\n\n\n\n";
S.search();
break;
case 4:clrscr();
cout<<"\n\n\t\t\t\t***MODIFY RECORD***\n\n\n\n";
S.modify();
break;
case 5:clrscr();
cout<<"\n\n\t\t\t\t***DELETE ACCOUNT***\n\n\n\n";
S.del();
break;
case 6:return;
default:cout<<"\n\n\n\n\n\n\n\n\t\t\t\t\t\t\t**WRONG CHOICE**";
}
}
}
//Creating and Modifing an Account in the bank
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<fstream.h>
#include<stdio.h> //rename() , remove()
#include<string.h>
class AVR
{
long accno; //account number
char name[40]; //customer name
char add[50]; //address of customer
float amount; //total amount in account
public:
void accept();
void display();
void search();
void modify();
void del();
void readfile();
void writefile();
}S;
fstream f;
void AVR::accept()
{
cout<<"\nEnter The Name Of Customer :\n\n\n\n";
gets(name);
cout<<"\nEnter The Address Of Customer :\n\n\n\n";
gets(add);
cout<<"\nEnter The Account Number :\n\n\n\n";
cin>>accno;
cout<<"\nEnter Total Amount In Customer's Account :\n\n\n\n";
cin>>amount;
getch();
}
void AVR::display()
{
cout<<"\n\t\t\tThe Name Of The Customer Is :\n\n\n\n\t\t\t";
puts(name);
cout<<"\n\t\t\tThe Address Of The Customer Is :\n\n\n\n\t\t\t";
puts(add);
cout<<"\n\t\t\tCustomers Account Number Is :\n\n\n\n\t\t\t";
cout<<accno;
cout<<"\n\t\t\tPresent Ammount In Customer's Account Is :\n\n\n\n\t\t\t";
cout<<amount;
getch();
}
void AVR::writefile()
{
f.open("AVR.DAT",ios::app|ios::binary);
accept();
f.write((char*)&S,sizeof(S));
f.close();
}
void AVR::readfile()
{
f.open("AVR.DAT",ios::in|ios::binary);
if(!f)
{
cout<<"****EMPTY FILE****";
getch();
return;
}
while(f.read((char*)&S,sizeof(S)))
{
display();
getch();
clrscr();
}
f.close();
}
void AVR::search()
{
long taccno;
int flag=0;
cout<<"Enter The Account Number To Be Searched :\n";
cin>>taccno;
f.open("AVR.DAT",ios::in|ios::binary);
while(!f.eof())
{
f.read((char*)&S,sizeof(S));
if(f.eof())
break;
if(S.accno==taccno)
{
S.display();
getch();
flag=1;
}
}
if(flag==0)
{
cout<<"The Account Number Does Not Exist\n";
getch();
}
f.close();
}
void AVR::del()
{
long taccno;
int check=0;
fstream f1;
cout<<"Enter The Account Number To Close The Account :\n";
cin>>taccno;
f.open("AVR.DAT",ios::in|ios::binary);
f1.open("RAV.DAT",ios::out|ios::binary);
f.seekg(0);
while(!f.eof())
{
f.read((char*)&S,sizeof(S));
if(taccno!=accno)
{
if(!f.eof())
f1.write((char*)&S,sizeof(S));
}
else if(taccno==accno)
check=1;
}
f.close();
f1.close();
remove("AVR.DAT");
rename("RAV.DAT","AVR.DAT");
if(check==0)
cout<<"\t\t\t***Account Number Not Found***\n";
else
cout<<"\n\n\n\n\t\t ****Account Closed Successfully****\n";
getch();
}
void AVR::modify()
{
long taccno;
int tamount;
float withdraw,deposit;
char tadd[55];
int choice,t=0,flag=0,n=0;
cout<<"\n\n\n\nEnter The Customer's Account Number :\n";
cin>>taccno;
f.open("AVR.DAT",ios::in|ios::out|ios::binary);
while(!f.eof())
{
n++;
f.read((char*)&S,sizeof(S));
if(f.eof())
break;
if(S.accno==taccno)
{
flag=1;
S.display();
cout<<"\n\n\n1.Modify Customer's Address.";
cout<<"\n\n\n2.Enter Amount Withdrawl.";
cout<<"\n\n\n3.Enter Amount Deposited.";
cout<<"\n\n\n4.Exit";
cout<<"\n\n\nEnter your choice :";
cin>>choice;
switch(choice)
{
case 1:t=(n-1)*sizeof(S);
cout<<"\n\nEnter Customer's New Address :\n";
gets(tadd);
strcpy(add,tadd);
f.seekp(t,ios::beg);
f.write((char*)&S,sizeof(S));
cout<<"\n\n\t\t\t\tAddress Is Modified";
getch();
break;
case 2:t=(n-1)*sizeof(S);
cout<<"\n\nEnter The Withdrawl Amount :\n";
cin>>withdraw;
if(withdraw>0)
{
amount=amount-withdraw;
f.seekp(t,ios::beg);
f.write((char*)&S,sizeof(S));
cout<<"\n\n\n\t\t\t\tAmount Modified";
getch();
}
break;
case 3:t=(n-1)*sizeof(S);
cout<<"\n\n\nEnter The Deposited Amount :\n";
cin>>deposit;
if(deposit>0)
{
amount=amount+deposit;
f.seekp(t,ios::beg);
f.write((char*)&S,sizeof(S));
cout<<"\n\n\t\t\t\t\tAmount Modified";
getch();
}
break;
case 4:return;
default:cout<<"\n Wrong Choice";
}
}
}
if(flag==0)
{
cout<<"\n****Account Number Not Found****";
getch();
}
f.close();
}
void main()
{
clrscr();
int ch=1;
cout<<"\n\n\n\n\n\n\n\n\n\n\t\t\t____________________________\n\n";
cout<<"\t\t\tWELCOME TO AVR BANK OF INDIA";
cout<<"\n\t\t\t____________________________";
cout<<"\n\n\n\n\n\n\n\n\n\n\n\t\t\t PRESS ENTER TO CONTINUE";
getch();
while(ch!=6)
{
clrscr();
cout<<"\n\n\t\t\t\t MAIN MENU\n";
cout<<"\n\n\n\n\n\n\n\t\t\t1.Enter Records";
cout<<"\n\n\n\n\t\t\t2.Display Records";
cout<<"\n\n\n\n\t\t\t3.Search Records";
cout<<"\n\n\n\n\t\t\t4.Modify Account Records";
cout<<"\n\n\n\n\t\t\t5.Close Account";
cout<<"\n\n\n\n\t\t\t6.EXIT";
cout<<"\n\n\n\n\n\n\nEnter Your Choice :\n";
cin>>ch;
switch(ch)
{
case 1:clrscr();
cout<<"\n\n\t\t\t\t***ADD RECORD***\n\n\n\n";
S.writefile();
break;
case 2:clrscr();
cout<<"\n\n\t\t\t\t***DISPLAY RECORD***\n\n\n\n\n";
S.readfile();
break;
case 3:clrscr();
cout<<"\n\n\t\t\t\t***SEARCH RECORD***\n\n\n\n";
S.search();
break;
case 4:clrscr();
cout<<"\n\n\t\t\t\t***MODIFY RECORD***\n\n\n\n";
S.modify();
break;
case 5:clrscr();
cout<<"\n\n\t\t\t\t***DELETE ACCOUNT***\n\n\n\n";
S.del();
break;
case 6:return;
default:cout<<"\n\n\n\n\n\n\n\n\t\t\t\t\t\t\t**WRONG CHOICE**";
}
}
}
No comments:
Post a Comment