Question
It is C++, Inherit the BankAccount class in two other classes, SavingsAccount, WalletAccount. Make sure you Have all the following methods and data members stated
It is C++, Inherit the BankAccount class in two other classes, SavingsAccount, WalletAccount. Make sure you Have all the following methods and data members stated bellow in each class. Remember during developing, you should not be rewriting any part of the code. You should call the methods already existing in the father class as part of the new method
I already comment what need to do in code;
setdate
-------------BankAccount.h
#ifndef BANKACCOUNT_H #define BANKACCOUNT_H #include #include using namespace std; class BankAccount { public: BankAccount(); //Balance, InterestRate and LastInterestDate to 0 BankAccount(double balances, double interestRates);//Set balance and interestRate to given arguments // Set lastInterestDate to today void setBalance(double balances);//set balance to be equal to the given argument void deposit(double addition); //add the amount of the addition to the balance void withdraw(double deduction); //if the balance is enough, deduct the amount of argument form the balance // if the balance is not enough, show the message that indicated the issue void setInterestRate(double interestRates); //set the interestRate to be equal to the given argument void addInterest(); //if today lastInterestDate is more than 30 days, calculate the interest and add it the balance, also update the lastInterestDate to today double getBalance();// return the balance double getInterestRate(); // return the interestRate int getLastInterestDate(); // return the lastInterestDate void printInfo(); /* print information about the account Balance : $ Interest Rate : % Last Interest Date : */ protected: double balance = 0.0; double interestRate = 0.0; int lastInterestDate = 0; };
#endif
---------------------BankAccount.cpp
#include "BankAccount.h"
BankAccount::BankAccount() { balance = 0.0; interestRate = 0.0; lastInterestDate = 0; }
BankAccount::BankAccount(double balances, double interestRates) { balance = balances; interestRate = interestRates;
}
void BankAccount::setBalance(double balances) { balance = balances; }
void BankAccount::deposit(double addition) { balance += addition; }
void BankAccount::withdraw(double deduction) { if (deduction > balance) { cout
}
void BankAccount::setInterestRate(double interestRates) { interestRate = interestRates; }
double BankAccount::getBalance() { return balance; }
double BankAccount::getInterestRate() { return interestRate; }
int BankAccount::getLastInterestDate() { return lastInterestDate; }
void BankAccount::printInfo() { cout
#ifndef SAVINGSACCOUNT_H #define SAVINGSACCOUNT_H #include "BankAccount.h"
class SavingsAccount:public BankAccount { public: SavingsAccount(double bal, double rate, bool lock); //The same as BankAccount constructor, also update the lock data member void lockAccount(); // update the lock member to be true. Show a message that states the account is locked. void removeLock();// update the lock member to be false. Show a message that states the account is open. void setBalance(double bal); //if the account is not locked, set the balance;otherwise, show a message that states access is denied due to account being locked. void setInterestRate(double rate); // if the account is not locked, set the interest rate ,otherwise, show a message that states access is denied due to account being locked. void addInterest(); // if the account is not locked, add the interest ;otherwise, show a message that states access is denied due to account being locked. void deposit(double addition);// if the account is not locked, execute the deposit; otherwise, show a message that states access is denied due to account being locked. void withdraw(double deduction);// if the account is not locked, execute the withdrawal; otherwise, show a message that states access is denied due to account being locked. void printInfo();/* show all the account information balance : $ interest rate : % last interest date : lock : true or false */ private: bool lock = false; void accountLockMessage(); };
#endif
--------------------SavingAccount.cpp
---------------------WalletAccount.h
#ifndef WALLETACCOUNT_H #define WALLETACCOUNT_H #include "BankAccount.h" class WalletAccount:public BankAccount { public: WalletAccount(); //Should be the same as BankAccount. //Dont copy and paste code, use BankAccount constructor WalletAccount(double bal, double rate); //Should be the same as BankAccount. //Dont copy and paste code, use relative BankAccount constructor double getMaxWalletCapacity();//return maxWalletCapacity void deposit(double addition); /* if balance + addition doesnt exceed maxWalletCapacity, add the addition to the balance. Otherwise, show a message that stated the balance would exceed the wallet capacity */ void setBalance(double bal);//if bal doesnt exceed maxWalletCapacity, update the balance. Otherwise, show a me void printInfo();/* show all information about the account balance : $ interest rate : % last interest date : max wallet capacity : $ */ private: double maxWalletCapacity = 100; };
#endif --------------------------WalletAccount.cpp
#include "WalletAccount.h"
double WalletAccount::getMaxWalletCapacity() { return maxWalletCapacity; }
void WalletAccount::printInfo() { cout
//// main.cpp
#include"BankAccount.h" #include "SavingsAccount.h" #include "WalletAccount.h"
int main() { SavingsAccount saving(1000, 0.02, true); saving.printInfo(); saving.withdraw(200); saving.removeLock(); saving.withdraw(300); saving.withdraw(1000); saving.lockAccount(); saving.deposit(2000); saving.printInfo();
WalletAccount wallet(70.0, 0.02); wallet.printInfo(); wallet.deposit(50); wallet.printInfo();
}
use the following to save date as an int number #includeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started