Question
C++ , try to use simple code for beginner of pointer please here is a code: BankAccount.h #includeBankAccount.h #include SavingsAccount.h #include WalletAccount.h int main() {
C++ , try to use simple code for beginner of pointer please
here is a code:
BankAccount.h
#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();
system("pause"); return 0; }
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; }
void BankAccount::addInterest() { time_t t = time(NULL); struct tm now; localtime_s(&now, &t); int todays = (now.tm_year + 1990) * 10000 + (now.tm_mon + 1) * 100 + (now.tm_mday); if ((todays - lastInterestDate) > 30) { balance = balance + balance * interestRate; lastInterestDate = todays; } }
double BankAccount::getBalance() { return balance; }
double BankAccount::getInterestRate() { return interestRate; }
int BankAccount::getLastInterestDate() { return lastInterestDate; }
void BankAccount::printInfo() { time_t t = time(NULL); struct tm now; localtime_s(&now, &t); int year = (now.tm_year + 1900); int month = (now.tm_mon + 1); int day = (now.tm_mday); std::string ax = to_string(month) + "/" + to_string(day) + "/" + to_string(year); today = ax; cout
SavingsAccount.h
#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
#include "SavingsAccount.h"
SavingsAccount::SavingsAccount(double bal, double rate, bool lock):BankAccount(bal,rate) { BankAccount::BankAccount(bal,rate); lock = lock; }
void SavingsAccount::lockAccount() {
lock = true;
accountLockMessage(); }
void SavingsAccount::removeLock() {
lock = false;
accountLockMessage(); }
void SavingsAccount::setBalance(double bal) {
if (lock == false)
balance = bal;
else
cout
void SavingsAccount::setInterestRate(double rate) {
if (lock == false)
interestRate = rate;
else
cout
void SavingsAccount::addInterest() { if (lock == false)
BankAccount::addInterest();
else
cout
void SavingsAccount::deposit(double addition) { if (lock == false)
BankAccount::deposit(addition);
else
cout
void SavingsAccount::withdraw(double deduction) { if (lock == false)
BankAccount::withdraw(deduction);
else
cout
void SavingsAccount::printInfo() {
BankAccount::printInfo();
}
void SavingsAccount::accountLockMessage() { if (lock)
cout
else
cout
}
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 balances, double interestRates); //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"
WalletAccount::WalletAccount():BankAccount() { }
WalletAccount::WalletAccount(double balances, double interestRates):BankAccount(balances,interestRates) { }
double WalletAccount::getMaxWalletCapacity() { return maxWalletCapacity; }
void WalletAccount::deposit(double addition) { double total = balance + addition; if (total > maxWalletCapacity) { cout
void WalletAccount::setBalance(double bal) { if (bal > maxWalletCapacity) cout
void WalletAccount::printInfo() { BankAccount::printInfo(); cout
Make necessary modifications in BankAccount class, in a way it can keep track of the number of accounts that has been created Hint: initialize accountCount to O Increment it in both constructors Decrement it in destructor Write a new main function Create a pointer for class SavingsAccount and initialize it Create a pointer for class WalletAccount and initialize it Hint: use static method defined in BankAccount Ask user if he wants to open an account If no show a message o If yes Ask if he wants to open a savings account If yes ask for balance create a new SavingsAccount object assign it to savings pointer Ask if he wants to open a wallet account " If yes Ask for balance Create a new WalletAccount object Assign it to wallet pointer Print the current number of accounts Possible output: . Run the code three time. Try the same inputs provided in sample outputs . Get a screenshot of each results . Save all your files in a folder Make a zip and submit it through canvas. Current number of accounts is: 0 Do you want to open an account? (y)n Maybe some other time! Current number of accounts is: 0 Press any key to continue .. . urrent number of accounts is: 0 o you want to open an account? (y)y o you want to open a savings account with 2% int reast rate? (y)y hat is your initial balance? 10e you want to open a wallet account with 2% int reast rate and $10 maximim capacity? (y)n urrent number of accounts is: 1 ress any key to continue .. . _ urrent number of accounts is: 0 o you want to open an account? (y)y Do you want to open a savings account with 2% intreast rate? (y)y hat is your initial balance? 186 o you want to open a wallet account with 2% intreast rate and $100 maximim capacity? (y)y hat is your initial balance? 36e urrent number of accounts is: 2 press any key to continue
Step 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