account.h using namespace std; class Account{ protected: double balance; public: Account(double x){ balance = x;} virtual double getBalance(); virtual double debit(double x); virtual double credit(double x);};
account.cpp
#include<iostream>
#include"account.h" using namespace std; double Account:: debit(double x){ if(x>balance){ cout << "Debit amount exceeded account balance." << endl;} else{balance = balance - x;} return balance;} double Account:: credit(double x){ balance = balance + x; return balance;} double Account::getBalance(){ return balance;};
savingaccount.h using namespace std; class SavingAccount : public Account { private: double interest; public: SavingAccount(double x,double y); double calculateInterenst(double x);};
Savingaccount.cpp
#include<iostream>
#include"account.h"
#include"savingaccount.h"
using namespace std;
SavingAccount::SavingAccount(double x, double y): Account(x){ balance =x ; interest =y;} double SavingAccount::calculateInterenst(double x){ x = balance * interest; return x;}
Checkingaccount.h using namespace std; class CheckingAccount : public Account{ private: double fee; public: CheckingAccount(double x, double y); virtual double debit(double x); virtual double credit(double x);};
Checkingaccount.cpp
#include<iostream>
#include"account.h"
#include"checkingaccount.h" using namespace std;
CheckingAccount :: CheckingAccount(double x, double y): Account(x){ balance =x ; fee =y;} double CheckingAccount :: debit(double x){ if(x>balance){cout << "Debit amount exceeded account balance." << endl;} else{ balance = balance - x; cout << "$" << fee << " transaction fee charged." << endl; balance = balance - fee; return balance;}} double CheckingAccount :: credit(double x){ balance = balance + x;