Question

In: Computer Science

Accounting Program in c++ Write a class to keep track of a balance in a bank...

Accounting Program in c++

Write a class to keep track of a balance in a bank account with a varying annual interest rate. The constructor will set both the balance and the interest rate to some initial values (with defaults of zero). The class should have member functions to change or retrieve the current balance or interest rate. There should also be functions to make a deposit (add to the balance) or withdrawal (subtract from the balance). You should not allow more money to be withdrawn than what is available in the account, nor should you allow for negative deposits. Finally, there should be a function that adds interest to the balance (interest accrual) at the current interest rate. This function should have a parameter indicating how many months’ worth of interest are to be added (for example, 6 indicate the account should have 6 months’ added). Interest is accrued from an annual rate. The month is representative of 1/12 that amount. Each month should be calculated and added to the total separately. For example: 1 month accrued at 5% APR is Balance = ((Balance * 0.05)/12) + Balance; For 3 months the calculations you repeat the statement above 3 times. Use the class as part of the interactive program provided below.

Solutions

Expert Solution

If you have any problem with the code feel free to comment

Program

#include <iostream>
#include <stdlib.h>

using namespace std;

class BankAccount{

private:
//instances of the class
float balance, interestRate;

public:
//default constructor
BankAccount(){
balance = 0;
interestRate = 0;
}
//getters and setters
void setBalance(float balance){
this->balance = balance;
}
float getBalance(){
return balance;
}
void setInterestRate(float interestRate){
this->interestRate = interestRate;
}
float getInterestRate(){
return interestRate;
}

//for performing deposit function
void deposit(float amount){
//deposit only when amount is more than 0
//else keep the balance unchanged
if(amount > 0)
balance += amount;
}

//for performing withdraw function
void withdraw(float amount){
//withdraw only when the amount is less than the balance
//else keep the balance unchanged
if(amount < balance)
balance -= amount;
}
//calculating the interest and adding it to the balance
void addInterest(int months){
interestRate = interestRate/100;
for(int i =0; i<months; i++){
balance = ((balance * interestRate)/12) + balance;
}
}
};

int main(){
BankAccount obj;

cout<<"Initial Balance: $"<<obj.getBalance()<<endl;
cout<<"Initial Interest Rate: "<<obj.getInterestRate()<<"%"<<endl;

//setting balance and interest rate
obj.setBalance(2000);
obj.setInterestRate(5);

cout<<"\nAfter Setting the Balance and Interest Rate"<<endl;
cout<<"Balance: $"<<obj.getBalance()<<endl;
cout<<"Interest Rate: "<<obj.getInterestRate()<<"%"<<endl;

//depositing
obj.deposit(1500);
cout<<"\nBalance after deposit: $"<<obj.getBalance()<<endl;

//withdrawing
obj.withdraw(1000);
cout<<"\nBalance after withdraw: $"<<obj.getBalance()<<endl;

//after interest added
obj.addInterest(6);
cout<<"\nBalance after interest added: $"<<obj.getBalance()<<endl;
}

Output


Related Solutions

Write a class to keep track of a balance in a bank account with a varying...
Write a class to keep track of a balance in a bank account with a varying annual interest rate. The constructor will set both the balance and the interest rate to some initial values (with defaults of zero). The class should have member functions to change or retrieve the current balance or interest rate. There should also be functions to make a deposit (add to the balance) or withdrawal (subtract from the balance). You should not allow more money to...
Write a class to keep track of a balance in a bank account with a varying...
Write a class to keep track of a balance in a bank account with a varying annual interest rate. The constructor will set both the balance and the interest rate to some initial values (with defaults of zero). The class should have member functions to change or retrieve the current balance or interest rate. There should also be functions to make a deposit (add to the balance) or withdrawal (subtract from the balance). You should not allow more money to...
Write a class to keep track of a balance in a bank account with a varying...
Write a class to keep track of a balance in a bank account with a varying annual interest rate. The constructor will set both the balance and the interest rate to some initial values (with defaults of zero).The class should have member functions to change or retrieve the current balance or interest rate. There should also be functions to make a deposit (add to the balance) or withdrawal (subtract from the balance). You should not allow more money to be...
Write a class to keep track of a balance in a bank account with a varying...
Write a class to keep track of a balance in a bank account with a varying annual interest rate. The constructor will set both the balance and the interest rate to some initial values (with defaults of zero). The class should have member functions to change or retrieve the current balance or interest rate. There should also be functions to make a deposit (add to the balance) or withdrawal (subtract from the balance). You should not allow more money to...
Write a c++ program for the Sales Department to keep track of the monthly sales of...
Write a c++ program for the Sales Department to keep track of the monthly sales of its salespersons. The program shall perform the following tasks: Create a base class “Employees” with a protected variable “phone_no” Create a derived class “Sales” from the base class “Employees” with two public variables “emp_no” and “emp_name” Create a second level of derived class “Salesperson” from the derived class “Sales” with two public variables “location” and “monthly_sales” Create a function “employee_details” under the class “Salesperson”...
Write a C++ program (The Account Class) Design a class named Account that contains (keep the...
Write a C++ program (The Account Class) Design a class named Account that contains (keep the data fields private): a) An int data field named id for the account. b) A double data field named balance for the account. c) A double data field named annualInterestRate that stores the current interest rate. d) A no-arg constructor that creates a default account with id 0, balance 0, and annualInterestRate 0. e) The accessor and mutator functions for id, balance, and annualInterestRate....
Write C++ a program that shows a class called gamma that keeps track of how many...
Write C++ a program that shows a class called gamma that keeps track of how many objects of itself there are. Each gamma object has its own identification called ID. The ID number is set equal to total of current gamma objects when an object is created. Test you class by using the main function below. int main()    {    gamma g1;    gamma::showtotal();    gamma g2, g3;    gamma::showtotal();    g1.showid();    g2.showid();    g3.showid();    cout <<...
ASSIGNMENT: Write a program to keep track of the total number of bugs collected in a...
ASSIGNMENT: Write a program to keep track of the total number of bugs collected in a 7 day period. Ask the user for the number of bugs collected on each day, and using an accumulator, keep a running total of the number of bugs collected. Display the total number of bugs collected, the count of the number of days, and the average number of bugs collected every day. Create a constant for the number of days the bugs are being...
In accounting, balance sheets are used to keep of track how much money a person has...
In accounting, balance sheets are used to keep of track how much money a person has in an account.  Write a Python program to create a simple three column balance sheet, showing credits in one column, debits in the next, and a running balance in the third.  If the balance dips into the negative, you must show the value in parentheses, the standard method in accounting. Input will be from a text file. The first value will be the opening balance in...
Using c++ Design a system to keep track of employee data. The system should keep track...
Using c++ Design a system to keep track of employee data. The system should keep track of an employee’s name, ID number and hourly pay rate in a class called Employee. You may also store any additional data you may need, (hint: you need something extra). This data is stored in a file (user selectable) with the id number, hourly pay rate, and the employee’s full name (example): 17 5.25 Daniel Katz 18 6.75 John F. Jones Start your main...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT