Question

In: Computer Science

In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance:...

In c++, define a class with the name BankAccount and the following members:

Data Members:

  1. accountBalance: balance held in the account
  2. interestRate: annual interest rate.
  3. accountID: unique 3 digit account number assigned to each BankAccount object. Use a static data member to generate this unique account number for each BankAccount
  4. count: A static data member to track the count of the number of BankAccount objects created.

Member Functions

  1. void withdraw(double amount): function which withdraws an amount from accountBalance
  2. void deposit(double amount): function which deposits an amount to the accountBalance.
  3. void calculateMonthlyInterest( ): function which calculates the monthly interest and adds to accountBalance
  4. void displayAccountInfo( ): function which displays the accountID, accountBalance, interestRate and count of the number of BankAccounts created.

Solutions

Expert Solution

Code

#include<iostream>

using namespace std;
class BankAccount
{
private:
   double accountBalance;
   double interestRate;
   int accountId;
public:
   static int count;
   BankAccount(double,double);
   void withdraw(double);
   void deposit(double);
   void calculateMonthlyInterest();
   void displayAccountInfo();
};
int BankAccount::count=0;
BankAccount::BankAccount(double balance,double rate)
{
   accountBalance=balance;
   interestRate=rate;
   accountId=101+count;
   count++;
}
void BankAccount::withdraw(double amount)
{
   if(amount>accountBalance)
   {
       cout<<"Insufficient balance."<<endl;
       return;
   }
   else
   {
       accountBalance-=amount;
   }
}
void BankAccount::deposit(double amount)
{
   accountBalance+=amount;
}
void BankAccount::calculateMonthlyInterest()
{
   accountBalance+=accountBalance*(interestRate/100);
}
void BankAccount::displayAccountInfo()
{
   cout<<"Account ID: "<<accountId<<endl;
   cout<<"Account Balance: $"<<accountBalance<<endl;
   cout<<"Intrest Rate: "<<interestRate<<"%"<<endl;
   cout<<"Number of account created: "<<count<<endl<<endl;
}
int main()
{
   BankAccount ba1(1000,4.5);
   BankAccount ba2(2000,6.5);

   cout<<"Initially account is "<<endl;
   ba1.displayAccountInfo();
   ba2.displayAccountInfo();

   ba1.deposit(200);
   ba2.deposit(500);
  
   cout<<"\nAfter deposite account is"<<endl;
   ba1.displayAccountInfo();
   ba2.displayAccountInfo();

}

output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.


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...
c++ programming 1.1 Class definition Define a class bankAccount to implement the basic properties of a...
c++ programming 1.1 Class definition Define a 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, check/savings/business)  Balance (double)  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. 1.2 Implement...
In C++ Define a base class called Person. The class should have two data members to...
In C++ Define a base class called Person. The class should have two data members to hold the first name and last name of a person, both of type string. The Person class will have a default constructor to initialize both data members to empty strings, a constructor to accept two string parameters and use them to initialize the first and last name, and a copy constructor. Also include appropriate accessor and mutator member functions. Overload the operators == and...
using C++ Please create the class named BankAccount with the following properties below: // The BankAccount...
using C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (using name & id), and - keeps track of a user's available balance. - how many transactions (deposits and/or withdrawals) are made. public class BankAccount { private int id; private String name private double balance; private int numTransactions; // ** Please define method definitions for Accessors and Mutators functions below for the class private member variables string getName();...
C++ Define a base class called Person. The class should have two data members to hold...
C++ Define a base class called Person. The class should have two data members to hold the first name and last name of a person, both of type string. The Person class will have a default constructor to initialize both data members to empty strings, a constructor to accept two string parameters and use them to initialize the first and last name, and a copy constructor. Also include appropriate accessor and mutator member functions. Overload the operators == and !=...
Define the class HotelRoom. The class has the following private data members: the room number (an...
Define the class HotelRoom. The class has the following private data members: the room number (an integer) and daily rate (a double). Include a default constructor as well as a constructor with two parameters to initialize the room number and the room’s daily rate. The class should have get/set functions for all its private data members [20pts]. The constructors and the get/set functions must throw an invalid_argument exception if either one of the parameter values are negative. The exception handler...
Define the class HotelRoom. The class has the following private data members: the room number (an...
Define the class HotelRoom. The class has the following private data members: the room number (an integer) and daily rate (a double). Include a default constructor as well as a constructor with two parameters to initialize the room number and the room’s daily rate. The class should have get/set functions for all its private data members [20pts]. The constructors and the get/set functions must throw an invalid_argument exception if either one of the parameter values are negative. The exception handler...
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 “”,...
Create a class BankAccount to hold at least the following data / information about a bank...
Create a class BankAccount to hold at least the following data / information about a bank account: Account balance Total number of deposits Total number of withdrawals Interest rate e.g., annual rate = 0.05 Service charges per month The class should have the following member functions: Constructor To set the required data. It may be parameterized or user’s input. depositAmount A virtual function used to accept an argument for the amount to be deposited. It should add the argument (amount)...
Design a Ship class that the following members: A field for the name of the ship...
Design a Ship class that the following members: A field for the name of the ship (a string). A field for the year that the ship was built (a string). A constructor and appropriate accessors and mutators. A toString method that displays the ship’s name and the year it was built. Design a CruiseShip class that extends the Ship class. The CruiseShip class should have the following members: A field for the maximum number of passengers (an int). A constructor...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT