STEP 1: Create the Multifile Project and the Main (Base) Class Create a new proj
ID: 3679961 • Letter: S
Question
STEP 1: Create the Multifile Project and the Main (Base) Class Create a new project that consists of the base class BankAccount. The BankAccount class should contain, at minimum, the following members. It should contain data members to store a bank customer's balance and account number. These should be of different and appropriate data types. It should have function members that do the following: set the account number; return the account number; return the account balance; deposit money into the account; and withdraw money from the account. STEP 2: Create the CheckingAccount Class Derived From the BankAccount Class The class CheckingAccount should contain, at a minimum, the following members. It should contain a data member to keep track of the number of withdrawal transactions made on the account. Whenever a withdrawal is made, this number should be incremented. Override the base class, withdraw-money function, and add the capability to deduct transaction fees from an account using the following guidelines. The checking account is allowed three free transactions. For each successful withdrawal transaction past the three free transactions, there will be a service fee of 50 cents per transaction. The service fee should be deducted from the account balance at the time the transaction is made. If there are insufficient funds in the account balance to cover the withdrawal plus the service fee, the withdrawal should be denied. The function should return a value to indicate whether the transaction succeeded or failed. Transaction fees should be deducted only from successful transactions, but the transaction count should be incremented in either case. STEP 3: Create the SavingsingAccount Class Derived From the BankAccount Class The class CheckingAccount should contain, at a minimum, the following members. It should contain a data member to hold the daily interest rate. The daily interest rate can be calculated from a yearly interest rate by dividing the annual rate by 365. It should contain a data member to keep track of the number of days since the last transaction or balance inquiry. This should be updated using a random-number generator (reference Lab 1) that will return a value representing the number of days between 0 and 7, inclusive. We will assume that this bank is open every day of the year. It should contain a data member to hold the interest earned since the last transaction or balance inquiry. It should contain a function member to set the annual interest rate. Utilize the base-class functions for both withdrawal and deposit operations for the savings account. Override the base-class-balance inquiry function to add calculating and adding interest to the account based on the daily interest rate, the current balance of the account, and the number of days since the last balance inquiry. This should be called only when a balance inquiry is made, not when a deposit or withdrawal transaction or an account number inquiry is made. If there are insufficient funds in the account balance to cover a withdrawal, the withdrawal should be denied. The number of days since the last transaction or balance inquiry and the interest calculations should still be made. A value should be returned to indicate whether a withdrawal transaction succeeded or failed. It should contain a function member to return the interest earned since the last transaction or balance inquiry. It should contain a function member to return the number of days since the last transaction or balance inquiry. STEP 4: Test Program Operation All data-input and data-display operations (cin and cout) should be done in the function main() test program. The test program should create one checking account and one savings account with initial balances of $100 each using the functions defined in the class definitions. The test program should also assign a unique, five-digit account number to each account and assign an annual interest rate of 3% for the savings account. The test program should then display a menu that allows the user to select which option is to be performed on which account, including the following. Make a deposit and specify the amount to a selected or an entered account. Make a withdrawal and specify the amount to a selected or an entered account. Return the balance of a selected or an entered account. For deposit transactions, withdrawal transactions, and balance inquiries, the updated balance and any fees charged or interest earned should also be displayed. For the savings account, the number of days since last transaction should be displayed. Exit the program. Each account operation should display the account number and the account type. Lab Questions Please answer all the lab questions in the text file that is to be turned into the Dropbox. You are not required to copy the question text into your document, but all answers should be listed with the question number they answer. Were any base-class functions called or overloaded in either of the derived classes? If so, list which class and which function, and explain why they were either called or overloaded. Were any derived-class functions not explicitly called by the test program? If so, list which class and function, and explain why this was done. Which access attribute was used for each of the classes derived from the base class? Why was this access attribute chosen?
Explanation / Answer
//Header section
#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
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.