In: Computer Science
In c++, define a class with the name BankAccount and the following members:
Data Members:
Member Functions
Code
#include<iostream>
using namespace std;
class BankAccount
{
private:
double accountBalance;
double interestRate;
int accountId;
public:
static int count;
BankAccount(double,double);
void withdraw(double);
void deposit(double);
void calculateMonthlyInterest();
void displayAccountInfo();
};
int BankAccount::count=0;
BankAccount::BankAccount(double balance,double rate)
{
accountBalance=balance;
interestRate=rate;
accountId=101+count;
count++;
}
void BankAccount::withdraw(double amount)
{
if(amount>accountBalance)
{
cout<<"Insufficient
balance."<<endl;
return;
}
else
{
accountBalance-=amount;
}
}
void BankAccount::deposit(double amount)
{
accountBalance+=amount;
}
void BankAccount::calculateMonthlyInterest()
{
accountBalance+=accountBalance*(interestRate/100);
}
void BankAccount::displayAccountInfo()
{
cout<<"Account ID:
"<<accountId<<endl;
cout<<"Account Balance:
$"<<accountBalance<<endl;
cout<<"Intrest Rate:
"<<interestRate<<"%"<<endl;
cout<<"Number of account created:
"<<count<<endl<<endl;
}
int main()
{
BankAccount ba1(1000,4.5);
BankAccount ba2(2000,6.5);
cout<<"Initially account is
"<<endl;
ba1.displayAccountInfo();
ba2.displayAccountInfo();
ba1.deposit(200);
ba2.deposit(500);
cout<<"\nAfter deposite account
is"<<endl;
ba1.displayAccountInfo();
ba2.displayAccountInfo();
}
output
If you have any query regarding the code please ask me in the
comment i am here for help you. Please do not direct thumbs down
just ask if you have any query. And if you like my work then please
appreciates with up vote. Thank You.