C++ Design and implement a hierarchy inheritance system of banking, which includ
ID: 3920209 • Letter: C
Question
C++
Design and implement a hierarchy inheritance system of banking, which includes Savings and Checking accounts of a customer. Inheritance and virtual functions must be used and applied, otherwise, there is no credit. The following features must be incorporated:
1. The account must have an ID and customer’s full name and his/her social security number.
2. General types of banking transactions for both accounts, Checking and Savings: withdraw, deposit, calculate interest (based on the current balance, and if it was not modified, there will be no new interest), figure out the balance, and transfer funds (between the two accounts, from Checking to Savings and vice versa).
3. Savings restrictions: Become inactive if the balance falls less than $25, and under such situation, no more activities may be allowed. Also the resulted balance that goes below $25 is not accepted. A $1 charge for each transfer fund (to Checking account), with the first transfer is free. The monthly interest rate is 3.75%.
4. Checking restrictions: A monthly service charge is $5 (automatically be charged when Checking account was opened). A 10 cents charge for each written check, with the first check is free. A $15 charge for each bounced check (not enough funds). The monthly interest rate is 2.5%.
Explanation / Answer
implement a hierarchy inheritance system of banking, which includes Savings and Checking accounts of a customer. Inheritance and virtual functions must be used and applied, otherwise, there is no credit
#include<iostream>
using namespace std;
//A base class named Account is created
class Account
{
protected:
double acc_blnc;
public:
Account(double);
bool credit(double);
bool debit(double);
double getBalance();
void assgn(double);
};
//Parameterized constructor, used to initialize account balance
Account::Account(double blnc)
{
if(blnc<=0.0)
{
cout<<" Invalid amount entered!! ";
acc_blnc=0.0;
}
else
acc_blnc=blnc;
}
//This function is used to assign current balance to the account
void Account::assgn(double bl)
{
acc_blnc=bl;
}
//This function is used to add an amount to the current balance
bool Account::credit(double amount)
{
if(amount<=0.0)
{
cout<<" Transaction unsucessful!!Please enter a valid amount. ";
return false;
}
acc_blnc+=amount;
cout<<" Transaction completed succcessfully... ";
return true;
}
//This function is used to withdraw money from the Account
bool Account::debit(double amount)
{
if(amount<=0.0)
{
cout<<" Transaction unsucessful!!Please enter a valid amount. ";
return false;
}
if(amount>acc_blnc)
{
cout<<" Transaction unsucessful!!Debit amount exceeded account balance... ";
return false;
}
acc_blnc-=amount;
cout<<" Transaction completed succcessfully... ";
return true;
}
//This function is used to return the current balance
double Account::getBalance()
{
return acc_blnc;
}
//Derived class named SavingsAccount is created which is derived from base class Account
class SavingsAccount:public Account
{
protected:
double interest_rate;
public:
SavingsAccount(double,double);
double CalculateInterest();
};
//Parameterized constructor, used to initialize interest rate and receive initial balance
SavingsAccount::SavingsAccount(double balance,double percentage):Account(balance)
{
acc_blnc=balance;
interest_rate=percentage;
}
//This function is used to return the amount of interest earned by an account
double SavingsAccount::CalculateInterest()
{
return acc_blnc*(interest_rate/100);
}
//Derived class named CheckingAccount is created which is derived from base class Account
class CheckingAccount:public Account
{
protected:
double fee;
public:
CheckingAccount(double,double);
double credit(double);
double debit(double);
};
//Parameterized constructor, used to initialize fee charged per transaction and receive initial balance
CheckingAccount::CheckingAccount(double balance,double fee_amount):Account(balance)
{
acc_blnc=balance;
fee=fee_amount;
}
//This function should charge a fee only if money is actually added
double CheckingAccount::credit(double amount)
{
if((amount-fee)>=0.0)
{ amount-=fee;
cout<<" Fee charged succcessfully... ";
}
else
amount=-99;
return amount;
}
//This function should charge a fee only if money is actually withdrawn
double CheckingAccount::debit(double amount)
{
if((amount-fee)>=0.0)
{
amount-=fee;
cout<<" Fee charged succcessfully... ";
}
else
amount=-99;
return amount;
}
int main()
{
double bal;
cout<<"Enter initial account balance:";
cin>>bal;
Account ac(bal);
double i_rate=4.0,fee=30.00;
cout<<" ";
int ch;
while(true)
{
cout<<" BANK --------------------- "" 1.Administrator. 2.Normal user. 3.Exit. ";
cout<<"Enter your choice:";
cin>>ch;
switch(ch)
{
case 1:
cout<<" 1.Change interest rate. 2.Change fee charged per transaction. 3.Add interest to account ";
cout<<"Enter your choice:";
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter new interest rate:";
cin>>i_rate;
break;
case 2:
while(true)
{
cout<<"Enter a new valid amount of fee charged per transaction:";
cin>>fee;
if(fee>=0.0)
break;
cout<<" Invalid amount of fee entered!! ";
}
break;
case 3:
{
SavingsAccount sav(ac.getBalance(),i_rate);
double interest=sav.CalculateInterest();
if((ac.credit(interest)==true))
cout<<" Interest added successfully. ";
}
break;
default:
cout<<"Invalid choice entered!! ";
}
break;
case 2:
cout<<" 1.Deposit balance. 2.Withdraw balance. ";
cout<<"Enter your choice:";
cin>>ch;
switch(ch)
{
case 1:
{
CheckingAccount acc(ac.getBalance(),fee);
cout<<"Enter amount to deposit:";
cin>>bal;
if((ac.credit(bal)==true))
{
bal=acc.credit(ac.getBalance());
if(bal==-99)
{
cout<<" Fee charge is not successful,operation terminated!! ";
return 0;
}
ac.assgn(bal);
}
}
break;
case 2:
{
CheckingAccount acc(ac.getBalance(),fee);
cout<<"Enter amount to withdraw:";
cin>>bal;
if((ac.debit(bal)==true))
{
bal=acc.debit(ac.getBalance());
if(bal==-99)
{
cout<<" Fee charge is not successful,operation terminated!! ";
return 0;
}
ac.assgn(bal);
}
}
break;
default:
cout<<"Invalid choice entered!! ";
}
break;
case 3:
return 0;
default:
cout<<"Invalid choice entered!! ";
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.