#include <iostream>
#include <string>
using namespace std;
class Account
{
protected:
float balance;
int accountNumber;
string owner;
static int nextAccountNumber;
private:
void construct(float, string);
public:
Account(float, string);
Account(float);
Account();
virtual void display();
virtual bool makeWithdrawal(float &);
virtual void makeLodgement(float &);
}
int Account::nextAccountNumber = 12345;
class CurrentAccount: public Account
{
float overdraftLimit;
public:
CurrentAccount(float, string, float);
CurrentAccount(Account, float);
virtual void display();
virtual bool makeWithdrawal(float &);
};
Account::Account(float _balance, string _owner):balance(_balance),
owner(_owner){}
Account::Account(float _balance):balance(_balance){}
Account::Account(){}
void Account::construct(float _balance, string _owner){
accountNumber = nextAccountNumber++;
balance = _balance;
owner = _owner;
}
void Account::dislplay(){
cout<<"Account owned by " << owner << " , account number: "
<< accountNumber << " , balance : " << balance << endl;
}
bool Account::makeWithdrawal(float& amount){
if (balance > amount){
balance = balance - amount;
return true;}
else
return false;`
}
void Account::makeLodgement(float& amount){
balance = balance + amount;
}
CurrentAccount::CurrentAccount(float _balance, string _owner,
float _overdraftLimit):balance(_balance), owner(_owner), overdraftLimit
(_overdraftLimit){}
CurrentAccount::CurrentAccount(Account a, float _overdraftLimit):
Account(a), overdraftLimit(_overdraftLimit){}
void CurrentAccount::display(){
Account::display();
cout << "And overdraft limit: " << overdraftLimit << endl;}
bool CurrentAccount::makeWithdrawal(float &amt){
if (amt<=(balance+overdraftLimit)){
balance-=amt;
return true;}
else return false;
}
int main()
{
Account a(100.0f, "Derek Molloy");
CurrentAccount b(200.0f, "John Doe", 500.0f);
CurrentAccount c(a, 1000.0f);
a.display();
b.display();
c.display();
system("pause");
}
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE