Develop a new class called
LoanAccount, based on
BankAccount( from Lab 10). This class has an overdraft facility, so that the user can withdraw money up to the overdraft limit. The class must store an overdraft limit for the account. It must also store the current interest rate, but this is the same for all accounts (it is not part of any one account).
The constructor will require a name and account number to be specified, and will invoke the constructor of the
BankAccount
class and also set the overdraft limit to 0. Also, the
withdraw
method from
BankAccount
will have to be overridden in this class, so that a negative balance is permitted. You will need to add a
protected
setBalance
method to
BankAccount
, that changes the balance without checking it, since
BankAccount
does not normally allow negative balances.
The public interface must also include the following additional methods:
1. set/get the interest rate
2. set/get the overdraft limit
3. calculate projected interest (0 if the balance is positive, otherwise multiply current balance by current interest rate)
#include
#include
using namespace std;
class BankAccount
{
private:
string accountName;
int accountNumber;
double accountBalance;
public:
BankAccount(string name, int myAcc);
void deposit(double myDep);
void withdraw(double amt);
void display();
~BankAccount();//destructor
};//end of class definition
//Defining methods
BankAccount::BankAccount(string name, int myAcc)
{
accountName = name;
accountNumber = myAcc;
accountBalance = 0.0;
}//constructor
void BankAccount::deposit(double myDep)
{
accountBalance += myDep;
}//deposit
void BankAccount::withdraw(double amt)
{
if(amt
accountBalance -=amt;
}
void BankAccount::display()
{
cout
}
BankAccount::~BankAccount()
{
cout
}//BankAccount
/////////MAIN//////
int main()
{
string acct1Name="";
string acct2Name = "";
double deposit1 =0.0;
double deposit2 = 0.0;
double withdrawal =0.0;
int acctNo1 =0;
int acctNo2 = 0;
cout
cin>>acct1Name;
cout
cin>>acctNo1;
//create the second object
BankAccount account1(acct1Name,acctNo1);
cout
cin>>acct2Name;
cout
cin>>acctNo2;
//create the first object
BankAccount account2(acct2Name,acctNo2);
//deposit money into both
cout
cin>>deposit1;
account1.deposit(deposit1);
account1.display();
cout
cin>>deposit2;
account2.deposit(deposit2);
account2.display();
///withdraw from both accounts
cout
cin>>withdrawal;
account1.withdraw(withdrawal);
account1.display();
cout
cin>>withdrawal;
account2.withdraw(withdrawal);
account2.display();
return 0;
}