C++ Design and implement a hierarchy inheritance system of banking, which includ
ID: 3919014 • 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
SOLUTION:
According to the given data the following code is given :
#include<iostream>
using namespace std;
class Account
{
protected:
double acc_blnc;
public:
Account(double);
bool credit(double);
bool debit(double);
double getBalance();
void assgn(double);
};
Account::Account(double blnc)
{
if(blnc<=0.0)
{
cout<<" Invalid amount entered!! ";
acc_blnc=0.0;
}
else
acc_blnc=blnc;
}
void Account::assgn(double bl)
{
acc_blnc=bl;
}
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;
}
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;
}
double Account::getBalance()
{
return acc_blnc;
}
class SavingsAccount:public Account
{
protected:
double interest_rate;
public:
SavingsAccount(double,double);
double CalculateInterest();
};
SavingsAccount::SavingsAccount(double balance,double percentage):Account(balance)
{
acc_blnc=balance;
interest_rate=percentage;
}
double SavingsAccount::CalculateInterest()
{
return acc_blnc*(interest_rate/100);
}
class CheckingAccount:public Account
{
protected:
double fee;
public:
CheckingAccount(double,double);
double credit(double);
double debit(double);
};
CheckingAccount::CheckingAccount(double balance,double fee_amount):Account(balance)
{
acc_blnc=balance;
fee=fee_amount;
}
double CheckingAccount::credit(double amount)
{
if((amount-fee)>=0.0)
{ amount-=fee;
cout<<" Fee charged succcessfully... ";
}
else
amount=-99;
return amount;
}
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!! ";
}
}
}
Therefore by using the above data we can can get our required output
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.