Define the class bankAccount to store a bank customer’s account number and balan
ID: 3685017 • Letter: D
Question
Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should provide the following operations: • Set the account number • Return the account number • Return the balance • Deposit money into Account • Withdraw money from Account • Print account information (Bank Name, Account number, and account balance) • Add the appropriate constructors. Derive the class checkingAccount from the class bankAccount. A customer 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 class should provide the following operations: • Set interest rate • Return interest rate • Set minimum balance • Return minimum balance • Set service charges • Return service charges • Verify if the balance is less than the minimum balance • Withdraw money from checkingAccount (override the method of the base class) • Add the appropriate constructors What to submit: • The bankAccount.h file • The bankAccount.cpp file • The checkingAccount.h file • The checkingAccount.cpp file • The test.cpp fileExplanation / Answer
CheckingAccount.h
#ifndef CHECKINGACCOUNT_H
#define CHECKINGACCOUNT_H
#include <string>
#include "BankAccount.h"
using namespace std;
class CheckingAccount: public BankAccount{
public:
//Constructors
CheckingAccount();
CheckingAccount(double, int, int, string,double,double);
//Prints info
void print();
private:
//Unique to the derived class:
double overdraftFee;
double minBalance;
};
#endif
BankAccount.cpp
#include "BankAccount.h"
#include <iostream>
#include <string>
using namespace std;
//Default constructor
BankAccount::BankAccount(){
balance = 0; //Double because of cent values
PIN = 1234;
accountNumber = 12345678;
bankName = "Peanut Butter and Jelly, LLC";
}
//Non-default constructor
BankAccount::BankAccount(double b,int p,int a,string bn){
balance = b;
PIN = p;
accountNumber = a;
bankName = bn;
}
//Print a message to the user
void BankAccount::print(){
cout << "This is the base class for the bank account!"<<endl;
cout << "I have basic bank account information!"<<endl;
}
BankAccount.h
#ifndef BANKACCOUNT_H
#define BANKACCOUNT_H
#include <string>
using namespace std;
class BankAccount{
public:
//Constructors
BankAccount();
BankAccount(double,int,int,string);
//Prints a small message to the user
void print();
protected:
//Inherited variables
double balance;
int PIN;
int accountNumber;
string bankName;
};
#endif
CheckingAccount.cpp
#include "CheckingAccount.h"
#include <iostream>
#include <string>
using namespace std;
//Default constructor, which initializes unique and inherited variables:
CheckingAccount::CheckingAccount(){
balance = 0;
PIN = 1234;
accountNumber = 12345678;
bankName = "Joe's Checks and Balances";
overdraftFee = 25.00;
minBalance = 0;
}
//Non-Default constructor:
CheckingAccount::CheckingAccount(double b, int p, int a, string bn,double of,double mb){
balance = b;
PIN = p;
accountNumber = a;
bankName = bn;
overdraftFee = of;
minBalance = mb;
}
//Print some information about the account to the user:
void CheckingAccount::print(){
cout << "Welcome to "<<bankName<<endl;
cout << "This Checking Account is No. " << accountNumber<< " and the PIN is: "<<PIN<<endl;
cout << "The balance is $"<<balance<< " which is "<<((balance>minBalance)?"over":"under")<< " the minimum balance."<<endl;
}
main.cpp
#include "BankAccount.h"
#include "CheckingAccount.h"
#include <iostream>
using namespace std;
int main(){
//Making instances of the base class and each derived class, and calling the print function from each:
BankAccount bank; //Base class default constructor
bank.print();
cout <<endl<<endl;
//Default Constructor call:
CheckingAccount acct;
acct.print();
cout<<endl<<endl;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.