** PLEASE C++ ONLY ** Define the class bankAccount to implement the basic proper
ID: 3856984 • Letter: #
Question
** PLEASE C++ ONLY **
Define the class bankAccount to implement the basic properties of a
bank account. An object of this class should store the following data:
Account holder’s name (string), account number (int), account type
(string, checking/saving), balance (double), and interest rate (double).
(Store interest rate as a decimal number.) Add appropriate member functions
to manipulate an object. Use a static member in the class to
automatically assign account numbers. Also declare an array of 10 components
of type bankAccount to process up to 10 customers and write a
program to illustrate how to use your class.
i.The constructor
ii.Set the data (name, account type, balance, interest rate)
iii.Deposit – receives amount of deposit
iv.Withdraw – receives amount of withdraw
v.Get the Interest Rate – returns the interest rate
vi.Get Account Number – returns the account number
vii.Get the Account Holders Name – returns the name
viii.Get the Account Type – returns the account type
ix.Get the balance – returns the balance
x.Print – nice output of one account and all of its information
Explanation / Answer
The required code in c++ is as follows:
BankManagement.cpp
#include<iostream>
#include<fstream>
#include<cctype>
#include<iomanip>
using namespace std;
class BankManagement
{
int accId;
char accName[50];
int depositedAmt;
char accType;
public:
void createAcc();
void dispAcc() const;
void alter();
void deposits(int);
void withdraw(int);
void dataTab() const;
int AccNo() const;
int retDepo() const;
char typeAcc() const;
};
void BankManagement::createAcc()
{
cout<<" Account No. :";
cin>>accId;
cout<<" Enter Name of Account Holder : ";
cin.ignore();
cin.getline(accName,50);
cout<<" Type of Account(C/S) : ";
cin>>accType;
accType=toupper(accType);
cout<<" Initial amount(>=500 for Saving and >=1000 for current ) : ";
cin>>depositedAmt;
cout<<" Account has been created..";
}
void BankManagement::dispAcc() const
{
cout<<" Account No. : "<<accId;
cout<<" Account Holder Name : ";
cout<<accName;
cout<<" Type of Account : "<<accType;
cout<<" Balance amount : "<<depositedAmt;
}
void BankManagement::alter()
{
cout<<" Account No. : "<<accId;
cout<<" Modify Account Holder Name : ";
cin.ignore();
cin.getline(accName,50);
cout<<" Modify Type of Account : ";
cin>>accType;
accType=toupper(accType);
cout<<" Modify Balance amount : ";
cin>>depositedAmt;
}
void BankManagement::deposits(int io)
{
depositedAmt+=io;
}
void BankManagement::withdraw(int io)
{
depositedAmt-=io;
}
void BankManagement::dataTab() const
{
cout<<accId<<setw(10)<<" "<<accName<<setw(10)<<" "<<accType<<setw(6)<<depositedAmt<<endl;
}
int BankManagement::AccNo() const
{
return accId;
}
int BankManagement::retDepo() const
{
return depositedAmt;
}
char BankManagement::typeAcc() const
{
return accType;
}
void recordEdit();
void accDetails(int);
void alterAcc(int);
void delAcc(int);
void dispAll();
void depORwithdraw(int, int);
void introduction();
int main()
{
char choice;
int no;
introduction();
do
{
system("cls");
cout<<" MAIN MENU";
cout<<" 01. NEW ACCOUNT";
cout<<" 02. DEPOSIT AMOUNT";
cout<<" 03. WITHDRAW AMOUNT";
cout<<" 04. BALANCE ENQUIRY";
cout<<" 05. ALL ACCOUNT HOLDER LIST";
cout<<" 06. CLOSE AN ACCOUNT";
cout<<" 07. MODIFY AN ACCOUNT";
cout<<" 08. EXIT";
cout<<" Select Your Option (1-8) ";
cin>>choice;
system("cls");
switch(choice)
{
case '1':
recordEdit();
break;
case '2':
cout<<" Account No. : "; cin>>no;
depORwithdraw(no, 1);
break;
case '3':
cout<<" Account No. : "; cin>>no;
depORwithdraw(no, 2);
break;
case '4':
cout<<" Account No. : "; cin>>no;
accDetails(no);
break;
case '5':
dispAll();
break;
case '6':
cout<<" Account No. : "; cin>>no;
delAcc(no);
break;
case '7':
cout<<" Account No. : "; cin>>no;
alterAcc(no);
break;
case '8':
cout<<" Thanks for using our services.";
break;
default :cout<<"";
}
cin.ignore();
cin.get();
}while(choice!='8');
return 0;
}
void recordEdit()
{
BankManagement bm;
ofstream of;
of.open("BankManagement.dat",ios::binary|ios::app);
bm.createAcc();
of.write(reinterpret_cast<char *> (&bm), sizeof(BankManagement));
of.close();
}
void accDetails(int n)
{
BankManagement bm;
bool fl=false;
ifstream if;
if.open("BankManagement.dat",ios::binary);
if(!if)
{
cout<<"fs could not be open !! Press any Key...";
return;
}
cout<<" BALANCE DETAILS ";
while(if.read(reinterpret_cast<char *> (&bm), sizeof(BankManagement)))
{
if(bm.AccNo()==n)
{
bm.dispAcc();
fl=true;
}
}
if.close();
if(fl==false)
cout<<" Account number does not exist";
}
void alterAcc(int n)
{
bool searched=false;
BankManagement bm;
fstream fs;
fs.open("BankManagement.dat",ios::binary|ios::in|ios::out);
if(!fs)
{
cout<<"fs could not be open !! Press any Key...";
return;
}
while(!fs.eof() && searched==false)
{
fs.read(reinterpret_cast<char *> (&bm), sizeof(BankManagement));
if(bm.AccNo()==n)
{
bm.dispAcc();
cout<<" Enter The New Details of BankManagement"<<endl;
bm.alter();
int position=(-1)*static_cast<int>(sizeof(BankManagement));
fs.seekp(position,ios::cur);
fs.write(reinterpret_cast<char *> (&bm), sizeof(BankManagement));
cout<<" Record Updated";
searched=true;
}
}
fs.close();
if(searched==false)
cout<<" Record Not Found ";
}
void delAcc(int n)
{
BankManagement bm;
ifstream if;
ofstream of;
if.open("BankManagement.dat",ios::binary);
if(!if)
{
cout<<"fs could not be open !! Press any Key...";
return;
}
of.open("Temp.dat",ios::binary);
if.seekg(0,ios::beg);
while(if.read(reinterpret_cast<char *> (&bm), sizeof(BankManagement)))
{
if(bm.AccNo()!=n)
{
of.write(reinterpret_cast<char *> (&bm), sizeof(BankManagement));
}
}
if.close();
of.close();
remove("BankManagement.dat");
rename("Temp.dat","BankManagement.dat");
cout<<" Record Deleted ..";
}
void dispAll()
{
BankManagement bm;
ifstream if;
if.open("BankManagement.dat",ios::binary);
if(!if)
{
cout<<"fs could not be open !! Press any Key...";
return;
}
cout<<" ACCOUNT HOLDER LIST ";
cout<<"==================================================== ";
cout<<"A/c no. NAME Type Balance ";
cout<<"==================================================== ";
while(if.read(reinterpret_cast<char *> (&bm), sizeof(BankManagement)))
{
bm.dataTab();
}
if.close();
}
void depORwithdraw(int n, int opt)
{
int amounts;
bool searched=false;
BankManagement bm;
fstream fs;
fs.open("BankManagement.dat", ios::binary|ios::in|ios::out);
if(!fs)
{
cout<<"fs could not be open !! Press any Key...";
return;
}
while(!fs.eof() && searched==false)
{
fs.read(reinterpret_cast<char *> (&bm), sizeof(BankManagement));
if(bm.AccNo()==n)
{
bm.dispAcc();
if(opt==1)
{
cout<<" TO DEPOSITE AMOUNT ";
cout<<" Enter The amount to be deposited";
cin>>amounts;
bm.deposits(amounts);
}
if(opt==2)
{
cout<<" TO WITHDRAW AMOUNT ";
cout<<" Enter The amount to be withdraw";
cin>>amounts;
int bal=bm.retDepo()-amounts;
if((bal<500 && bm.typeAcc()=='S') || (bal<1000 && bm.typeAcc()=='C'))
cout<<"Insufficience balance";
else
bm.withdraw(amounts);
}
int position=(-1)*static_cast<int>(sizeof(bm));
fs.seekp(position,ios::cur);
fs.write(reinterpret_cast<char *> (&bm), sizeof(BankManagement));
cout<<" Record Updated";
searched=true;
}
}
fs.close();
if(searched==false)
cout<<" Record Not Found ";
}
void introduction()
{
cout<<" BANK";
cout<<" MANAGEMENT";
cout<<" SYSTEM";
cout<<" MADE BY : your accName";
cout<<" SCHOOL : your school accName";
cin.get();
}
Please rate the answer if it helped.....Thankyou
Hope it helps....
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.