C++ You are to design and implement bank account usage. A typical bank account w
ID: 3832847 • Letter: C
Question
C++
You are to design and implement bank account usage.
A typical bank account will include: account number, name (first, last), checking balance/interest rate/last updated date, savings balance/interest rate/last updated date. The activities may include (not limited to): open an account; check balance; deposit to checking or saving; cash from checking or saving; transfer from checking/saving to saving/checking.
You will specify the program input and check the output. It is assumed that user will also enter the date of an activity (e.g., today's date).
Note: You code should use class(es) for the design and coding. You will decide how to calculate the interest earned (e.g., by days or months or years)
Explanation / Answer
#include<iostream>
#include<stdlib.h>
using namespace std;
//Create a class BankAccount
class BankAccount
{
//Data members
protected:
int accountNumber;
string firstName;
string lastName;
};//End of class
//Prototype of Saving class
class Saving;
//Create Checking class inherited from BankAccount
class Checking : public BankAccount
{
//Data members
double balance;
double interestRate;
string lastUpdatedDate;
public:
//Member functions
//To create an account
void openAccount()
{
//Accept account information
cout<<" Enter Account Number: ";
cin>>accountNumber;
cout<<" Enter First Name: ";
cin>>firstName;
cout<<" Enter Last Name: ";
cin>>lastName;
cout<<" Enter Initial Balance: ";
cin>>balance;
cout<<" Enter Interest Rate: ";
cin>>interestRate;
cout<<" Enter The Date: ";
cin>>lastUpdatedDate;
}//End of function
//To return balance
double checkBalance()
{
//calculateInterest();
return balance;
}//End of function
//To deposit money
void deposit(double da)
{
balance += da;
}//End of function
//To withdraw money
void withdraw(double wa)
{
//Checks for insufficient fund
if(wa < balance)
balance -= wa;
else
cout<<" Insufficient Balance";
}//End of function
//Calculate interest
void calculateInterest()
{
balance += balance * (interestRate / 100);
}//End of function
//Friend function to transfer fund
friend void transformAmountCS(Checking &c, Saving &s, double amt);
friend void transformAmountSC(Checking &c, Saving &s, double amt);
};//End of class
class Saving : public BankAccount
{
//Data members
double balance;
double interestRate;
string lastUpdatedDate;
public:
//Member functions
//To create an account
void openAccount()
{
cout<<" Enter Account Number: ";
cin>>accountNumber;
cout<<" Enter First Name: ";
cin>>firstName;
cout<<" Enter Last Name: ";
cin>>lastName;
cout<<" Enter Initial Balance: ";
cin>>balance;
cout<<" Enter Interest Rate: ";
cin>>interestRate;
cout<<" Enter The Date: ";
cin>>lastUpdatedDate;
}//End of function
//To return balance
double checkBalance()
{
//calculateInterest();
return balance;
}//End of function
//To deposit money
void deposit(double da)
{
balance += da;
}//End of function
//To withdraw money
void withdraw(double wa)
{
if(wa < balance)
balance -= wa;
else
cout<<" Insufficient Balance";
}//End of function
//To calculate interest
void calculateInterest()
{
balance += balance * (interestRate / 100);
}//End of function
friend void transformAmountCS(Checking &c, Saving &s, double amt);
friend void transformAmountSC(Checking &c, Saving &s, double amt);
};//End of class
//Transfer fund from Checking account to Saving account
void transformAmountCS(Checking &c, Saving &s, double amt)
{
s.balance += amt;
c.balance -= amt;
}//End of function
//Transfer fund from Saving account to Checking account
void transformAmountSC(Checking &c, Saving &s, double amt)
{
c.balance += amt;
s.balance -= amt;
}//End of function
//Main function
int main()
{
int ch;
char type;
double amt;
//Class object created
Saving s;
Checking c;
//Loops till user choice is 6
do
{
//Displays menu and accept choice
cout<<" 1) Open Account 2) Check Balance 3) Deposit 4) Withdraw 5) Transfer 6) Exit. Enter your choice: ";
cin>>ch;
switch(ch)
{
//Create account
case 1:
//Accepts type of account
cout<<" Enter the type of Account: S for Saving Account C for Checking Account";
cin>>type;
if(type == 's' || type == 'S')
{
s.openAccount();
}
else if(type == 'c' || type == 'C')
{
c.openAccount();
}
else
cout<<" Invalid Account Type";
break;
case 2:
cout<<" Enter the type of Account: S for Saving Account C for Checking Account";
cin>>type;
if(type == 's' || type == 'S')
{
cout<<" Current Balance: "<<s.checkBalance();
}
else if(type == 'c' || type == 'C')
{
cout<<" Current Balance: "<<c.checkBalance();
}
else
cout<<" Invalid Account Type";
break;
case 3:
cout<<" Enter the type of Account: S for Saving Account C for Checking Account";
cin>>type;
if(type == 's' || type == 'S')
{
cout<<" Enter the deposit amount: ";
cin>>amt;
s.deposit(amt);
}
else if(type == 'c' || type == 'C')
{
cout<<" Enter the deposit amount: ";
cin>>amt;
c.deposit(amt);
}
else
cout<<" Invalid Account Type";
break;
case 4:
cout<<" Enter the type of Account: S for Saving Account C for Checking Account";
cin>>type;
if(type == 's' || type == 'S')
{
cout<<" Enter the withdraw amount: ";
cin>>amt;
s.withdraw(amt);
}
else if(type == 'c' || type == 'C')
{
cout<<" Enter the withdraw amount: ";
cin>>amt;
c.withdraw(amt);
}
else
cout<<" Invalid Account Type";
break;
case 5:
cout<<" Enter the type of Account: S for Saving Account C for Checking Account";
cin>>type;
if(type == 's' || type == 'S')
{
cout<<" Enter the deposit amount: ";
cin>>amt;
transformAmountSC(c, s, amt);
}
else if(type == 'c' || type == 'C')
{
cout<<" Enter the deposit amount: ";
cin>>amt;
transformAmountCS(c, s, amt);
}
else
cout<<" Invalid Account Type";
break;
case 6:
exit(0);
default:
cout<<" Invalid choice";
}//End of switch
}while(1);//End of while
}//End of function
Output:
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice: 1
Enter the type of Account: S for Saving Account C for Checking Accounts
Enter Account Number: 111
Enter First Name: papu
Enter Last Name: sahu
Enter Initial Balance: 1000
Enter Interest Rate: 10
Enter The Date: 12/4/2017
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice: 1
Enter the type of Account: S for Saving Account C for Checking Accountc
Enter Account Number: 2000
Enter First Name: supri
Enter Last Name: sahu
Enter Initial Balance: 2000
Enter Interest Rate: 12
Enter The Date: 12/4/2017
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice: 2
Enter the type of Account: S for Saving Account C for Checking Accounts
Current Balance: 1000
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice: 2
Enter the type of Account: S for Saving Account C for Checking Accountc
Current Balance: 2000
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice: 3
Enter the type of Account: S for Saving Account C for Checking Account100
Invalid Account Type
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice:
Invalid choice
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice: 2
Enter the type of Account: S for Saving Account C for Checking Accounts
Current Balance: 1000
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice: 3
Enter the type of Account: S for Saving Account C for Checking Accounts
Enter the deposit amount: 100
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice: 2
Enter the type of Account: S for Saving Account C for Checking Accounts
Current Balance: 1100
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice: 3
Enter the type of Account: S for Saving Account C for Checking Accountc
Enter the deposit amount: 400
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice: 2
Enter the type of Account: S for Saving Account C for Checking Accountc
Current Balance: 2400
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice: 4
Enter the type of Account: S for Saving Account C for Checking Account500
Invalid Account Type
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice:
Invalid choice
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice: 4
Enter the type of Account: S for Saving Account C for Checking Accounts
Enter the withdraw amount: 400
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice: 2
Enter the type of Account: S for Saving Account C for Checking Accounts
Current Balance: 700
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice: 4
Enter the type of Account: S for Saving Account C for Checking Accountc
Enter the withdraw amount: 800
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice: 2
Enter the type of Account: S for Saving Account C for Checking Accountc
Current Balance: 1600
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice: 5
Enter the type of Account: S for Saving Account C for Checking Accounts
Enter the deposit amount: 200
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice: 2
Enter the type of Account: S for Saving Account C for Checking Accounts
Current Balance: 500
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice: 2
Enter the type of Account: S for Saving Account C for Checking Accountc
Current Balance: 1800
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice: 5
Enter the type of Account: S for Saving Account C for Checking Accountc
Enter the deposit amount: 800
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice: 2
Enter the type of Account: S for Saving Account C for Checking Accounts
Current Balance: 1300
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice: 2
Enter the type of Account: S for Saving Account C for Checking Accountc
Current Balance: 1000
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice: 4
Enter the type of Account: S for Saving Account C for Checking Accountc
Enter the withdraw amount: 2000
Insufficient Balance
1) Open Account
2) Check Balance
3) Deposit
4) Withdraw
5) Transfer 6) Exit.
Enter your choice: 6
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.