Question


he class definition for a Hank Account class, contains the following private data nembers: the name, account number (both are character arrays of 30 elements each) alance, and interest rate Cbolth are double). It also have the following public member unctions Bank AccountO: This function is the default constructor. deposito: subsequently adjusts the balance. (balance- balance + amt) withdrawo: This function is passed an amount to withdraw and subsequently adjusts the balance. (balance balance- amt). cale interestO: This function calculates the simple interest on the account by using the interest rate and balance data members and subsequently adjusts the balance by adding the interest.(balance balance+ balance interest_rate) This function is passed an amount to deposit and get name0 This function returns the name. . get accountO: This function returns the account number. get balance0: This function returns the balance. get interestO: This function returns the interest rate . set allO This function is passed a name, account number, balance, and interest rate and assigns these arguments to the private data members of the class. a. Write the elass definition for the Bank_Account in the file bank account.h b. Write the method definitions for the Bank_Account class in the file bank account.epp. Write the driver as bankacctdrvr.cpp Create two Bank account objects acct1, and acet2. For acctl the data is John Smith, 206-345678, 55000.00, 0.08, for acct2 Paul Jones 206-436789,75000.00, 0.05 accti deposits 10000.00, and withdraws 5000.00, and acct2 deposits 15000.00, and withdraws 7500.00. Also invoke the cale interest method for both objects. You should use the cout statements to return the values of all private data members. Create a bank object acet3 to be the copy of acct2(Use the copy constructor. You should define in the bank account.h, and write the code for it in the method file, i.e., bank-account.cpp) Test if the two accounts acct3 and acet2 are the same. If they are equal, you should print the message The two accounts acet2 and acct3 are the same otherwise the two accounts acct2 and acct3 are different. c. d. e. (You should overload the operator -Again define it in the bank acct.h, and write the code for it in the method file bank account.cpp)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//bank_account.h

#include<iostream>

using namespace std;

class Bank_Account{
  
   private:
       char name[30],account_number[30];
       double balance,interest_rate;
   public:
       Bank_Account();
       Bank_Account(const Bank_Account&);        //copy constructor
       void operator == (const Bank_Account&);   //Operator overloading
       void deposit(double);
       void withdraw(double);
       void calc_interest();
       char* get_name();
       char* get_account();
       double get_balance();
       double get_interest();
       void set_all(char[],char[],double,double);             
};

//bank_account.cpp

#include<iostream>
#include<string.h>
#include "bank_account.h"
using namespace std;

Bank_Account::Bank_Account(){}
Bank_Account::Bank_Account(const Bank_Account &obj)        //copy constructor
{
   strcpy(name,obj.name);
   strcpy(account_number,obj.account_number);
   balance=obj.balance;
   interest_rate=obj.interest_rate;
}
void Bank_Account::operator == (const Bank_Account &obj2)
{
   if(strcmp(this->name,obj2.name)==0 && strcmp(this->account_number,obj2.account_number)==0 &&(this->balance==obj2.balance) && (this->interest_rate==obj2.interest_rate))
   cout<<"The two accounts "<<this->name<<" and "<<obj2.name<<" are the same";
   else
   cout<<"The two accounts "<<this->name<<" and "<<obj2.name<<" are the different";
}
void Bank_Account::deposit(double amt)
{
   balance += amt;
}
void Bank_Account::withdraw(double amt)
{
   balance -= amt;
}
void Bank_Account::calc_interest()
{
   balance += balance * interest_rate;
}
char* Bank_Account::get_name()
{
   return name;
}
char* Bank_Account::get_account()
{
   return account_number;
}
double Bank_Account::get_balance()
{
   return balance;
}
double Bank_Account::get_interest()
{
   return interest_rate;
}
void Bank_Account::set_all(char n[30],char account[30],double bal,double interest)
{
   strcpy(name,n);
   strcpy(account_number,account);
   balance=bal;
   interest_rate=interest;
}   

//bankacctdrvr.cpp

#include<iostream>
#include<stdio.h>
#include "bank_account.h"
using namespace std;

int main()
{

char *nam,*account; //Pointers to hold name and account number

Bank_Account acct1,acct2,acct3;

acct1.set_all("John Smith","206-345678",55000.00,0.08);
acct2.set_all("Paul Jones","206-436789",75000.00,0.05);

acct1.deposit(10000.00);
acct1.withdraw(5000.00);
acct1.calc_interest();

acct2.deposit(15000.00);
acct2.withdraw(7500.00);
acct2.calc_interest();

nam=acct1.get_name();
account=acct1.get_account();

printf("Name: %s\n",nam);      //Displaying the details
printf("Account: %s\n",account);
cout<<"Balance: "<<acct1.get_balance()<<endl;
cout<<"Interest rate:"<<acct1.get_interest()<<endl;

nam=acct2.get_name();
account=acct2.get_account();

printf("Name: %s\n",nam);     //Displaying the details
printf("Account: %s\n",account);
cout<<"Balance: "<<acct2.get_balance()<<endl;
cout<<"Interest rate:"<<acct2.get_interest()<<endl;

acct3 = acct2;   // calling Copy constructor

nam=acct3.get_name();
account=acct3.get_account();

printf("Name: %s\n",nam);     //Displaying the details
printf("Account: %s\n",account);
cout<<"Balance: "<<acct3.get_balance()<<endl;
cout<<"Interest rate:"<<acct3.get_interest()<<endl;


acct2==acct3;   //Operator overloading
  
}

Sample Output:

CAUsersRaNa\Documents\raj HomeworkLiblbankaccount.exe Name: John Smith Account: 206-345678 Balance: 64800 Interest rate:0.08 Name: Paul Jones Account: 206-436789 Balance: 86625 Interest rate:0.05 Name: Paul Jones Account: 206-436789 Balance: 86625 Interest rate:0.05 The two accounts Paul Jones and Paul Jones are the same Process exited after 26.02 seconds with return value e Press any key to continue . . .

Add a comment
Know the answer?
Add Answer to:
he class definition for a Hank Account class, contains the following private data nembers: the name,...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 9.7 (The Account class) Design a class named Account that contains: • A private int data...

    9.7 (The Account class) Design a class named Account that contains: • A private int data field named id for the account (default o). • A private double data field named balance for the account (default o). • A private double data field named annualInterestRate that stores the current interest rate (default o). Assume that all accounts have the same interest rate. • A private Date data field named dateCreated that stores the date when the account was created. •...

  • (The Account class) Design a class named Account that contains: A private int data field named...

    (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 that creates a default...

  • Java Code: 2. Define a class ACCOUNT with the following members: Private members Acno of type...

    Java Code: 2. Define a class ACCOUNT with the following members: Private members Acno of type int Name of type String Balance of type float Public members void Init) method to enter the values of data members void Show) method to display the values of data members void Deposit(int Amt) method to increase Balance by Amt void Withdraw(int Amt) method to reduce Balance by Amt (only if required balance exists in account) float RBalance() member function that returns the value...

  • PYTHON PROGRAMMING LANGUAGE Design a class named Savings Account that contains: A private int data field...

    PYTHON PROGRAMMING LANGUAGE Design a class named Savings Account that contains: A private int data field named id for the savings account. A private float data field named balance for the savings account. A private float data field named annuallnterestRate that stores the current interest rate. A_init_ that creates an account with the specified id (default 0), initial balance (default 100), and annual interest rate (default 0). . The accessor and mutator methods for id, balance, and annuallnterestRate. A method...

  • Design a class named BankAccount that contains: 1. A private int data field named accountId for...

    Design a class named BankAccount that contains: 1. A private int data field named accountId for the account. 2. A private double data field named accountBalance for the account (default 0). 3. A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. 4. A private Date data field named dateCreated that stores the date when the account was created. 5. A private int data field named numberOfDeposits...

  • In C++ Write a program that contains a BankAccount class. The BankAccount class should store the...

    In C++ Write a program that contains a BankAccount class. The BankAccount class should store the following attributes: account name account balance Make sure you use the correct access modifiers for the variables. Write get/set methods for all attributes. Write a constructor that takes two parameters. Write a default constructor. Write a method called Deposit(double) that adds the passed in amount to the balance. Write a method called Withdraw(double) that subtracts the passed in amount from the balance. Do not...

  • in c++ Define and implement the class Employee with the following requirements: private data members string...

    in c++ Define and implement the class Employee with the following requirements: private data members string type name a. b. double type hourlyRate 2. public member functions a. default constructor that sets the data member name to blank"and hourlyRate to zero b. A constructor with parameters to initialize the private data members c. Set and get methods for all private data members d. A constant method weeklyPay() that receives a parameter representing the number of hours the employee worked per...

  • The Account class Create a class named Account, which has the following private properties: number: long...

    The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber(), getBalance(), setBalance(double newBalance). There is no setNumber() -- once an account is created, its account number cannot change. Now implement these methods: void deposit(double amount) and void withdraw(double amount). For both these methods,...

  • Design a class that contains: we have to make 3 files header file , one .cpp...

    Design a class that contains: we have to make 3 files header file , one .cpp file for function and one more main cpp file 9.3 (The Account class) Design a class named Account that contains: An int data field named id for the account. A double data field named balance for the account. A double data field named annualInterestRate that stores the current interest rate. A no-arg constructor that creates a default account with id 0, balance 0, and...

  • Write a class called Player that has four data members: a string for the player's name,...

    Write a class called Player that has four data members: a string for the player's name, and an int for each of these stats: points, rebounds and assists. The class should have a default constructor that initializes the name to the empty string ("") and initializes each of the stats to -1. It should also have a constructor that takes four parameters and uses them to initialize the data members. It should have get methods for each data member. It...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT