In: Computer Science
In C++, 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.
#include<bits/stdc++.h>
using namespace std;
class bankAccount{
string name;
int accountNumber;
string accountType;
double balance,interest;
public:
static int account;
bankAccount(){}
bankAccount(string n,string t,double b,double i)
{
accountNumber=account;
account++;
name=n;
accountType=t;
balance=b;
interest=i;
}
void display()
{
cout<<"Account Number:
"<<accountNumber<<endl;
cout<<"Name:
"<<name<<endl;
cout<<"Account Type:
"<<accountType<<endl;
cout<<"Balance:
"<<balance<<endl;
cout<<"Interest:
"<<interest<<endl;
cout<<endl;
}
void setBalance(double b)
{
balance=b;
}
void setInterest(double i)
{
interest=i;
}
};
int bankAccount::account=1000;
int main()
{
bankAccount * customer=new bankAccount[10];
//declaring 10 customers
customer[0]=bankAccount("ABC","SAVINGS",15000,5.2);
customer[1]=bankAccount("DEF","SAVINGS",5000,4.2);
customer[2]=bankAccount("GHI","CHECKING",25000,6.2);
customer[3]=bankAccount("JKL","SAVINGS",50000,8.1);
customer[4]=bankAccount("MNO","CHECKING",125000,16);
customer[5]=bankAccount("PQR","SAVINGS",175000,1.3);
customer[6]=bankAccount("STU","SAVINGS",1000,23.2);
customer[7]=bankAccount("VWX","CHECKING",200,14.2);
customer[8]=bankAccount("YZS","CHECKING",25300,3.6);
customer[9]=bankAccount("CSD","SAVINGS",745000,7.2);
cout<<"Details of customers
are:"<<endl;
for(int i=0;i<10;i++)
{
cout<<"======================================="<<endl;
customer[i].display();
cout<<"======================================="<<endl;
}
customer[0].setBalance(102354);
customer[0].setInterest(9.9);
customer[0].display();
}