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
c++ Design a class named Account that contains (keep the data fields private): a) An int...
c++ 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...
Problem Description: Problem Description: (The Account class) Design a class named Account that contains: A private...
Problem Description: Problem Description: (The Account class) 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...
Define the EvenNumber class for representing an even number. The class contains: A data field value...
Define the EvenNumber class for representing an even number. The class contains: A data field value of the int type that represents the integer value stored in the object. A no-arg constructor that creates an EvenNumber object for the value 0. A constructor that constructs an EvenNumber object with the specified value. A function named getValue() to return an int value for this object. A function named getNext() to return an EvenNumber object that represents the next even number after...
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...
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...
Has to be written in C#! Write a program that includes an Employee class that can...
Has to be written in C#! Write a program that includes an Employee class that can be used to calculate and print the take-home pay for a commissioned sales employee. Items to include as data members are employee number, first name, last name, and total sales. All employees receive 9% of the total sales of the month. Federal tax rate is 18%. Retirement contribution is 10%. Social Security tax rate is 6%. Use appropriate constants, design an object-oriented solution, and...
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...
****in java Create a class CheckingAccount with a static variable of type double called interestRate, two...
****in java Create a class CheckingAccount with a static variable of type double called interestRate, two instance variables of type String called firstName and LastName, an instance variable of type int called ID, and an instance variable of type double called balance. The class should have an appropriate constructor to set all instance variables and get and set methods for both the static and the instance variables. The set methods should verify that no invalid data is set. Also define...
Using Java language.... Polymorphism of Interfaces : Take the Account class from the last chapter and...
Using Java language.... Polymorphism of Interfaces : Take the Account class from the last chapter and make a java program for your bank. However, there is another type of customer that may not have money in the bank and may not in fact have a back account with this bank at all, but may have a loan here. Make another class in the application you are making called CarLoan. Carloan's should have a name, amount owed, a rate, and a...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT