Question

c++ program. can you please do commenting. Question 1 [25]. (The Account Class) Design a class...

c++ program. can you please do commenting.

Question 1 [25]. (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.

Homework Answers

Answer #1

The below mentioned code works as per the requirement stated in the question.

The code is commented to understand the flow.


#include <iostream>
using namespace std;

// create a class Account
class Account {

   private:  // private members
    int id;
    double balance;
    double annualInterestRate;
   public:
        
    // constructor
    Account(int i, double bal, double interest) 
    {   id = id;
        balance = bal;
        annualInterestRate = interest;
    }  
    
    // accessors and mutators
    void setAccountId (int x)
    {   
        id = x;
    }

    int getAccountId()
    {   
        return id;
    }
    
    void setBalance(double x)
    {   
        balance = x;
    }
    
    double getBalance()
    {   
        return balance;
    }
    
    void setInterest(double x)
    {   
        annualInterestRate = x;
    }
    
    double getInterest()
    {   
        return annualInterestRate;
    }
    
    double getMonthlyInterestRate()
    {   
        double  mInterestRate;
    
        mInterestRate = annualInterestRate / 12;  // to calculate monthly interest rate
        return mInterestRate;
    }
    
    bool withdraw(double amount)   // to withdraw balance function to deduct balance from current balance
    {   if (balance >= amount)
        {   
            balance -= amount;
                return true;
        }
        else
        {   
            return false;
        }
    }
    
    void deposit(double amount)  // to add balance to current balance
    {  
        
        balance += amount;
    }
    
    


    
};

int main()
{
    int choice;
    double amt;
    string flag = "true";
    
    Account ac(1122, 20000, 4.5); // create object of Account
    
    while (!flag.compare("true")){
    cout<<"Welcome to banking system: ";
    cout << "Enter 1 to make a deposit" << endl;
        cout << "Enter 2 to make a withdraw" << endl;
        cout << "Enter 3 to check balance" << endl;
        cout << "Enter 4 to check monthly interest rate" << endl;
        cout << "Enter 5 to display account summary" << endl;
        cout << "Enter 0 to exit" << endl;
        cin >> choice;
        
        switch (choice)  // cases to every option mentioned above
    {
    case 1:
        cout<< "Enter the amount to deposite: ";
        cin >> amt;
            ac.deposit (amt);    
        break;
        case 2: 
            cout<< "Enter the amount to withdraw: ";
        cin >> amt;
            ac.withdraw (amt);  
        break;
    case 3: 
            cout<< "Your current balance is : " ;
            cout<< ac.getBalance() << endl; 
        break;
        case 4: 
            cout << "Monthly interest rate: " << ac.getMonthlyInterestRate() << endl;
                break;
        case 5:
            cout << "Account ID: " << ac.getAccountId() << endl;
                cout << "Current Balance: " << ac.getBalance() << endl;
                cout << "Monthly interest rate: " << ac.getMonthlyInterestRate() << endl;     
                break;
        case 0:
                exit;
        default:    
            cout << "Invalid option" << endl;               
        }
        
        cout<< "continue? true/false" <<endl;
        
        cin >> flag;  // flag to continue the while loop 
}
    return 0;
}

Output screenshot:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
(The Rectangle class) (WOULD APPRECIATE IT IF THE PROGRAM/ANSWER COULD BE DIRECTLY COPY AND PASTED, also...
(The Rectangle class) (WOULD APPRECIATE IT IF THE PROGRAM/ANSWER COULD BE DIRECTLY COPY AND PASTED, also this should be in java) Following the example of the Circle class in Section 9.2, design a class named Rectangle to represent a rectangle. The class contains: - Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. - A no-arg constructor that creates a default rectangle....
Must be C++ programming    The MyPoint class was created to model a point in a...
Must be C++ programming    The MyPoint class was created to model a point in a two-dimensional space. The MyPoint class has the properties x and y that represent x- and y-coordinates, two get functions for x and y, and the function for returning the distance between two points. Create a class named ThreeDPoint to model a point in a three-dimensional space. Let ThreeDPoint be derived from MyPoint with the following additional features: A data field named z that represents...
In C++ Employee Class Write a class named Employee (see definition below), create an array of...
In C++ Employee Class Write a class named Employee (see definition below), create an array of Employee objects, and process the array using three functions. In main create an array of 100 Employee objects using the default constructor. The program will repeatedly execute four menu items selected by the user, in main: 1) in a function, store in the array of Employee objects the user-entered data shown below (but program to allow an unknown number of objects to be stored,...
Need to get the following output by Editing ChekingAccount.h ,ChekingAccount.cpp CheckingAccount Derived class CheckingAccount that inherits...
Need to get the following output by Editing ChekingAccount.h ,ChekingAccount.cpp CheckingAccount Derived class CheckingAccount that inherits from base class Account and include an additional data member of type double that represents the fee charged per transaction (transactionFee). Write Checking- Account’s constructor that receives the initial balance, as well as a parameter indicating a transaction fee amount. If transaction fee is less than zero, the transactionFee will be set to zero. Write the chargeFee member function that updates the balance by...
C# Step 1: Create a Windows Forms Application. Step 2: Create a BankAccount class. Include: Private...
C# Step 1: Create a Windows Forms Application. Step 2: Create a BankAccount class. Include: Private data fields to store the account holder's name and the account balance A constructor with 0 arguments A constructor with 1 argument (account holder's name) A constructor with 2 arguments(account holder's name and account balance) Public properties for the account holder's name and the account balance. Do not use auto-implemented properties. A method to increase the balance (deposit) A method to decrease the balance...
Design a Java class named Polygon that contains:  A private int data field named numSides...
Design a Java class named Polygon that contains:  A private int data field named numSides that defines the number of sides of the polygon. The default value should be 4.  A private double data field named sideLength that defines the length of each side. The default value should be 5.0.  A private double data field named xCoord that defines the x-coordinate of the center of the polygon. The default value should be 0.0.  A private double...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class...
Create a Software Application for XYZ Bank that allows its members to access their bank account...
Create a Software Application for XYZ Bank that allows its members to access their bank account information through an “ATM like” interface. The Menu Options should include: checking the account balance, debiting the account and crediting the account, along with an option to exit the program. Create an Account Class to represent the customers’ bank accounts. Include a data member of type float to represent the account balance. Provide a constructor that receives an initial balance and uses it to...
IN JAVA PLEASE Design and implement an ADT CreditCard that represents a credit card. The data...
IN JAVA PLEASE Design and implement an ADT CreditCard that represents a credit card. The data of the ADT should include Java variables for the customer name, the account number, the next due date, the reward points, and the account balance. The initialization operation should set the data to client-supplied values. Include operations for a credit card charge, a cash advance, a payment, the addition of interest to the balance, and the display of the statistics of the account. Be...
Create a client for your BankAccount classcalled BankAccountClient.java.    This a separate file from the BankAccount file....
Create a client for your BankAccount classcalled BankAccountClient.java.    This a separate file from the BankAccount file. Both files must be in the same directory to compile. Display all dollar amounts using the DecimalFormat class. Create an account Ask the user for the type of account, the bank account number, the amount that they will deposit to start the account. Set interest earned to 0. Print the account information using an implicit or explicit call to toString Update an account Use...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT