Need help with inheretience lab for c++. Please and thank you. Please send corre
ID: 665241 • Letter: N
Question
Need help with inheretience lab for c++. Please and thank you. Please send correct code and output. This project will be done in seperate files .h and cpp files. These files with the input are provided below in dropbox. Please implement the files an fill out the missing parts.
https://www.dropbox.com/sh/36sxpfkktf7rawv/AABiPMaEmnPVSsVlR65Jr7S6a?dl=0
This week we will be working with different bank accounts. For this lab, we will have checking, savings, and certificate of deposit (or CD) accounts.
About the accounts
Checking accounts:
* Can withdrawal and deposit money normally
* Do not gain interest
Savings accounts:
* Can withdrawal and deposit normally
* Gain 1% interest if they have $100.00 – 999.99
* Gain 2% interest if they have $1000.00 or more
Certificate of Deposits (CDs):
* Can deposit normally
* Tracks if money has been withdrawn
* Gain 10% interest if they haven’t been withdrawn
* Gain 1% interest if they have been withdrawn from
Structure
The base class is pretty simple on it’s own. The Account class is provided. But other derived classes all need to inherit the methods and properties of the Account class.
Ex: having a Rectangle class inherit from a Shape class:
Class Rectangle : public Shape { … }
We will use an array of pointers to Accounts to store these. Depending on the type of account we need, we’ll insert a new account in that point of the array. This won’t normally work, but using polymorphism, and setting up our accounts to inherit from a base Account class, then any subclass we define will actually also be a type of the base class.
Ex: Creating a new checking account: Account *newAccount;
newAccount = new CheckingAccount(123);
Input
The input file consists of multiple lines of commands. These tell the program what to do.
If the line starts with NEW, then it creates a new account of the next word’s type (CHECKING, SAVINGS, or CERTIFICATE). Then it creates it with the account number provided after that.
If the line starts with DEPOSIT, then it deposits into the account (listed next) the amount (listed after that).
If the line starts with WITHDRAWAL, then it withdraws from the account (listed next) the amount (listed after that).
If the line starts with INTEREST, we apply interest to all of the accounts. (Telling a checking account to gain interest will run, but it doesn’t do anything.)
If the line starts with TRANSFER, transfer from the first account number to the second account number the amount listed after that.
See the provided input.txt to see how the file looks.
Output
Print out the line “BANK STATEMENT” with an extra empty line. Then print out the account number, type, and balance in this format:
Account number: 101
Type of account: Checking
Balance: $40
Leave a blank line between each account.
Explanation / Answer
//Account.h
#include <string>
using namespace std;
// Prevent multiple includes of this class
#ifndef ACCOUNT_H
#define ACCOUNT_H
class Account
{
protected:
// The identifying number of the account
int accountNum;
// The total amount of money stored in the account
double balance;
// The type of account
string type;
public:
// Default constructor
Account();
// Returns the account number
int getAccountNum();
// Returns the account type
string getAccountType();
// Returns the amount of money stored
double getBalance();
// Applies an interest rate to the balance
virtual void accrueInterest() = 0;
// Adds money to the bank account
virtual void deposit(double amount);
// Removes money from the bank account
virtual void withdrawal(double amount);
};
#endif ACCOUNT_H
--------------------------------------------------------------------------------
//Account.cpp
#include "Account.h"
Account::Account()
{
balance = 0.0;
}
int Account::getAccountNum()
{
return accountNum;
}
string Account::getAccountType()
{
return type;
}
double Account::getBalance()
{
return balance;
}
void Account::deposit(double amount)
{
balance += amount;
}
void Account::withdrawal(double amount)
{
balance -= amount;
}
-----------------------------------------------------------------------------------------------
//SavingsAccount.h
#include "Account.h"
// Prevent multiple includes of this class
#ifndef SAVINGSACCOUNT_H
#define SAVINGSACCOUNT_H
class SavingsAccount :public Account
{
public:
// Constructor
SavingsAccount(int newAccountNum);
// Applies an interest rate to the balance
void accrueInterest();
};
#endif SAVINGSACCOUNT_H
-----------------------------------------------------------------------------------------------
//SavingsAccount.cpp
#include <iostream>
#include"Account.h"
#include"SavingsAccount.h"
using namespace std;
// Constructor
SavingsAccount::SavingsAccount(int newAccountNum)
{
accountNum = newAccountNum;
type = "Savings";
}
// Applies an interest rate to the balance
void SavingsAccount::accrueInterest()
{
if (balance >= 100.00 && balance < 1000.00)
balance =balance+balance*(0.01);
else if (balance >= 1000.00)
balance =balance+balance*(0.02);
}
-----------------------------------------------------------------------------------------------
//CheckingAccount.h
#include "Account.h"
// Prevent multiple includes of this class
#ifndef CHECKINGACCOUNT_H
#define CHECKINGACCOUNT_H
class CheckingAccount :public Account
{
public:
// Constructor
CheckingAccount(int newAccountNum);
// Adds money to the bank account
void deposit(double amount);
// Removes money from the bank account
void withdrawal(double amount);
// Applies an interest rate to the balance
void accrueInterest();
};
#endif CHECKINGACCOUNT_H
-----------------------------------------------------------------------------------------------
//CheckingAccount.cpp
#include "Account.h"
#include "CheckingAccount.h"
// Constructor
CheckingAccount::CheckingAccount(int newAccountNum)
{
accountNum=newAccountNum;
type = "CheckingAccount";
}
void CheckingAccount::deposit(double amount)
{
balance += amount;
}
void CheckingAccount::withdrawal(double amount)
{
balance -= amount;
}
// Applies an interest rate to the balance
void CheckingAccount::accrueInterest()
{
}
-----------------------------------------------------------------------------------------------
// Your Name
// Today's date
// Lab 6
#include "Account.h"
// Prevent multiple includes of this class
#ifndef CERTIFICATEOFDEPOSIT_H
#define CERTIFICATEOFDEPOSIT_H
class CertificateOfDeposit :public Account
{
private:
bool hasWithdrawn;
public:
// Constructor
CertificateOfDeposit(int newAccountNum, bool withdrawn);
// Applies an interest rate to the balance
void accrueInterest();
// Removes money from the bank account
void withdrawal(float amount);
};
#endif CERTIFICATEOFDEPOSIT_H
-----------------------------------------------------------------------------------------------
// Your Name
// Today's date
// Lab 6
#include "Account.h"
#include "CertificateOfDeposit.h"
// Constructor
CertificateOfDeposit::CertificateOfDeposit(int newAccountNum,bool withdrawn)
{
accountNum=newAccountNum;
type = "CertificateAccount";
hasWithdrawn=withdrawn;
}
// Applies an interest rate to the balance based on the boolean value hasWithdrawn.
//If not withdrawn then 10 % percent otherwise 1% percent
void CertificateOfDeposit::accrueInterest()
{
if(hasWithdrawn==false)
balance =balance+balance*(0.10);
else if (hasWithdrawn==true)
balance =balance+balance*(0.01);
}
-----------------------------------------------------------------------------------------------
// Driver program
//main.cpp
#include<iostream>
#include "Account.h"
#include "CertificateOfDeposit.h"
#include "CheckingAccount.h"
#include "SavingsAccount.h"
#include <fstream>
#include <string>
#include <stdlib.h>
using namespace std;
int main()
{
srand(time_t(0));
// File I/O
ifstream fin("input.txt");
ofstream fout("output.txt");
// Stores up to 30 accounts
Account* accounts[30];
// Number of accounts that have been opened
int numAccounts = 0;
// For file input processing
string command;
string acctType;
int acctNum1, acctNum2;
double amount;
// Do the input and math
while(fin >> command)
{
if(command == "NEW")
{
// Create a new account
fin>>acctType;
fin>>acctNum1;
if(acctType=="CHECKING")
{
accounts[numAccounts]=new CheckingAccount(acctNum1);
}
else if(acctType=="SAVINGS")
{
accounts[numAccounts]=new SavingsAccount(acctNum1);
}
else if(acctType=="CERTIFICATE")
{
//generate a random value 0,1
int value=rand()%2;
//If value is zero , then set withdrawl is false otherwiser set withdrawl is true
if(value==0)
accounts[numAccounts]=new CertificateOfDeposit(acctNum1,false);
else if(value==1)
accounts[numAccounts]=new CertificateOfDeposit(acctNum1,true);
}
numAccounts++;
}
else if (command == "WITHDRAWAL")
{
// Remove money from an account
fin>>acctNum2;
fin>>amount;
bool found=false;
for(int index=0;index<numAccounts && !found;index++)
{
if(accounts[index]->getAccountNum()==acctNum2)
{
found=true;
accounts[index]->withdrawal(amount);
}
}
}
else if (command == "DEPOSIT")
{
// Add money to an account
fin>>acctNum2;
fin>>amount;
bool found=false;
for(int index=0;index<numAccounts && !found;index++)
{
if(accounts[index]->getAccountNum()==acctNum2)
{
found=true;
accounts[index]->deposit(amount);
}
}
}
else if (command == "TRANSFER")
{
// Move money from one account to another
fin>>acctNum1;
fin>>acctNum2;
fin>>amount;
bool found=false;
//first withdrawl the amount from first account
for(int index=0;index<numAccounts && !found;index++)
{
if(accounts[index]->getAccountNum()==acctNum1)
{
found=true;
//calll the method withdraw before ransfer the amont from the sender
accounts[index]->withdrawal(amount);
}
}
found=false;
//Then deposit the amount to second account number
for(int index=0;index<numAccounts && !found;index++)
{
if(accounts[index]->getAccountNum()==acctNum2)
{
found=true;
//calll the method deposit to transfer the amount to receiver
accounts[index]->deposit(amount);
}
}
}
else if (command == "INTEREST")
{
for(int index=0;index<numAccounts;index++)
{
//calling the method to calculate the interest on the balance in the account
accounts[index]->accrueInterest();
}
}
}
// Print output
fout << "BANK STATEMENT" << endl << endl;
for(int i = 0; i < numAccounts; i++)
{
fout << "Account number: " << accounts[i]->getAccountNum() << endl;
fout << "Type of account: " << accounts[i]->getAccountType() << endl;
fout << "Balance: $" << accounts[i]->getBalance() << endl;
fout << endl;
}
// Delete accounts
for (int i = 0; i < numAccounts; i++)
delete accounts[i];
// Close files
fin.close();
fout.close();
return 0;
}
-----------------------------------------------------------------------------------------------
input text file:
input.txt
NEW CHECKING 101
NEW SAVINGS 102
NEW CERTIFICATE 103
DEPOSIT 101 75.00
DEPOSIT 102 25.00
DEPOSIT 103 100.00
DEPOSIT 101 10.00
WITHDRAWAL 101 15.00
WITHDRAWAL 102 10.00
TRANSFER 103 101 25.00
NEW CERTIFICATE 104
DEPOSIT 104 500.00
INTEREST
DEPOSIT 102 50.00
NEW CHECKING 105
DEPOSIT 100 100.00
WITHDRAWAL 101 5.00
WITHDRAWAL 101 5.00
DEPOSIT 101 5.00
WITHDRAWAL 101 5.00
INTEREST
DEPOSIT 105 43.00
DEPOSIT 104 31.00
WITHDRAWAL 102 9.00
NEW CERTIFICATE 106
DEPOSIT 106 100.00
DEPOSIT 106 4.00
INTEREST
NEW SAVINGS 107
DEPOSIT 107 195.00
NEW SAVINGS 108
DEPOSIT 108 199.00
WITHDRAWAL 101 45.00
DEPOSIT 107 50.00
WITHDRAWAL 108 91.00
DEPOSIT 106 182.00
INTEREST
----------------------------------------------------------------------------------------------------------------
Sample output file:
BANK STATEMENT
Account number: 101
Type of account: CheckingAccount
Balance: $40
Account number: 102
Type of account: Savings
Balance: $56
Account number: 103
Type of account: CertificateAccount
Balance: $109.808
Account number: 104
Type of account: CertificateAccount
Balance: $551.925
Account number: 105
Type of account: CheckingAccount
Balance: $43
Account number: 106
Type of account: CertificateAccount
Balance: $326.04
Account number: 107
Type of account: Savings
Balance: $247.45
Account number: 108
Type of account: Savings
Balance: $109.08
Hope this helps you