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 MyDate class to represent a data that has 3 data members: day, month,...
C++ Define a MyDate class to represent a data that has 3 data members: day, month, year. The class should have: A default constructor to initialize the day, month, and year to 0. A constructor that accepts three integers as arguments to initialize the day, month, and year if the three arguments are valid. A copy constructor that accepts a reference to a MyDate object as argument. This constructor use the argument's three data fields to initialize the day, month,...
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...
c++ Design the Weather class that contains the following members: Data members to store: -a day...
c++ Design the Weather class that contains the following members: Data members to store: -a day (an integer) -a month (an integer) -a year (an integer) -a temperature (a float) -a static data member that stores the total of all temperatures (a float) Member functions: -a constructor function that obtains a day, month, year and temperature from the user. This function should also accumulate/calculate the total of all temperatures (i.e., add the newly entered temperature to the total). -a static...
C++ Assignment. Design the Weather class that contains the following members: Data members to store: -...
C++ Assignment. Design the Weather class that contains the following members: Data members to store: - a day (an integer) - a month (an integer) - a year (an integer) - a temperature (a float) - a static data member that stores the total of all temperatures (a float) Member functions: - a constructor function that obtains a day, month, year and temperature from the user. This function should also accumulate/calculate the total of all temperatures (i.e., add the newly...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT