The Code is as follow
#include<iostream>
#include<fstream>
#include<cctype>
#include<iomanip>
using namespace std;
int InitialNumber=2016000;
int GenerateAccount()
{
return InitialNumber+=1;
}
class account
{
int accountno;
char name[50];
int depositCash;
char Accounttype;
public:
void create_account();
void show_account() const;
void modify();
void deposit(int);
void draw(int);
void report() const;
int returnaccountno() const;
int returndeposit() const;
char returntype() const;
};
void account::create_account()
{
std::cout<<"\n\nEnter The Name of The account Holder : ";
std::cin.ignore();
std::cin.getline(name,50);
std::cout<<"\nEnter Type of The account (C/S) : ";
std::cin>>Accounttype;
Accounttype=toupper(Accounttype);
std::cout<<"\nEnter The Initial amount : ";
std::cin>>depositCash;
accountno=GenerateAccount();
cout<<"\nYour Account Number is :"<<accountno;
std::cout<<"\n\n\nAccount Created..";
}
void account::show_account() const
{
std::cout<<"\nAccount No. : "<<accountno;
std::cout<<"\nAccount Holder Name : ";
std::cout<<name;
std::cout<<"\nType of Account : "<<Accounttype;
std::cout<<"\nBalance amount : "<<depositCash;
}
void account::modify()
{
std::cout<<"\nAccount No. : "<<accountno;
std::cout<<"\nModify Account Holder Name : ";
std::cin.ignore();
std::cin.getline(name,50);
std::cout<<"\nModify Type of Account : ";
std::cin>>Accounttype;
Accounttype=toupper(Accounttype);
std::cout<<"\nModify Balance amount : ";
std::cin>>depositCash;
}
void account::deposit(int x)
{
depositCash+=x;
}
void account::draw(int x)
{
depositCash-=x;
}
void account::report() const
{
std::cout<<accountno<<setw(10)<<" "<<name<<setw(10)<<" "<<Accounttype<<setw(6)<<depositCash<<endl;
}
char account::returntype() const
{
return Accounttype;
}
int account::returnaccountno() const
{
return accountno;
}
int account::returndeposit() const
{
return depositCash;
}
class functions: public account
{
public:
void write_account()
{
account ac;
ofstream outFile;
outFile.open("account.dat",ios::binary|ios::app);
ac.create_account();
outFile.write(reinterpret_cast<char *> (&ac), sizeof(account));
outFile.close();
}
void display_sp(int n)
{
account ac;
bool flag=false;
ifstream inFile;
inFile.open("account.dat",ios::binary);
if(!inFile)
{
std::cout<<"File could not be open !! Press any Key...";
return;
}
std::cout<<"\nBALANCE DETAILS\n";
while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(account)))
{
if(ac.returnaccountno()==n)
{
ac.show_account();
flag=true;
}
}
inFile.close();
if(flag==false)
std::cout<<"\n\nAccount number does not exist";
}
void modify_account(int n)
{
bool found=false;
account ac;
fstream File;
File.open("account.dat",ios::binary|ios::in|ios::out);
if(!File)
{
std::cout<<"File could not be open !! Press any Key...";
return;
}
while(!File.eof() && found==false)
{
File.read(reinterpret_cast<char *> (&ac), sizeof(account));
if(ac.returnaccountno()==n)
{
ac.show_account();
std::cout<<"\n\nEnter The New Details of account"<<endl;
ac.modify();
int pos=(-1)*static_cast<int>(sizeof(account));
File.seekp(pos,ios::cur);
File.write(reinterpret_cast<char *> (&ac), sizeof(account));
std::cout<<"\n\n\t Record Updated";
found=true;
}
}
File.close();
if(found==false)
std::cout<<"\n\n Record Not Found ";
}
void delete_account(int n)
{
account ac;
ifstream inFile;
ofstream outFile;
inFile.open("account.dat",ios::binary);
if(!inFile)
{
std::cout<<"File could not be open !! Press any Key...";
return;
}
outFile.open("Temp.dat",ios::binary);
inFile.seekg(0,ios::beg);
while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(account)))
{
if(ac.returnaccountno()!=n)
{
outFile.write(reinterpret_cast<char *> (&ac), sizeof(account));
}
}
inFile.close();
outFile.close();
remove("account.dat");
std::rename("Temp.dat","account.dat");
std::cout<<"\n\n\tRecord Deleted ..";
}
void display_all()
{
account ac;
ifstream inFile;
inFile.open("account.dat",ios::binary);
if(!inFile)
{
std::cout<<"File could not be open !! Press any Key...";
return;
}
std::cout<<"\n\n\t\tACCOUNT HOLDER LIST\n\n";
std::cout<<"====================================================\n";
std::cout<<"A/c no. NAME Type Balance\n";
std::cout<<"====================================================\n";
while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(account)))
{
ac.report();
}
inFile.close();
}
void deposit_withdraw(int n, int option)
{
int amt;
bool found=false;
account ac;
fstream File;
File.open("account.dat", ios::binary|ios::in|ios::out);
if(!File)
{
std::cout<<"File could not be open !! Press any Key...";
return;
}
while(!File.eof() && found==false)
{
File.read(reinterpret_cast<char *> (&ac), sizeof(account));
if(ac.returnaccountno()==n)
{
ac.show_account();
if(option==1)
{
std::cout<<"\n\n\tTO DEPOSITE AMOUNT ";
std::cout<<"\n\nEnter The amount to be deposited";
std::cin>>amt;
ac.deposit(amt);
}
if(option==2)
{
std::cout<<"\n\n\tTO WITHDRAW AMOUNT ";
std::cout<<"\n\nEnter The amount to be withdraw";
std::cin>>amt;
int bal=ac.returndeposit()-amt;
if((bal<500 && ac.returntype()=='S') || (bal<1000 && ac.returntype()=='C'))
std::cout<<"Insufficience balance";
else
ac.draw(amt);
}
int pos=(-1)*static_cast<int>(sizeof(ac));
File.seekp(pos,ios::cur);
File.write(reinterpret_cast<char *> (&ac), sizeof(account));
std::cout<<"\n\n\t Record Updated";
found=true;
}
}
File.close();
if(found==false)
std::cout<<"\n\n Record Not Found ";
}
};
class menu:public account,public functions
{
protected:
int ch,num;
public:
void mainScreen()
{
do
{
system("cls");
std::cout<<"__________SELECT ROLE_________";
std::cout<<"\n\n01 : Manager";
std::cout<<"\n\n02 : Teller";
std::cout<<"\n\n03 : Accountant";
std::cin>>ch;
system("cls");
switch (ch)
{
case 1:
ManagerMenu();
break;
case 2:
TellerMenu();
break;
case 3:
AccountantMenu();
break;
case 4:
std::cout<<"\n\n\tThanks for using bank managemnt system";
break;
default :std::cout<<"\a";
}
std::cin.ignore();
std::cin.get();
}while(ch!=4);
}
void AccountantMenu()
{
do{
system("cls");
std::cout<<"\n\n\t01. NEW ACCOUNT";
std::cout<<"\n\n\t02. ALL ACCOUNT HOLDER LIST";
std::cout<<"\n\n\t03. CLOSE AN ACCOUNT";
std::cout<<"\n\n\t04. MODIFY AN ACCOUNT";
std::cout<<"\n\n\t05. EXIT";
std::cout<<"\n\n\tSelect Your Option (1-5) ";
std::cin>>ch;
system("cls");
switch (ch)
{
case 1:
write_account();
break;
case 2:
display_all();
break;
case 3:
std::cout<<"\n\n\tEnter The account No. : ";
std::cin>>num;
delete_account(num);
case 4:
std::cout<<"\n\n\tEnter The account No. : ";
std::cin>>num;
modify_account(num);
case 5:
std::cout<<"\n\n\tThanks for using bank managemnt system";
break;
deafult :std::cout<<"\a";
}
std::cin.ignore();
std::cin.get();
}while(ch!=5);
}
void TellerMenu()
{
do{
system("cls");
std::cout<<"\n\n\t01. DEPOSIT AMOUNT";
std::cout<<"\n\n\t02. WITHDRAW AMOUNT";
std::cout<<"\n\n\t03. BALANCE ENQUIRY";
std::cout<<"\n\n\t04. ALL ACCOUNT HOLDER LIST";
std::cout<<"\n\n\t05. EXIT";
std::cout<<"\n\n\tSelect Your Option (1-5) ";
std::cin>>ch;
system("cls");
switch (ch)
{
case 1:
std::cout<<"\n\n\tEnter The account No. : ";
std::cin>>num;
deposit_withdraw(num, 1);
break;
case 2:
std::cout<<"\n\n\tEnter The account No. : ";
std::cin>>num;
deposit_withdraw(num, 2);
break;
case 3:
std::cout<<"\n\n\tEnter The account No. : ";
std::cin>>num;
display_sp(num);
break;
case 4:
display_all();
break;
case 5:
std::cout<<"\n\n\tThanks for using bank managemnt system";
break;
default :std::cout<<"\a";
}
std::cin.ignore();
std::cin.get();
}while(ch!=5);
}
void ManagerMenu()
{
do
{
system("cls");
std::cout<<"\n\n\n\tMAIN MENU";
std::cout<<"\n\n\t01. NEW ACCOUNT";
std::cout<<"\n\n\t02. DEPOSIT AMOUNT";
std::cout<<"\n\n\t03. WITHDRAW AMOUNT";
std::cout<<"\n\n\t04. BALANCE ENQUIRY";
std::cout<<"\n\n\t05. ALL ACCOUNT HOLDER LIST";
std::cout<<"\n\n\t06. CLOSE AN ACCOUNT";
std::cout<<"\n\n\t07. MODIFY AN ACCOUNT";
std::cout<<"\n\n\t08. EXIT";
std::cout<<"\n\n\tSelect Your Option (1-8) ";
std::cin>>ch;
system("cls");
switch(ch)
{
case 1:
write_account();
break;
case 2:
std::cout<<"\n\n\tEnter The account No. : ";
std::cin>>num;
deposit_withdraw(num, 1);
break;
case 3:
std::cout<<"\n\n\tEnter The account No. : ";
std::cin>>num;
deposit_withdraw(num, 2);
break;
case 4:
std::cout<<"\n\n\tEnter The account No. : ";
std::cin>>num;
display_sp(num);
break;
case 5:
display_all();
break;
case 6:
std::cout<<"\n\n\tEnter The account No. : ";
std::cin>>num;
delete_account(num);
break;
case 7:
std::cout<<"\n\n\tEnter The account No. : ";
std::cin>>num;
modify_account(num);
break;
case 8:
std::cout<<"\n\n\tThanks for using bank managemnt system";
break;
default :std::cout<<"\a";
}
std::cin.ignore();
std::cin.get();
}while(ch!=8);
}
};
void intro();
int num;
int main()
{
int num;
intro();
menu m;
m.mainScreen();
return 0;
}
void intro()
{
std::cout<<"\n\n\n\t BANK";
std::cout<<"\n\n\tMANAGEMENT";
std::cout<<"\n\n\t SYSTEM";
std::cout<<"\n\n\n\nMADE BY : Ubaidullah Hassan & HAmza Asif";
std::cin.get();
}
0 comments
Post a Comment