Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This homework assignment gives you the opportunity to practice inheritance. It b

ID: 3815612 • Letter: T

Question

This homework assignment gives you the opportunity to practice inheritance. It builds upon HW4-3. You have the option to submit the basic version (you can earn up to 100 points out of 100) or the extra credit version (you can earn up to 120 points out of 100). Please state clearly in the comments header of main.cpp which version you submit. HW4-4-Basic Version Your program should implement the following: 1. Account class Mccount has the following member variables: private: account Number of type int owner Name of type string numberAccounts of type static int initialized to zero protected: balance of type double totalNetDeposits of type static double totalNetDeposits is the cumulative sum of all deposits (at account creation and at deposits) minus the cumulative sum of all withdrawals and the following member functions: public: Account (number, name, amount) is the constructor that initializes the account's member variables with number, name and amount. amount is the amount deposited when the account is created. The amount is added to totalNetDeposits. numberAccounts is incremented withdraw (amount) function to withdrawaspecified amount from the account. The function should first check if there is sufficient balance in the account. If the balance is sufficient, withdrawal is processed. Otherwise the withdrawal is not made. If the withdrawal is made, the withdrawal amount is deducted from balance and from total NetDeposits. deposit (amount) function to deposit a specified amount of money to the account. The function should first check if the deposit amount is positive. If it is positive, deposit is processed. Otherwise the deposit is not made. Ifthe deposit is made, the amount is added to balance and to totalNetDeposits. get Account Number An accessor function that returns the account number. get Balance An accessor function that returns the account balance

Explanation / Answer

/***************** Account.h **************/

#include <iostream>

using namespace std;

class Account
{
private:
int accountNumber;
string ownerName;
static int numberAccounts=0;

protected:
double balance;
static double totalNetDeposits;

public:

Account(int number, string name, double amount)
{
accountNumber = number;
ownerName = name;
balance = amount;
totalNetDeposits = balance;
numberAccounts += 1;
}

bool withdraw(double amount)
{
if(amount <= balance)
{
balance -= amount;
totalNetDeposits -= amount;
return true;
}else
{
return false;
}
}

bool deposit(double amount)
{
if(amount > 0)
{
balance += amount;
totalNetDeposits += amount;
return true;
}else{
return false;
}
}

int getAccountNumber()
{
return accountNumber;
}

double getBalance()
{
return balance;
}

static double getTotalNetDeposits()
{
return totalNetDeposits;
}

static int getNumberAccounts()
{
return numberAccounts;
}

void print()
{
cout<<"Account Number: "<<accountNumber;
cout<<"Owner Name: "<<ownerName;
cout<<"Balance: "<<balance;
}
};

/********* RegularAccount.h ************/

#include 'Account.h';
class RegularAccount : public Account
{
static int numberRegularAccounts;

public:

RegularAccount(int number, string name, double amount)
: Account(number, name, amount)
{
numberRegularAccounts += 1;
}

static int getNumberRegularAccounts()
{
return this.numberRegularAccounts;
}
};

RegularAccount::numberRegularAccounts = 0;


/********** PremiumAccount.h **************/

#include 'Account.h';

class PremiumAccount : public Account
{
static int numberPremiumAccounts = 0;
static double MIN_BALANCE = 1000;

public :

PremiumAccount(int number, string name, double amount)
: Account(number, name, amount)
{
numberPremiumAccounts += 1;
}

static int getNumberPremiumAccounts()
{
return numberPremiumAccounts;
}

bool withdraw(double amount)
{

if( (amount + MIN_BALANCE) <= balance)
{
balance -= amount;
totalNetDeposits -= amount;
return true;
}else
{
return false;
}
}

double getMinBalance()
{
return MIN_BALANCE;
}
};

/*********** main *************/

#include <iostream>
#include <stdio.h>
#include <Account.h>
#include <RegularAccount.h>
#include <PremiumAccount.h>

int main()
{

const int NUM_REGULAR_ACCOUNT = 5;
const int NUM_PREMIUM_ACCOUNT = 5;

RegularAccount * regularAccountArray[NUM_REGULAR_ACCOUNT];
PremiumAccount * premiumAccountArray[NUM_PREMIUM_ACCOUNT];

int i =0;
while(true)
{

int temp;
cout<<"1. Create regular account"<<endl;
cout<<"2. Create preimum account"<<endl;
cout<<"3. Deposit to regular account"<<endl;
cout<<"4. Deposit to preimum account"<<endl;
cout<<"5. Withdraw from regular account"<<endl;
cout<<"6. Withdraw from preimum account"<<endl;
cout<<"7. Display information for all accounts."<<endl;
cout<<"8. Get totalNetDeposits";
cout<<"9. Exit the program";

cin>>temp;
if(temp == 9)
{
return false;
}else{

int number, name;
double amount;
if(temp == 1)
{
cout<<"Enter Account Number, Name & Amount";
cin>>number>>name>>amount;

int j =0;
while(j <= 4)
{
if (number == regularAccountArray[j]->getAccountNumber())
{
return false;
}
}

regularAccountArray[i] = new RegularAccount(number, name, amount);
}

if(temp == 2)
{
cout<<"Enter Account Number, Name & Amount";
cin>>number>>name>>amount;

int j =0;
while(j <= 4)
{
if (number == premiumAccountArray[j]->getAccountNumber())
{
return false;
}
}

if(amount < MIN_BALANCE)
{
cout<<"Cannot create premium account with balance less than MIN BALANCE";
return false;
}

premiumAccountArray[i] = new PremiumAccount(number, name, amount);
}

if(temp == 3)
{
cout<<"Enter account number to deposit to: ";
cin>>number;

int j = 0;
while(j <= 4)
{
if (number == regularAccountArray[j]->getAccountNumber())
{
cout<<"Enter amount to deposit";
double deposit;
cin>>deposit;
  
if(deposit <= 0)
{
cout<<"Couldn't deposit";
return false;
}

if(regularAccountArray[i]->deposit(amount)){
cout<<"Deposited. /n";
}else{
cout<<"Couldn't Deposit";
}
}
}
}


if(temp == 4)
{
cout<<"Enter account number to deposit to: ";
cin>>number;

int j = 0;
while(j <= 4)
{
if (number == premiumAccountArray[i]->getAccountNumber())
{
cout<<"Enter amount to deposit";
double deposit;
cin>>deposit;
if(deposit <= 0)
{
cout<<"Couldn't deposit";
return false;
}

if(premiumAccountArray[i]->deposit(amount)){
cout<<"Deposited. /n";
}else{
cout<<"Couldn't Deposit";
}
}
}
}


if(temp == 5)
{
cout<<"Enter account number to withdraw from: ";
cin>>number;
  
int j=0;
while(j <= 4)
{
if(number == regularAccountArray[j]->getAccountNumber())
{
cout<<"Enter amount: ";
cin>>amount;
if(regularAccountArray[i]->withdraw(amount))
{
}else{
cout<<"Couldn't withdraw";
}
}
}

}


if(temp == 6)
{
cout<<"Enter account number to withdraw from: ";
cin>>number;
  
int j=0;
while(j <= 4)
{
if(number == premiumAccountArray[j]->getAccountNumber())
{
cout<<"Enter amount: ";
cin>>amount;
if(premiumAccountArray[i]->withdraw(amount))
{
}else{
cout<<"Couldn't withdraw";
}
}
}
}


if(temp == 7)
{
int j =0 ;
while(j <= 4)
{
cout<<premiumAccountArray[j]->print();
cout<<regularAccountArray[j]->print();
}
}

if(temp == 8)
{
int j = 0;
double temp;
while(j <= 4)
{
temp += premiumAccountArray[j]->getTotalNetDeposits();
temp += regularAccountArray[j]->getTotalNetDeposits();
}

cout<<"Total Net Deposit: "<<temp;
}

}

i++;
}

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote