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...
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...
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...
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...
1. Define a class named Book that contains:  An int data field named pages that...
1. Define a class named Book that contains:  An int data field named pages that stores the number of pages in the book.  A String data field named title that represents the title of the book.  A constructor with parameters for initializing pages and title.  The getter and setter methods for all data fields.  A toString method that returns book information, including the book title and pages.  The equals method that returns true if...
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...