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...
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();...
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...
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 !=...
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)...
Write a program in which define a templated class mySort with private data members as a...
Write a program in which define a templated class mySort with private data members as a counter and an array (and anything else if required). Public member functions should include constructor(s), sortAlgorithm() and mySwap() functions (add more functions if you need). Main sorting logic resides in sortAlgorithm() and mySwap() function should be called inside it. Test your program inside main with integer, float and character datatypes.
Design a Ship class that has the following members: • A member variable for the name...
Design a Ship class that has the following members: • A member variable for the name of the ship (a string) • A member variable for the year that the ship was built (a string) • A constructor and appropriate accessors and mutators • A virtual print function that displays the ship’s name and the year it was built. Design a CruiseShip class that is derived from the Ship class. The CruiseShip class should have the following members: • A...
Write a class called Person that has two private data members - the person's name and...
Write a class called Person that has two private data members - the person's name and age. It should have an init method that takes two values and uses them to initialize the data members. It should have a get_age method. Write a separate function (not part of the Person class) called std_dev that takes as a parameter a list of Person objects and returns the standard deviation of all their ages (the population standard deviation that uses a denominator...
Develop a java program with a class named friend with data members like name, phno and...
Develop a java program with a class named friend with data members like name, phno and hobby. Use Parameterized constructor to create two friend objects and invoke checkhobby method which takes only one parameter, to find whether they have same hobby or different hobbies
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT