Question

In: Computer Science

1.   Design a class, Account, that models the basic workings of a bank account. The class...

1.   Design a class, Account, that models the basic workings of a bank account. The class should perform the following tasks:
a.   Save the account balance.
b.   Save the number of transactions performed on the account.
c.   Allow deposits to be made to the account.
d.   Allow withdrawals to be taken from the account.
e.   Calculate interest for the period.
f.   Report the current account balance at any time.
g.   Report the current number of transactions at any time

The private member variables needed by the class are:
  
-   balance (a double to hold the current account balance)
-   interestRate (a double that holds the interest rate for the period)
-   interest (a double that holds the interest earned for the current period)
-   transactions (an integer that holds the current number of transactions)

The public member functions needed are:

-   constructor to initially store balance (0) and interest rate(0.045 or 4.5%)
-   setInterestRate()
-   makeDeposit()
-   withDraw()
-   calcInterest()
-   getInterestRate()
-   getBalance()
-   getInterest()
-   getTransactions()

Solutions

Expert Solution

#include<iostream>
#include<iomanip>
using namespace std;
//account class
class Account
{ //data member declarations
   private:
       double balance,interestRate,interest;
       static int transactions;
       //member functions
   public:
   Account()   ;
   void setInterestRate();
   void makeDeposit();
   void withDraw();
   void calcInterest();
   double getInterestRate();
   double getBalance();
   double getInterest();
   int getTransactions();
};
//constructor
Account :: Account()
{
    balance=0; //set balance to 0
    interestRate= 4.5; //set interest rate to 4.5
}
//setInterestRate() method
void Account :: setInterestRate()
{
   cout<<endl<<"Enter the Rate of Interest";
   cin>>interestRate; //set the interest rate
   }
   //method to deposit
   void Account :: makeDeposit()
{
   double d;
   cout<<endl<<"Enter the amount to deposit";
   cin>>d; //Inout teh amount too deposit
   if(d<0) //validate the amount
   cout<<endl<<"Invalid amount for deposit";
   else
   balance = balance +d; //update the balance
  
   transactions++; //update the transactions
   }
   //method to withdraw
   void Account :: withDraw()
   {
      double d;
      cout<<endl<<"Enter the amount for withdraw";
      cin>>d;//input the balance
      if(d<0) //validate the balance
      cout<<endl<<"Invalid Amount";
      else
       if(d>balance) //check for sufficient balanc3e or not
       cout<<endl<<"Insufficient balance";
       else
       balance = balance-d; //update the balance
       transactions++;//update the transactions
   }
   //method to calculate the interest
   void Account :: calcInterest()
   {
       interest = (balance * interestRate)/100; //compute the interest
       balance = balance + interest; //update the balance
       transactions++;//update the transactions
   }
   //return the interest rate
   double Account :: getInterestRate()
   {
       return interestRate;
   }
   //return the balance
   double Account :: getBalance()
   {
       return balance;
   }
   //return the interest amount
   double Account :: getInterest()
   {
       return interest;
   }
   //return the number of transactions
   int Account :: getTransactions()
   {
      return transactions;
   }
   //defination of static variable
   int Account::transactions;
   //driver program
   int main()
   {
       Account aobj; //creat object
       int opt;
       //infinite loop
       while(1)
       {
           //display the menu
           cout<<endl<<"1. Set InterestRate\n2. Make Deposit\n3. Withdraw\n4. Interest Calculation\n5. Print InterestRate\n6. Print Balance\n7. Print Total Interest\n 8. Print Number of transactions\n 0. Exit";
           cout<<endl<<"Enter choice";
           cin>>opt;//ask for choice
           //perform the operation according to the choice given by user
           if(opt==1)
           aobj.setInterestRate();
           else
               if(opt==2)
               aobj.makeDeposit();
               else
               if(opt==3)
               aobj.withDraw();
               else
               if(opt==4)     
                   aobj.calcInterest();
               else
               if(opt==5)    
                  cout<<endl<<"Rate of Interest : "<<fixed<<setprecision(2)<<aobj.getInterestRate();
               else
               if(opt==6)   
                   cout<<endl<<"Total Balance : $"<<fixed<<setprecision(2)<<aobj.getBalance();
               else
               if(opt==7)    
                   cout<<endl<<"Total Interest : $"<<fixed<<setprecision(2)<<aobj.getInterest();
               else
               if(opt==8)    
                   cout<<endl<<"Number of transactions performed : "<<aobj.getTransactions();
               else
               if(opt==0)    
               exit(0);
           }
       }
  

OUTPUT

NOTE: NUMBER OF TRANSACTION INCLUDES ONLY FOR WITHDRAW,DEPOSIT AND CALCULATION OF INTEREST. IF YOU WANT TO INCLUDE FOR ALLTHE METHODS THEN INFORM. I WILL UPDATE.


Related Solutions

In C++, define the class bankAccount to implement the basic properties of a bank account. An...
In C++, define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name (string), account number (int), account type (string, checking/saving), balance (double), and interest rate (double). (Store interest rate as a decimal number.) Add appropriate member functions to manipulate an object. Use a static member in the class to automatically assign account numbers. Also declare an array of 10 components of type bankAccount to...
1.   Design a class called BankAccount. The member fields of the class are: Account Name, Account...
1.   Design a class called BankAccount. The member fields of the class are: Account Name, Account Number and Account Balance. There are also other variables called MIN_BALANCE=9.99, REWARDS_AMOUNT=1000.00, REWARDS_RATE=0.04. They look like constants, but for now, they are variables of type double Here is the UML for the class:                                                         BankAccount -string accountName // First and Last name of Account holder -int accountNumber // integer -double accountBalance // current balance amount + BankAccount()                     //default constructor that sets name to “”,...
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...
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....
Using python class: Design a class called Account CLASS NAME:    Account ATTRIBUTES: -nextAcctID: int    #NOTE-...
Using python class: Design a class called Account CLASS NAME:    Account ATTRIBUTES: -nextAcctID: int    #NOTE- class-level attribute initialized to 1000 -acctID: int -bank: String -acctType: String (ex: checking, savings) -balance: Float METHODS: <<Constructor>>Account(id:int, bank: String, type:String, bal:float) +getAcctID(void): int                        NOTE: retrieving a CLASS-LEVEL attribute! -setAcctID(newID: int): void           NOTE: PRIVATE method +getBank(void): String +setBank(newBank: String): void +getBalance(void): float +setBalance(newBal: float): void +str(void): String NOTE: Description: prints the information for the account one item per line. For example: Account #:        ...
c++ The above Account class was created to model a bank account. An account has the...
c++ The above Account class was created to model a bank account. An account has the properties (keep the properties private) account number, balance, and annual interest rate, date created, and functions to deposit and withdraw. Create two derived classes for checking and saving accounts. A checking account has an overdraft limit, but a savings account cannot be overdrawn. Define a constant virtual toString() function in the Account class and override it in the derived classes to return the account...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main()...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main() function to coordinate the execution of the program. We will need methods: Method for Depositing values into the account. What type of method will it be? Method for Withdrawing values from the account. What type of method will it be? Method to output the balance of the account. What type of method will it be? Method that will output all deposits made to the...
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....
JAVA PROGRAM: Creates a Bank Account class with one checking account and methods to withdraw and...
JAVA PROGRAM: Creates a Bank Account class with one checking account and methods to withdraw and deposit. Test the methods in the main function.
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT