Question

For this lab you must write a complete class in C++. This will be a class...

For this lab you must write a complete class in C++. This will be a class named BankAccount. This class must have the following private variables:

1. accountHolderName : string

2. balance : double

3. interestRate: double

This class must have the following public constructor:

1. BancAccount(name : string, balance : double, rate : double)

This class must have the following public member functions:

1. getAccountHolderName() : string a. returns the account holders name

2. getBalance() : double a. returns the current balance

3. getInterestRate() : double a. returns the current interest rate

4. deposit(amount : double) : void a. adds the amount to the balance

5. withdraw(amount : double) : void a. subtracts the amount from the balance

6. applyInterest() : void a. adds interest (balance * interestRate) to the balance

You must write the complete and correct BankAccount.h file that will contain the class declaration.

You must write the complete and correct BankAccount.cpp file that will contain the implementation code.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program code:

#include<iostream.h>

#include<conio.h>

class bankAccount

{

public:

char *name;

double balance,d,w,a,a1,i;

double rate;

public:

bankAccount()//constructor is used

{

name=name;

balance=balance;

rate=rate;

}

//Function to get Account holder Name

void getAccountHolderName()

{

cout<<"\n**********************";

cout<<"\n Bank Account Details";

cout<<"\n***********************";

cout<<"\n Enter account holders name:";

cin>>name;

}

//function to check for balance.

void getBalance()

{

cout<<"\n Enter the current balance:";

cin>>balance;

}

//function to get the interest rate.

void getInterestRate()

{

cout<<"\n Interest rate:"<<rate;

}

//Function to deposite the amount

void putDeposit()

{

cout<<"\n Enter the amount you need to deposit:";

cin>>d;

a=balance+d;

cout<<"\n New balance:"<<a;

}

//function to withdraw the amount

void withdraw()

{

cout<<"\n Enter the amount you want to withdraw:";

cin>>w;

a1=a-w;

cout<<"\n Current balance:"<<a1;

}

//function to calculate the interest

void ApplyInterest()

{

rate=0.3;

i=((balance)*(rate));//interest calculation;

cout<<"\n Interest:"<<i;

}

//function to display

void display()

{

cout<<"\n*****************************";

cout<<"\n Account Holders Information";

cout<<"\n******************************";

cout<<"\n"<<"\t"<<"AccountHolder"<<"\t"<<"Balance"<<"\t"<<"Deposit"<<"\t"<<"Withdrawal"<<"CurrentBalance"<<"InterestRate";

cout<<"\t\t"<<name<<"\t\t"<<balance<<"\t"<<d<<"\t"<<w<<"\t\t"<<a1<<"\t\t"<<i;

}

};

//main function

void main()

{

clrscr();

bankAccount b;

b.getAccountHolderName();

b.getBalance();

b.getInterestRate();

b.putDeposit();

b.withdraw();

b. calcInterest();

b.display();

getch();

}

Output:

Add a comment
Answer #2

bankaccount.h

#ifndef BANKACCOUNT_H
#define BANKACCOUNT_H
#include <string>

class BankAccount {
private:
   std::string accountHolderName ;
   double balance;
   double interestRate; // in dollars
public:
   BankAccount(std::string name, double balance, double rate);
   std::string getAccountHolderName();
   double getBalance();
   double getInterestRate();
   void deposit(double amount);
   void withdraw(double amount);

} ;

#endif

BankAccount.cpp

#include "bankaccount.h"
#include<iostream>
#include <string.h>
using namespace std;
double balance;
double interestRate;

BankAccount::BankAccount(std::string initaccountHolderName, double initbalance,
double initrate) {
balance = initbalance;
accountHolderName = initaccountHolderName;
interestRate = initrate;
}

double BankAccount::getBalance () {
return balance;
}

string BankAccount::getAccountHolderName () {
return accountHolderName;
}


void BankAccount::deposit (double amount) {
balance += amount;
}

double BankAccount::getInterestRate () {
return interestRate;
}

void BankAccount::withdraw (double amount) {
if (balance < amount)
cerr << "Insufficient funds\n";
else
balance -= amount;
}

void applyInterest(){
balance = balance + balance*interestRate;
}

Add a comment
Know the answer?
Add Answer to:
For this lab you must write a complete class in C++. This will be a class...
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
  • How would I alter this code to have the output to show the exceptions for not...

    How would I alter this code to have the output to show the exceptions for not just the negative starting balance and negative interest rate but a negative deposit as well? Here is the class code for BankAccount: /** * This class simulates a bank account. */ public class BankAccount { private double balance; // Account balance private double interestRate; // Interest rate private double interest; // Interest earned /** * The constructor initializes the balance * and interestRate fields...

  • C++ Please create the class named BankAccount with the following properties below: // The BankAccount class...

    C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (name & ID), keeps track of a user's available balance. // It also keeps track of how many transactions (deposits and/or withdrawals) are made. public class BankAccount { Private String name private String id; private double balance; private int numTransactions; // Please define method definitions for Accessors and Mutator functions below Private member variables string getName(); // No set...

  • Write a Java class called BankAccount (Parts of the code is given below), which has two...

    Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...

  • Write a Java class called BankAccount (Parts of the code is given below), which has two...

    Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...

  • [JAVA] < Instruction> You are given two classes, BankAccount and ManageAccounts ManageAccounts is called a Driver...

    [JAVA] < Instruction> You are given two classes, BankAccount and ManageAccounts ManageAccounts is called a Driver class that uses BankAccount. associate a member to BankAcount that shows the Date and Time that Accounts is created. You may use a class Date. To find API on class Date, search for Date.java. Make sure to include date information to the method toString(). you must follow the instruction and Upload two java files. BankAccount.java and ManageAccounts.java. -------------------------------------------------------------------------- A Bank Account Class File Account.java...

  • c++ please    Define the class bankAccount to implement the basic properties of a bank account....

    c++ please    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 func- tions to manipulate an object. Use a static member in the class to automatically assign account numbers. Also declare an array of 10 compo- nents of...

  • Requirements:  Your Java class names must follow the names specified above. Note that they are...

    Requirements:  Your Java class names must follow the names specified above. Note that they are case sensitive. See our template below.  BankAccount: an abstract class.  SavingAccount: a concrete class that extends BankAccount. o The constructor takes client's firstname, lastname and social security number. o The constructor should generate a random 6-digit number as the user account number. o The initial balance is 0 and the annual interest rate is fixed at 1.0% (0.01).o The withdraw method signature...

  • Implement a class Portfolio. This class has two objects, checking and savings, of the type BankAccount....

    Implement a class Portfolio. This class has two objects, checking and savings, of the type BankAccount. Implement four methods: • public void deposit(double amount, String account) • public void withdraw(double amount, String account) • public void transfer(double amount, String account) • public double getBalance(String account) Here the account string is "S" or "C". For the deposit or withdrawal, it indicates which account is affected. For a transfer, it indicates the account from which the money is taken; the money is...

  • java code ============= public class BankAccount { private String accountID; private double balance; /** Constructs a...

    java code ============= public class BankAccount { private String accountID; private double balance; /** Constructs a bank account with a zero balance @param accountID - ID of the Account */ public BankAccount(String accountID) { balance = 0; this.accountID = accountID; } /** Constructs a bank account with a given balance @param initialBalance the initial balance @param accountID - ID of the Account */ public BankAccount(double initialBalance, String accountID) { this.accountID = accountID; balance = initialBalance; } /** * Returns the...

  • Write a unit test to test the following class. Using Java : //Test only the debit...

    Write a unit test to test the following class. Using Java : //Test only the debit method in the BankAccount. : import java.util.*; public class BankAccount { private String customerName; private double balance; private boolean frozen = false; private BankAccount() { } public BankAccount(String Name, double balance) { customerName = Name; this.balance = balance; } public String getCustomerName() { return customerName; } public double getBalance() { return balance; } public void setDebit(double amount) throws Exception { if (frozen) { throw...

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
ADVERTISEMENT