Question

In: Computer Science

please recode this in c++ language public abstract class BankAccount { double balance; int numOfDeposits; int...

please recode this in c++ language

public abstract class BankAccount
{
double balance;
int numOfDeposits;
int numOfWithdraws;
double interestRate;
double annualInterest;
double monSCharges;
double amount;
double monInterest;

//constructor accepts arguments for balance and annual interest rate
public BankAccount(double bal, double intrRate)
{
balance = bal;
annualInterest = intrRate;
}

//sets amount
public void setAmount(double myAmount)
{
amount = myAmount;
}

//method to add to balance and increment number of deposits
public void deposit(double amountIn)
{
balance = balance + amountIn;
numOfDeposits++;
}

//method to negate from balance and increment number of withdrawals
public void withdraw(double amount)
{
balance = balance - amount;
numOfWithdraws++;
}

//updates balance by calculating monthly interest earned
public double calcInterest()
{
double monRate;

monRate= interestRate / 12;
monInterest = balance * monRate;
balance = balance + monInterest;
return balance;
}

//subtracts services charges calls calcInterest method sets number of withdrawals and deposits
//and service charges to 0
public void monthlyProcess()
{
calcInterest();
numOfWithdraws = 0;
numOfDeposits = 0;
monSCharges = 0;
}

//returns balance
public double getBalance()
{
return balance;
}

//returns deposits
public double getDeposits()
{
return numOfDeposits;
}

//returns withdrawals
public double getWithdraws()
{
return numOfWithdraws;
}
}
and the subclass

public class SavingsAccount extends BankAccount
{
//sends balance and interest rate to BankAccount constructor
public SavingsAccount(double b, double i)
{
super(b, i);
}

//determines if account is active or inactive based on a min acount balance of $25
public boolean isActive()
{
if (balance >= 25)
return true;
return false;
}

//checks if account is active, if it is it uses the superclass version of the method
public void withdraw()
{
if(isActive() == true)
{
super.withdraw(amount);
}
}

//checks if account is active, if it is it uses the superclass version of deposit method
public void deposit()
{
if(isActive() == true)
{
super.deposit(amount);
}
}

//checks number of withdrawals adds service charge
public void monthlyProcess()
{
if(numOfWithdraws > 4)
monSCharges++;
}
}

INSTRUCTIONS WERE:
Build a retirement calculator program using classes ( have sets and gets for classes ) including unit tests for the classes.

Create a class for BankSavings Account -

fixed interest rate ( annual rate ) ( this should be set via a function call )

add money

withdraw money


Class for MoneyInYourPocket

add money

withdraw money


Class for MarketMoney ( investment )

rate of return is a variable 4% +- 6% randomly each time we 'apply it' ( don't need to unit test this for now, wait till next week )

add money

withdraw money ( every time you withdraw money, you get charged a $10 fee )


Build the retirement simulator.

Ask the user how old they are, and what age they want to retire.

For each asset type, get a current balance.

for every year until they retire ( loops ),

apply the return on investment or interest rate.

print the current balance in each type

ask for additional savings or withdrawals ( for each account type )

Once you reach the retirement age, display the balances of each type.

Also, generate a grand total, and adjust it for inflation ( fixed 2% per year )

total / ( 1.02 ^ years )

question has been answered before, so dont know how it doesnt have "enough inputs"

Solutions

Expert Solution

class BankAccount
{
public:
double balance = 0;
int numOfDeposits = 0;
int numOfWithdraws = 0;
double interestRate = 0;
double annualInterest = 0;
double monSCharges = 0;
double amount = 0;
double monInterest = 0;

//constructor accepts arguments for balance and annual interest rate
BankAccount(double bal, double intrRate);

//sets amount
virtual void setAmount(double myAmount);

//method to add to balance and increment number of deposits
virtual void deposit(double amountIn);

//method to negate from balance and increment number of withdrawals
virtual void withdraw(double amount);

//updates balance by calculating monthly interest earned
virtual double calcInterest();

//subtracts services charges calls calcInterest method sets number of withdrawals and deposits
//and service charges to 0
virtual void monthlyProcess();

//returns balance
virtual double getBalance();

//returns deposits
virtual double getDeposits();

//returns withdrawals
virtual double getWithdraws();
};
and_Keyword the subclass class SavingsAccount : public BankAccount
{
//sends balance and interest rate to BankAccount constructor
public:
SavingsAccount(double b, double i);

//determines if account is active or inactive based on a min acount balance of $25
virtual bool isActive();

//checks if account is active, if it is it uses the superclass version of the method
virtual void withdraw();

//checks if account is active, if it is it uses the superclass version of deposit method
virtual void deposit();

//checks number of withdrawals adds service charge
void monthlyProcess() override;
};

//.cpp file code:

#include "snippet.h"

BankAccount::BankAccount(double bal, double intrRate)
{
balance = bal;
annualInterest = intrRate;
}

void BankAccount::setAmount(double myAmount)
{
amount = myAmount;
}

void BankAccount::deposit(double amountIn)
{
balance = balance + amountIn;
numOfDeposits++;
}

void BankAccount::withdraw(double amount)
{
balance = balance - amount;
numOfWithdraws++;
}

double BankAccount::calcInterest()
{
double monRate;

monRate = interestRate / 12;
monInterest = balance * monRate;
balance = balance + monInterest;
return balance;
}

void BankAccount::monthlyProcess()
{
calcInterest();
numOfWithdraws = 0;
numOfDeposits = 0;
monSCharges = 0;
}

double BankAccount::getBalance()
{
return balance;
}

double BankAccount::getDeposits()
{
return numOfDeposits;
}

double BankAccount::getWithdraws()
{
return numOfWithdraws;
}

SavingsAccount::SavingsAccount(double b, double i) : BankAccount(b, i)
{
}

bool SavingsAccount::isActive()
{
if (balance >= 25)
{
return true;
}
return false;
}

void SavingsAccount::withdraw()
{
if (isActive() == true)
{
BankAccount::withdraw(amount);
}
}

void SavingsAccount::deposit()
{
if (isActive() == true)
{
BankAccount::deposit(amount);
}
}

void SavingsAccount::monthlyProcess()
{
if (numOfWithdraws > 4)
{
monSCharges++;
}
}

NOTE:If my answer helped you,please like my answer. THANK YOU!!


Related Solutions

java code ============ public class BankAccount { private String accountID; private double balance; /** Constructs a...
java code ============ public class BankAccount { private String accountID; private double balance; /** Constructs a bank account with a zero balance @param accountID - ID of the Account */ public BankAccount(String accountID) { balance = 0; this.accountID = accountID; } /** Constructs a bank account with a given balance @param initialBalance the initial balance @param accountID - ID of the Account */ public BankAccount(double initialBalance, String accountID) { this.accountID = accountID; balance = initialBalance; } /** * Returns the...
mport java.util.Scanner; public class BankAccount { //available balance store static double availableBalance; // bills constants final...
mport java.util.Scanner; public class BankAccount { //available balance store static double availableBalance; // bills constants final static int HUNDRED_DOLLAR_BILL = 100; final static int TWENTY_DOLLAR_BILL = 20; final static int TEN_DOLLAR_BILL = 10; final static int FIVE_DOLLAR_BILL = 15; final static int ONE_DOLLAR_BILL = 1; public static void main(String[] args) { System.out.print("Welcome to CS Bank\n"); System.out.print("To open a checking account,please provide us with the following information\n:" ); String fullname; String ssn; String street; String city; int zipCode; Scanner input =...
public class P2 { public static int F(int x[], int c) { if (c < 3)...
public class P2 { public static int F(int x[], int c) { if (c < 3) return 0; return x[c - 1] + F(x, c - 1); } public static int G(int a, int b) { b = b - a; a = b + a; return a; } public static void main(String args[]) { int a = 4, b = 1; int x[] = { 3, 1, 4, 1, 5 }; String s = "Problem Number 2"; System.out.println(x[2 +...
using C++ Please create the class named BankAccount with the following properties below: // The BankAccount...
using C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (using name & id), and - keeps track of a user's available balance. - how many transactions (deposits and/or withdrawals) are made. public class BankAccount { private int id; private String name private double balance; private int numTransactions; // ** Please define method definitions for Accessors and Mutators functions below for the class private member variables string getName();...
public class Account{ public int bal; // this store the balance amount in the account public...
public class Account{ public int bal; // this store the balance amount in the account public Account(int initialBalance) { bal = initialBalance; } public static void swap_1(int num1, int num2) { int temp = num1; num1 = num2; num2 = temp; } public static void swap_2(Account acc1, Account acc2) { int temp = acc1.bal; acc1.bal = acc2.bal; acc2.bal = temp; } public static void swap_3(Account acc1, Account acc2) { Account temp = acc1; acc1 = acc2; acc2 = temp; }...
package hw; public class MyArrayForDouble { double[] nums; int numElements; public MyArrayForDouble() { // Constructor. automatically...
package hw; public class MyArrayForDouble { double[] nums; int numElements; public MyArrayForDouble() { // Constructor. automatically called when creating an instance numElements = 0; nums = new double[5]; } public MyArrayForDouble(int capacity) { // Constructor. automatically called when creating an instance numElements = 0; nums = new double[capacity]; } public MyArrayForDouble(double[] nums1) { nums = new double[nums1.length]; for(int i=0;i<nums1.length;i++) nums[i] = nums1[i]; numElements = nums1.length; } void printArray(){ // cost, times System.out.printf("printArray(%d,%d): ",numElements,nums.length); for(int i=0; i<numElements;i++) System.out.print(nums[i]+" "); System.out.println(); }...
public class StringTools {    public static int count(String a, char c) {          ...
public class StringTools {    public static int count(String a, char c) {           }
Java Create an abstract Product Class Add the following private attributes: name sku (int) price (double)...
Java Create an abstract Product Class Add the following private attributes: name sku (int) price (double) Create getter/setter methods for all attributes Create a constructor that takes in all attributes and sets them Remove the default constructor Override the toString() method and return a String that represents the building object that is formatted nicely and contains all information (attributes) Create a FoodProduct Class that extends Product Add the following private attributes: expDate (java.util.Date) for expiration date refrigerationTemp (int) if 70...
package dealership; public abstract class Vehicle { private float dealerPrice; private int year; public Vehicle(float d,...
package dealership; public abstract class Vehicle { private float dealerPrice; private int year; public Vehicle(float d, int y) { dealerPrice = d; year = y; } public float getDealerPrice() { return dealerPrice; } public int getYear() { return year; } public abstract float getStickerPrice(); } In the space below write a concrete class Car in the dealership package that is a subclass of Vehicle class given above. You will make two constructors, both of which must call the superclass constructor....
public class SinglyLikedList {    private class Node{        public int item;        public...
public class SinglyLikedList {    private class Node{        public int item;        public Node next;        public Node(int item, Node next) {            this.item = item;            this.next = next;        }    }       private Node first;    public void addFirst(int a) {        first = new Node(a, first);    } } 1. Write the method add(int item, int position), which takes an item and a position, and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT