Using C++ as language (if you have Visual Studio 2013/5/7 please use that to avo
ID: 3722900 • Letter: U
Question
Using C++ as language (if you have Visual Studio 2013/5/7 please use that to avoid of unknown stupid question when I may run
file available here: https://drive.google.com/open?id=1UHmjwWgN9cBGkWtDXQw3X2O3gAxQ99ci
OVERVIEW This activity is designed to have you work with an abstract virtual base class, and a set of derived classes INSTRUCTIONS In this program you will create a set of unique but similar banking account classes that are designed to model the accounts at a bank. Each of the classes will be based upon a generic/abstract base class, and then you will implement the commands necessary to keep track of them. THE MAIN PROGRAM Your main program will be provided for you. It will be designed to work in sections. The first section will read data from a file and create the accounts as necessary. The second section will allow the user to make changes to the accounts via data entry. THE BANKACCOUNT CLASS The BankAccount class will be the generic starting point for all your future classes. In it you will hold the following information . Balance Number of deposits made so far. Number of withdrawals made so far. Annual Percentage rate. An Account ID String · In addition, you will want the following functions, note that some of these may be virtual, and you may need to create some others as necessary. (cough constructors cough)Explanation / Answer
account.h
class Account {
public:
Account(double newBalance); //constructor
//methods
virtual double deposit(double amount) = 0; //not sure about this
virtual double withdrawal(double amount) = 0;
virtual double transferFrom(char accountTrans, double moneyTrans) = 0;
protected:
//gets and sets
virtual double getBalance() const;
virtual void setBalance(double newBalance) = 0;
private:
double balance;
};
account.cpp
#include <stdlib.h>
#include <iostream>
#include "account.h"
using namespace std;
//----------------------------------------------------------------------------------------------------
Account::Account(double newBalance)
{
if (newBalance > 0)
{
balance = newBalance;
}
else
{
cerr << "Illegal Balance" << endl << endl;
}
}
//----------------------------------------------------------------------------------------------------
double Account::getBalance() const
{
return balance;
}
//----------------------------------------------------------------------------------------------------
void Account::setBalance(double newBalance)
{
if (newBalance > 0)
{
balance = newBalance;
}
else
{
cerr << "Illegal Balance" << endl << endl;
}
}
//----------------------------------------------------------------------------------------------------
double Account::deposit(double amount)
{
if (amount >= 0)
{
balance = balance + amount;
}
else
{
cerr << "Illegal deposit" << endl << endl;
}
return balance;
}
//----------------------------------------------------------------------------------------------------
double Account::withdrawal(double amount)
{
if (amount > 0)
{
balance = balance - amount;
}
else
{
cerr << "Illegal withdrawal" << endl << endl;
}
return balance;
}
//----------------------------------------------------------------------------------------------------
double Account::transferFrom(char* accountTrans, double moneyTrans)
{
accountTrans->balance = accountTrans->balance - moneyTrans;
this->balance = this->balance + moneyTrans;
return balance;
}
savings.h
#include "account.h"
class Savings: public Account {
public:
Savings(double newBalance, double newInterestRate);
double withdrawal(double amount);
double deposit(double amount);
protected:
double getRate() const;
double setRate();
private:
double interestRate;
};
savings.cpp
#include <iostream>
#include <stdlib.h>
#include "savings.h"
//--------------------------------------------------------------------------------------
Savings::Savings(double balance, double interestRate) : Account(balance)
{
Account::setBalance(balance);
setRate(interestRate);
}
//--------------------------------------------------------------------------------------
void Savings::setRate(double interest)
{
interestRate = interest;
interestRate = (interestRate/100)/12; // to get interest in monthly format
}
//--------------------------------------------------------------------------------------
double Savings::getRate() const
{
return interestRate;
}
//--------------------------------------------------------------------------------------
double Savings::withdrawal(double amount)
{
if ( (Account::getBalance() - amount) >= 0)
{
Account::withdrawal(amount);
Account::setBalance(Account::getBalance() + ( interestRate * Account::getBalance() ) );
}
else
{
cerr << "Not enough funds in savings for transaction" << endl << endl;
}
}
//--------------------------------------------------------------------------------------
double Savings::deposit(double amount)
{
Account::deposit(amount);
Account::setBalance(Account::getBalance() + ( interestRate * Account::getBalance() ) );
}
checking.h
#include "account.h"
class Checking: public Account {
public:
Checking(double newBalance);
double withdrawal(double);
double deposit(double);
};
checking.cpp
#include "checking.h"
Checking::Checking(double newBalance): Account(balance)
{
Account::setBalance(balance);
}
double Checking::withdrawal(double amount)
{
if ( Account::getBalance() - amount >= 0)
{
Account::withdrawal(amount);
}
else
{
cout << "Not enough funds in checking for transaction" << endl << endl;
}
}
double Checking::deposit(double amount)
{
Account::deposit(amount);
}
main.cpp
#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <string>
#include "checking.h"
#include "savings.h"
#include "moneymarket.h"
#include "certificatedeposit.h"
using namespace std;
void main
{
//declare all 4 types, call withdrawl, deposit,
//and transfer from on each account
Checking Brad (200);
Savings Brad (100);
Checking sweety (10000);
Savings sweety (10);
cout << "Brad's Checking balance: " << Brad->Checking::getBalance() << endl << endl;
cout << "Brad's Saving balance: " << Brad->Saving::getBalance() << endl << endl;
cout << "sweety's Checking balance: " << sweety->Checking::getBalance() << endl << endl;
cout << "sweety's Savings balance: " << sweety->Savings::getBalance() << endl << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.