Question

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 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

#include <iostream>

using namespace std;

class Account

{

private:

    // a) An int data field named id for the account.

    int id;

    // b) A double data field named balance for the account.

    double balance;

    // c) A double data field named annualInterestRate that stores the current interest rate.

    double annualInterestRate;

public:

    // d) A no-arg constructor that creates a default account with id 0, balance 0, and annualInterestRate 0.

    Account()

    {

        this->id = 0;

        this->balance = 0;

        this->annualInterestRate = 0;

    }

    // e) The accessor and mutator functions for id, balance, and annualInterestRate.

    int getId()

    {

        return id;

    }

    double getBalance()

    {

        return balance;

    }

    double getAnnualInterestRate()

    {

        return annualInterestRate;

    }

    void setId(int id)

    {

        this->id = id;

    }

    void setBalance(double balance)

    {

        this->balance = balance;

    }

    void setAnnualInterestRate(double annualInterestRate)

    {

        this->annualInterestRate = annualInterestRate;

    }

    // f) A function named getMonthlyInterestRate() that returns the monthly interest rate.

    double getMonthlyInterestRate()

    {

        return annualInterestRate / 12;

    }

    // g) A function named withdraw(amount) that withdraws a specified amount from the account.

    void withdraw(double amount)

    {

        if (balance >= amount)

            balance -= amount;

    }

    // h) A function named deposit(amount) that deposits a specified amount to the account.

    void deposit(double amount)

    {

        if (amount > 0)

            balance += amount;

    }

};

int main()

{

    // create an Account object with an

    Account testing;

    // account ID of 1122

    testing.setId(1122);

    // a balance of 20000

    testing.setBalance(20000);

    // an annual interest rate of 4.5%.

    testing.setAnnualInterestRate(4.5);

    // Use the withdraw function to withdraw $2500,

    testing.withdraw(2500);

    // use the deposit function to deposit $3000,

    testing.deposit(3000);

    // and print the balance, the monthly interest.

    cout << "Balance: $" << testing.getBalance() << endl;

    cout << "Monthly interest: $" << testing.getMonthlyInterestRate() * testing.getBalance() / 100 << endl;

}

.

Output:

.

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++ 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...
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...
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,...
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...
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...
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...
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...
Menu.cpp isn't working. C++  utilize inheritance to create a banking app. The architecture of the app is...
Menu.cpp isn't working. C++  utilize inheritance to create a banking app. The architecture of the app is up to you as long as you implement some form of inheritance. Below is my code however the credit and the actual menu isn't working. Can i get some help on getting the menu to work properly. // BankAccount.h #ifndef ACCOUNT_H #define ACCOUNT_H #include <string> #include <iostream> using namespace std; class BankAccount { protected : int noOfWithdrawls; private: // Declaring variables    float balance;...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields,...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields, as well as the methods for the Inventory class (object). Be sure your Inventory class defines the private data fields, at least one constructor, accessor and mutator methods, method overloading (to handle the data coming into the Inventory class as either a String and/or int/float), as well as all of the methods (methods to calculate) to manipulate the Inventory class (object). The data fields...
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...