Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Purpose: Demonstrate the ability to create and manipulate classes, data members,

ID: 3533518 • Letter: P

Question

Purpose: Demonstrate the ability to create and manipulate classes, data members, and member

functions. This assignment also aims at creating a C++ project to handle multiple files (one header

file and two .cpp files) at the same time.


Create a C++ project to implement simplified functionalities of a Banking scheme.


Step 1:

Create a header file Bank.h to define a Bank class with the following members:

Data members: The program should implement data hiding, so please define data members

accordingly.

- accountNumber

- balance


Note: The data types are not specified for this problem, so as to give you flexibility to design

the program in your way.


Member functions: Please include only the declaration of the member functions in the header file.

The implementation of member functions will later be done in the Bank.cpp file.


- Bank() constructor with no arguments to create a bank account with a default accountNumber as

9999 and balance value of zero.


- Bank(param1, param2) constructor with two parameters to create a bank account with a specified

accountNumber and balance (as param1 and param2, respectively).


- withdraw(param1) function to withdraw a specified amount (param1) from the account. The

function should first check if there is sufficient balance in the account. If the balance is sufficient,

withdrawal is processed, otherwise display a message to the user that says

Explanation / Answer

#include < iostream >

using namespace std;

//Base class BankAccount

class BankAccount

{

//Data members

public:

int accountNumber;

double balance;

public:

//Constructor

BankAccount(int ano,double bal)

{

accountNumber=ano;

balance=bal;

}

BankAccount() { }

public:

//Accessor methods for getting balance

double getBalance()

{

return(balance);

}

//Accessor methods for getting account number

int getAccountNumber()

{

return(accountNumber);

}

//Mutuator method to set balance

void setBalance(double amount)

{

balance=amount;

}

//Setting account number

void setAccountNumber(int ano)

{

accountNumber=ano;

}


//show account information

void virtual showAccountInfo()

{

cout<<"Account Number :"<<accountNumber<<endl;

cout<<"Account Balance:"<<balance<<endl;

}


//function to perform deposit

double virtual depositAmount(double damount)

{


balance=balance+damount;

return(balance);

}


//withdrawl amount

double virtual withDrawAmount(double wamount)

{

balance=balance-wamount;

return(balance);

}

};//End of class



/***************************************

Checking Account class which is derived

from BankAccount.

****************************************/

class CheckingAccount : BankAccount

{

//Data members

double interest;

double minBal;

double serviceCharge;

public://Constructore

CheckingAccount(int _ano,double _amount,double _interest):BankAccount(_ano,_amount)

{

interest=_interest;

minBal=500;//By default

}

//To set interest rate

void setInterestRate(double irate)

{

interest=irate;

}

//to get interest rate

double retrieveInterestRate()

{

return(interest);

}

//to set minimum balance

void setMinBal(double mbal)

{

minBal=mbal;

}

//To get minimum balance

double retrieveMinBal()

{

return(minBal);

}

//To set service charge

void setServiceCharge(double scharge)

{

serviceCharge=scharge;

}

//To get service charge

double retrieveServiceCharge()

{

return(serviceCharge);

}

//To perform deposit

//overriding base class function

double depositAmount(double damount)

{

balance=balance+damount;

return(balance);

}


//to perform withdraw

//overriding base class function

double withDrawAmount(double wamount)

{

//Checking for account have sufficient balance or not

if(check())

balance=balance-wamount;

else

cout<<"you have in sufficient balance"<<endl;

return(balance);

}

//Check function for verifying balance

bool check()

{

if(balance<minBal)

return(false);

else

return(true);

}

//To display account information

void showAccountInfo()

{

cout<<"Account Number :"<<accountNumber<<endl;

cout<<"Account Balance:"<<balance<<endl;

}

};//End of class



/***************************************

SavingAccount class which is derived

from BankAccount.

****************************************/

class SavingAccount:BankAccount

{

//data member

double minBal;

public:

//Constructor

SavingAccount(int _ano,double _amount):BankAccount(_ano,_amount)

{

minBal=500;

}

//to perform deposit

//overriding base class function

double depositAmount(double damount)

{

balance=balance+damount;

return(balance);

}

//to perform withdraw

//overriding base class function

double withDrawAmount(double wamount)

{

if(check())

balance=balance-wamount;

else

cout<<"you have in sufficient balance"<<endl;

return(balance);

}

//Setting minimum balance

void setMinBal(double mbal)

{

minBal=mbal;

}

//Checking for account sufficiency

bool check()

{

if(balance<minBal)

return(false);

else

return(true);

}

//Showing account information

void showAccountInfo()

{

cout<<"Account Number :"<<accountNumber<<endl;

cout<<"Account Balance:"<<balance<<endl;

}

};//End of class



/*Main function to test above classes*/

int main()

{

//Declaring local variables

double amount;

int choice;

//Displaying menu choices

do

{

cout<<"Create an Account"<<endl;

cout<<"1 Checking Account"<<endl;

cout<<"2 Saving Account"<<endl;

cout<<"3 Exit"<<endl;

//reading choice

cin>>choice;

//if checking account

if(choice==1)

{

cout<<"enter account number";

int ano;

cin>>ano;

cout<<endl<<"enter opening balance";

double obal;

cin>>obal;

double irate;

cout<<endl<<"enter interest rate";

cin>>irate;

CheckingAccount obj(ano,obal,irate);

int ch;

do

{

//ask choice of operations

cout<<"1 Deposit"<<endl<<"2 WithDraw"<<endl<<

"3 Account Info"<<endl<<"4 Exit"<<endl;

cin>>ch;

//Perform selected operation

switch(ch)

{

case 1:

cout<<"Enter amount";

cin>>amount;

double damount;

damount=obj.depositAmount(amount);

cout<<"Available balance: "<<damount<<endl;

break;

case 2:

cout<<"Enter amount";

cin>>amount;

double wamount;

wamount=obj.withDrawAmount(amount);

cout<<"Available balance: "<<wamount<<endl;


break;


case 3:


obj.showAccountInfo();


break;

}//End of switch


}while(ch!=4);

}//end of if


//If choice is savings account

else if(choice==2)

{

//reading needed information

cout<<"enter account number";

int _ano;

cin>>_ano;

cout<<endl<<"enter opening balance";

double _obal;

cin>>_obal;

double _irate;

cout<<endl<<"enter interest rate";

cin>>_irate;

//Creating object for savings account

SavingAccount sObj(_ano,_obal);

int _ch;

do

{

cout<<"1 Deposit"<<endl<<"2 WithDraw"<<endl<<

"3 Account Info"<<"4 Exit"<<endl;

cin>>_ch;

switch(_ch)

{

case 1:

cout<<"Enter amount";

cin>>amount;

double _damount;

_damount=sObj.depositAmount(amount);

cout<<"Available balance: "<<_damount;

break;

case 2:

cout<<"Enter amount";

cin>>amount;

double _wamount;

_wamount=sObj.withDrawAmount(amount);

cout<<"Available balance: "<<_wamount;

break;


case 3:

sObj.showAccountInfo();

break;

case 4:break;

default:cout<<"invalid choice";break;

}//End of switch


}while(_ch!=4);

}//End of else

}while(choice!=3);

}//End of main

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote