Vous êtes sur la page 1sur 8

#include<fstream.

h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
#include<iomanip.h>
#include<stdlib.h>

class account {
unsigned long int acno;
struct loan {
float pri, amt, rate, years;
};
loan x;
struct date {
int da_year;
int da_day;
int da_mon;
};
date dob;
int age;
char name[32];
char resi[65];
char mobile[15];
char aadhar_no[15};
char branch[18];
float balance;
public:
void getdata(char type);
void showdata();
void disptab()
{
cout<<setw(14)<<acno
<<setw(32)<<name
<<setw(15)<<balance
<<setw(17)<<branch
<<endl;
}
float retbal()
{
return(balance);
}
unsigned long int retacno()
{
return(acno);
}
};

void account::getdata(char type)


{
clrscr();
char opt;
int dr;
cout<<�Enter account number (upto 9 digits) : �;
cin>>acno;
cout<<�Enter name of account holer: �;
gets(name);
cout<<�Enter age: �;
cin>>age;
cout<<�Enter date of birth (dd/mm/yyyy): �;
cin>>dob.da_day>>dob.da_mon>>dob.da_year;
cout<<�Enter aadhar card number: �;
cin>>aadhar_no;
cout<<�Enter mobile number: �;
cin>>mobile;
cout<<�Enter residential address of account holder: �;
gets(resi);
if( type == �a� )
cout<<�Enter amount of first deposit: Rs �;
else if( type == �b� )
cout<<�Enter current balance: Rs �;
cout<<�Enter branch name of where account is created: �;
gets(branch);
do
{
cout<<�Has the account holder applied for a loan? : �;
cin>>opt;
if( opt == �Y� || opt == �y� )
dr = 1;
else if( opt == �N� || opt == �n� )
dr = 2;
switch(dr)
{
case 1 : {
cout<<�Enter principal amount: �;
cin>>x.pri;
cout<<�Enter rate of interest: �;
cin>>x.rate;
cout<<�Enter time period(in years): �;
cin>>x.years;
int opt2;
cout<<�Press 1:Interest is simple�
<<endl;
cout<<�Press 2:Interest is compound�
<<endl ;
cin>>opt2;
if( opt2 == 1 )
{
x.amt=x.pri+(x.pri*x.rate*x.years)/100;
}
if( opt2 == 2 )
{
int n;
cout<<�Enter number of times the �
<<�interest is compounded: �;
cin>>n;
x.amt=x.pri*pow(1+(x.rate/n),n*x.years);
}
if( x.amt )
{
cout<<�Loan application successful�
<<endl;
}
break;
}
case 2: {
x.amt=x.pri=x.rate=x.years=0.0;
break;
}
default: cout<<�Invalid Input !!! �;
}
}while( opt != �n� || opt != �N� )
}

void account::showdata()
{
cout<<�Account number: �<<acno<<endl;
cout<<�Name: �<<name<<endl;
cout<<�Age: �<<age<<endl;
cout<<�Date of Birth: �<<dob.da_day<<�/�
<<dob.da_mon<<�/�<<dob.da_year<<endl;
cout<<�Aadhar number: �<<aadhar_no<<endl;
cout<<�Mobile number: �<<mobile<<endl;
cout<<�Residential address: �<<resi<<endl;
cout<<�Balance: Rs�<<balance<<endl;
cout<<�Home Branch: �<<branch<<endl;
cout<<�Applied for loan: �;
if(x.amt)
{
cout<<�Yes�<<endl;
cout<<�Debt: Rs �<<x.amt<<endl;
}
else
cout<<�No�<<endl;
}

void saveaccount()
{
fstream save;
save.open(�bank.dat� , ios::app | ios::binary);
if(save)
{
char choice;
account a;
do
{
cout<<�File opened successfully ! \n�;
cout<<endl;
a.getdata(�a�);
save.write((char*)&a, sizeof(a));
cout<<�Would you like to register more �
<<�accounts? (Y/N): �;
cin>>choice;
}while( choice == �Y� || choice == �y� );
save.close();
}
else
cout<<�File not opened !! \n�;
}

Void searchacbyacno()
{
clrscr();
fstream file;
file.open(�bank.dat�, ios::in | ios::binary);
account a;
unsigned long int anum;
cout<<�Enter account number of required account: �;
cin>>anum;
cout<<endl;
int found=0;
while(found == 0 && file)
{
file.read((char*)&a, sizeof(a));
if(a.retacno() == anum)
found=1;
}
if(found == 1)
{
cout<<�Account found!�;
cout<<�The details are as given below: \n\n�;
a.showdata();
}
else
cout<<�Account not found !!�;
file.close();
}

void delac()
{
fstream file1,file2;
file1.open(�bank.dat�, ios::in | ios::binary);
file2.open(�temp.dat�, ioss::out | ios::binary);
long int gcode;
cout<<�Enter the account number: �;
cin>>gcode;
account a;
while(file1.read((char*)&a, sizeof(a)))
{
if(a.retacno() != gcode)
file2.write((char*)&a, sizeof(a));
}
cout<<�Account has been deleted successfully�;
file1.close();
file2.close();
remove(�bank.dat�);
rename(�temp.dat� , �bank.dat�);
}
void modac()
{
unsigned long int gcode;
cout<<�Enter account number: �;
cin>>gcode;
fstream file;
file.open(�bank.dat�, ios::in | ios::app | ios::binary);
account a;
int found=0;
while(file.read((char*)&a , sizeof(a)))
{
if(a.retacno() == gcode)
{
found = 1;
break;
}
}
if( found == 0 )
{
cout<<�Account does not exist�;
getch();
file.close(); return;
}
else if(found)
{
cout<<�Please enter account holder�s info�
<<� with changes: \n\n�;
a.getdata(�b�);
file.seekg(-sizeof(a),ios::cur);
file.write((char*)&a, sizeof(a));
}
file.close();
}

Void showac()
{
clrscr();
fstream file;
file.open(�bank.dat�, ios::in | ios::binary);
account a;
if(file)
{
cout<<�File opened successfully !! \n�;
if(file.read((char*)&a,sizeof(a)))
{
cout<<�All registered accounts are: \n\n�;
cout<<setw(14)<<�A/c No: �
<<setw(32)<<�Name of account holder: �
<<setw(15)<<�Balance: �
<<setw(17)<<�Branch: �<<endl;
file.seekg(0, ios::beg);
while(file.read((char*)&a, sizeof(a)))
a.disptab();
}
else
cout<<�No accounts have been created !!�;
}
else
cout<<�Fie not opened !!�;
}

Int isstaff()
{
char code[5] = { �Hello� };
int access = 1;
char input[5];
cout<<�Enter the access code: �;
for(int i=0; i<5; i++)
{
input[i] = getch();
cout<<�*�;
}
getch();
cout<<endl;
for(i=0; i<5; i++)
if( input[i] != code[i] )
{
access = 0;
break;
}
if( access == 1 )
return(1);
else
return(0);
}
void menustaff()
{
cout<<�\n\t\t\t STAFF USER INTERFACE \n\n\n�;
cout<<� Press 1: Register new account (s). �<<endl;
cout<<� Press 2: View accounts list. �<<endl;
cout<<� Press 3: View info of an account. �<<endl;
cout<<� Press 4: Modify an account�s info. �<<endl;
cout<<� Press 5: Delete an account. �<<endl;
cout<<� Press 6: Back to main menu. �<<endl;
cout<<� Enter your choice: �;
}
void menucustomer()
{
cout<<�\n\t\t\t ACCOUNT HOLDER USER INTERFACE\n�;
cout<<� Press 1: View account info. �<<endl;
cout<<� Press 2: Modify your account info. �<<endl;
cout<<� Press 3: Apply for a loan. �<<endl;
cout<<� Press 4: Back to the main menu �<<endl;
cout<<� Enter your choice: �;
}

void main()
{
clrscr();
account a;
int driver, opt;
do
{
clrscr();
driver = 0;
opt = 0;
cout<<�\n\t\t WELCOME TO JDT BANK !! \n �;
cout<<�\t\t\t MAIN MENU \n\n\n �;
cout<<� Press 1: For Account Holders�<<endl;
cout<<� Press 2: For Bank Staff�<<endl;
cout<<� Press 3: To Exit�<<endl;
cout<<�Enter your choice: �;
cin>>driver;
switch(driver)
{
case 1:
{
do
{
opt = 0;
clrscr();
menucustomer();
cin>>opt;
switch(opt)
{
case 1:
{
searchacbyacno();
getch();
break;
}
case 2:
case 3:
{
modac();
getch();
break;
}
case 4: break;
default:
{
cout<<�Invalid Input�;
getch();
}
}
)while(opt != 4);
break;
}
case 2:
{
clrscr();
if( isstaff() )
{
do
{
opt = 0;
clrscr();
menustaff();
cin>>opt;
switch(opt)
{
case 1:
{
saveaccount();
getch();
break;
}
case 2:
{
showac();
getch();
break;
}
case 3:
{
searchacbyacno();
getch();
}
case 4:
{
clrscr();
modac();
getch();
break;
}
case 5:
{
clrscr();
delac();
getch();
break;
}
case 6: break;
default:
{
cout<<�Invalid Input�;
getch();
}
}
}whle( opt != 6 );
}
else
{
cout<<�Invalid Input !!�;
getch();
}
break;
}
case 3:
{
cout<<�\n\n Thank you for using JDT �
<<�Bank UI !!�;
getch();
exit(0);
}
default:
{
cout<<�Invalid Input !!!�;
getch();
}
}
}while(driver != 3);
}

Vous aimerez peut-être aussi