Question

In: Computer Science

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. f) A function named getMonthlyInterestRate() that returns the monthly interest rate. g) A function named withdraw(amount) that withdraws a specified amount from the account. h) A function named deposit(amount) that deposits a specified amount to the account. Implement the class. Write a test program that creates an Account object with an account ID of 1122, a balance of 20000, and an annual interest rate of 4.5%. Use the withdraw function to withdraw $2500, use the deposit function to deposit $3000, and print the balance, the monthly interest.

Solutions

Expert Solution

Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.

Let me know for any help with any other questions.

Thank You!
===========================================================================

#include<iostream>
#include<iomanip>
using namespace std;

class Account{
   private:
       int id;
       double balance;
       double annualInterestRate;
   public:
       Account(){
           id = 0; balance = 0; annualInterestRate =0;
       }
       int getID() const{return id;}
       double getBalance() const{return balance;}
       double getAnnualInterestRate() const{return annualInterestRate;}
      
       void setID(int id){this->id =id;}
       void setBalance(double bal);
       void setAnnualInterestRate(double rate);
       double getMonthlyInterestRate() const;
       void withdraw(double amount);
       void deposit(double amount);
       double getMonthlyInterest() const;
      
};
void Account::setBalance(double bal){
   if(bal>0) balance = bal;
}
void Account::setAnnualInterestRate(double rate){
   if(rate>0) annualInterestRate=rate;
}
double Account::getMonthlyInterestRate() const{
return annualInterestRate/12;
}
void Account::withdraw(double amount){
   if(amount>0 && amount<balance) balance = balance - amount;
   else cout<<"Sorry! You dont have sufficient funds.\n";
}
void Account::deposit(double amount){
   if(amount>0) balance += amount;
}

double Account::getMonthlyInterest() const{
   return getMonthlyInterestRate()*getBalance()/100;
}

int main(){
  
  
   Account myAccount;
   myAccount.setID(1122);
   myAccount.setBalance(20000);
   myAccount.setAnnualInterestRate(4.5);
  
   cout<<"Account Details:\n";
   cout<<"Account ID: "<< myAccount.getID()<<endl;
   cout<<"Account Balance: $"<<myAccount.getBalance()<<endl;
   cout<<"Annual Interest Rate Pecentage: "<<myAccount.getAnnualInterestRate()<<endl;
   cout<<"Monthly Interest Rate Percentage: "<<myAccount.getMonthlyInterestRate()<<endl;
   cout<<"Monthly Interest Earned: $"<<myAccount.getMonthlyInterest()<<endl;
  
  
   cout<<"\nWithdrawing $4500 amount...\n\n";
   myAccount.withdraw(4500);
   cout<<"Account Balance: $"<<myAccount.getBalance()<<endl;
   cout<<"Monthly Interest Earned: $"<<myAccount.getMonthlyInterest()<<endl;
  
   cout<<"\nDepositing $3000 amount...\n\n";
   myAccount.deposit(3000);
   cout<<"Account Balance: $"<<myAccount.getBalance()<<endl;
   cout<<"Monthly Interest Earned: $"<<myAccount.getMonthlyInterest()<<endl;
  


   return 0;
}
======================================================================


Related Solutions

In c++ Design a class named Account that contains: a.An int data field named id for...
In c++ Design a class named Account that contains: a.An int data field named id for the account. b.A double data field named balancefor the account. c.A double data field named annualInterestRate that stores the current interestrate. d.A no-arg constructor that creates a default account with id 0, balance 0, andannualInterestRate 0. e.The set and get functions for id,balance, and annualInterestRate. f.A functionearnedAmount()that calculates and returns the amount of dollars earned after one year. g.A function named printAccountInfo() that print...
7.3 (The Account class) Design a class named Account that contains: ■ A private int data...
7.3 (The Account class) Design a class named Account that contains: ■ A private int data field named id for the account. ■ A private float data field named balance for the account. ■ A private float data field named annualInterestRate that stores the current interest rate. ■ A constructor that creates an account with the specified id (default 0), initial balance (default 100), and annual interest rate (default 0). ■ The accessor and mutator methods for id, balance, and...
Design a class named Account that contains: A private int data field named id for the...
Design a class named Account that contains: A private int data field named id for the account. A private double data field named balance for the account. A private double data field named annualInterestRate that stores the current interest rate. A no-arg constructor that creates a default account with id 0, balance 0, and annualInterestRate 0. The accessor and mutator methods for id, balance, and annualInterestRate. A method named getMonthlyInterestRate() that returns the monthly interest rate. A method named withdraw(amount)...
Design a class named Account that contains: A private String data field named accountNumber for the...
Design a class named Account that contains: A private String data field named accountNumber for the account (default AC000). A private double data field named balance for the account (default 0). A private double data field named annualIntRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. A private Date data field named dateCreated that stores the date when the account was created. A no-arg constructor that creates a default account. A constructor...
Design a class named Account that contains: ■ A private int data field named id for...
Design a class named Account that contains: ■ A private int data field named id for the account (default 0). ■ A private double data field named balance for the account (default 0). ■ A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. ■ A private Date data field named dateCreated that stores the date when the account was created. ■ A no-arg constructor that creates...
c++ E2b: Design a class named Rectangle to represent a rectangle. The class contains:
using c++E2b: Design a class named Rectangle to represent a rectangle. The class contains:(1) Two double data members named width and height which specifies the width and height of the rectangle .(2) A no-arg constructor that creates a rectangle with width 1 and height 1.(3) A constructor that creates a rectangle with the specified width and height .(4) A function named getArea() that returns the area of this rectangle .(5) A function named getPerimeter() that returns the perimeter of this...
Java - Design a class named Account that contains: A private String data field named accountNumber...
Java - Design a class named Account that contains: A private String data field named accountNumber for the account (default AC000). A private double data field named balance for the account (default 0). A private double data field named annualIntRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. A private Date data field named dateCreated that stores the date when the account was created. A no-arg constructor that creates a default account....
THIS IS JAVA PROGRAMMING Design a class named Account (that contains 1. A private String data...
THIS IS JAVA PROGRAMMING Design a class named Account (that contains 1. A private String data field named id for the account (default 0). 2. A private double data field named balance for the account (default 0). 3. A private double data field named annualInterestRate that stores the current interest rate (default 0). 4. A private Date data field named dateCreated that stores the date when the account was created. 5. A no-arg constructor that creates a default account. 6....
Design a class named Fan to represent a fan. The class contains: ■ Three constants named...
Design a class named Fan to represent a fan. The class contains: ■ Three constants named SLOW, MEDIUM, and FAST with the values 1, 2, and 3 to denote the fan speed. ■ A private int data field named speed that specifies the speed of the fan (the default is SLOW). ■ A private boolean data field named on that specifies whether the fan is on (the default is false). ■ A private double data field named radius that specifies...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT