Question

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 type bankAccount to process up to 10 customers and write a program to illustrate how to use your class

A. You will be creating three files. The bankAccount.h file, the implementation of the bankAccount Class cpp file and the test drive cpp file with the main function to test your class.

b. The class needs to have at least these methods:

i. The constructor

ii. Set the data (name, account type, balance, interest rate)

iii. Deposit – receives amount of deposit

iv. Withdraw – receives amount of withdraw

v. Get the Interest Rate – returns the interest rate

vi. Get Account Number – returns the account number

vii. Get the Account Holders Name – returns the name

viii. Get the Account Type – returns the account type

ix. Get the balance – returns the balance

x. Print – nice output of one account and all of its information

c. Your test driver needs to test all of the methods. It needs to allow the user to enter a new account, make a deposit and withdraw. Every time you deposit or withdraw, print all of the account information so the user can see the change was made

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

bankAccount.h

#include <iostream>

#include <vector>

#include <iomanip>

#include <cstdlib>

using namespace std;

class bankAccount

{

private:

static int counter;

string holderName;

int accountNumber;

string accountType;

double balance;

double interestRate;

public:

bankAccount();

bankAccount(string, string, double, double);

string getHolderName();

int getAccountNumber();

string getAccountType();

double getBalance();

double getInterestRate();

void setHolderName(string);

void setAccountType(string);

void setBalance(double);

void setInterestRate(double);

void deposit(double);

void withdraw(double);

void print();

};

bankAccount.cpp

#include "bankAccount.h"

int bankAccount::counter = 0;

bankAccount::bankAccount()

{

this->holderName = "";

this->accountNumber = 0;

this->accountType = "";

this->balance = 0;

this->interestRate = 0;

}

bankAccount::bankAccount(string holderName, string accountType, double balance, double interestRate)

{

this->holderName = holderName;

counter++;

this->accountNumber = counter;

this->accountType = accountType;

this->balance = balance;

this->interestRate = interestRate;

}

string bankAccount::getHolderName()

{

return this->holderName;

}

int bankAccount::getAccountNumber()

{

return this->accountNumber;

}

string bankAccount::getAccountType()

{

return this->accountType;

}

double bankAccount::getBalance()

{

return this->balance;

}

double bankAccount::getInterestRate()

{

return this->interestRate;

}

void bankAccount::setHolderName(string name)

{

this->holderName = name;

}

void bankAccount::setAccountType(string type)

{

this->accountType = type;

}

void bankAccount::setBalance(double balance)

{

this->balance = balance;

}

void bankAccount::setInterestRate(double rate)

{

this->interestRate = rate;

}

void bankAccount::deposit(double amount)

{

this->balance += amount;

}

void bankAccount::withdraw(double amount)

{

if(amount > this->balance || (this->balance - amount) < 0)

{

cout << "Transaction not possible due to insufficient balance!";

}

else

{

this->balance -= amount;

}

}

void bankAccount::print()

{

cout << setprecision(2) << fixed;

cout << "Holder: " << getHolderName() << ", Account Number: " << getAccountNumber() << ", Account Type: " << getAccountType() << ", Interest Rate: " << getInterestRate() << "%, Balance: $" << getBalance() << endl;

}

main.cpp

#include "bankAccount.h"

int main()

{

vector<bankAccount> accounts;

string holderName, accountType;

double balance, interestRate;

// prompt user to add 5 accounts to the list

int numberOfAccounts = 5;

cout << endl;

for(int i = 0; i < numberOfAccounts; i++)

{

cout << "Account " << (i + 1) << ":" << endl;

cout << "Enter account holder name(no spaces): ";

cin >> holderName;

cout << "Enter account type(Savings/Checking): ";

cin >> accountType;

cout << "Enter account initial balance: $";

cin >> balance;

cout << "Enter account interest rate(%): ";

cin >> interestRate;

accounts.push_back(bankAccount(holderName, accountType, balance, interestRate));

cout << endl;

}

// print the list of all accounts

cout << endl << "ALL ACCOUNTS:\n-------------\n";

for(int i = 0; i < numberOfAccounts; i++)

{

accounts[i].print();

}

cout << endl;

// testing for deposit method

int usrAccNumber;

cout << "Testing for deposit() method..." << endl;

cout << "Enter the account number (1 - " << numberOfAccounts << "): ";

cin >> usrAccNumber;

while(usrAccNumber < 1 || usrAccNumber > numberOfAccounts)

{

cout << "Please enter a number between 1 & " << numberOfAccounts << ": ";

cin >> usrAccNumber;

}

double amount;

cout << "Enter the amount to deposit: ";

cin >> amount;

accounts[usrAccNumber - 1].deposit(amount);

// print the list of all accounts

cout << endl << "ALL ACCOUNTS AFTER DEPOSIT:\n-------------\n";

for(int i = 0; i < numberOfAccounts; i++)

{

accounts[i].print();

}

cout << endl;


// testing for withdraw method

cout << endl << endl << "Testing for withdraw() method..." << endl;

cout << "Enter the account number (1 - " << numberOfAccounts << "): ";

cin >> usrAccNumber;

while(usrAccNumber < 1 || usrAccNumber > numberOfAccounts)

{

cout << "Please enter a number between 1 & " << numberOfAccounts << ": ";

cin >> usrAccNumber;

}

cout << "Enter the amount to withdraw: ";

cin >> amount;

accounts[usrAccNumber - 1].withdraw(amount);

// print the list of all accounts

cout << endl << "ALL ACCOUNTS AFTER WITHDRAWAL:\n-------------\n";

for(int i = 0; i < numberOfAccounts; i++)

{

accounts[i].print();

}

cout << endl;

}

*********************************************************************** SCREENSHOT ****************************************************

Add a comment
Know the answer?
Add Answer to:
c++ please    Define the class bankAccount to implement the basic properties of a bank account....
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
  • Define the class bankAccount to implement the basic properties of a bank account. An object of...

    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 process up...

  • C++ Design a class bankAccount that defines a bank account as an ADT and implements the...

    C++ Design a class bankAccount that defines a bank account as an ADT and implements the basic properties of a bank account. The program will be an interactive, menu-driven program. a. Each object of the class bankAccount will hold the following information about an account: account holder’s name account number balance interest rate The data members MUST be private. Create an array of the bankAccount class that can hold up to 20 class objects. b. Include the member functions to...

  • 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...

  • 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...

  • Write one for all three files in c++ E MISLI UCCIONS if Instructions Define the class...

    Write one for all three files in c++ E MISLI UCCIONS if Instructions 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...

  • C++ Define the class bankAccount to implement the basic properties of a bank account. An object...

    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

  • In this, you will create a bank account management system according to the following specifications: BankAccount...

    In this, you will create a bank account management system according to the following specifications: BankAccount Abstract Class contains the following constructors and functions: BankAccount(name, balance): a constructor that creates a new account with a name and starting balance. getBalance(): a function that returns the balance of a specific account. deposit(amount): abstract function to be implemented in both Checking and SavingAccount classes. withdraw(amount): abstract function to be implemented in both Checking and SavingAccount classes. messageTo Client (message): used to print...

  • Please hlep as I've tried this C++ program and keep coming up with the wrong syntax...

    Please hlep as I've tried this C++ program and keep coming up with the wrong syntax somewhere. I need help defining 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...

  • 14 b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount...

    14 b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class inherits members to store the account number and the balance from the base class. A customer with a checking account typically receives interest, maintains a minimum balance, and pays service charges if the balance falls below the minimum balance. Add member variables to store this additional information. In addition to the operations inherited from the base class, this...

  • 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...

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