[Lab Evaluation] Banking System
Banking System
You are tasked with implementing a banking system in C++ that utilizes inheritance. You have a base class Account
, a derived class SavingsAccount
, and now, we'll introduce two more derived classes: CheckingAccount
and CreditAccount
.
Account Class: Create a base class called Account
with the following attributes and methods:
accountNumber
(int)accountHolderName
(string)balance
(double)deposit(double amount)
- Adds the specified amount to the balance.withdraw(double amount)
- Subtracts the specified amount from the balance (if sufficient funds are available).displayAccountInfo()
- Displays the account number, account holder's name, and current balance.
SavingsAccount Class: Create a derived class called SavingsAccount
that inherits from Account
. This class should have the following additional attributes and methods:
interestRate
(double) - Represents the annual interest rate.calculateInterest()
- Calculates and adds interest to the account balance based on the formula:interest = balance * (interestRate / 100) / 12
. This should be called once a month.- Override the
displayAccountInfo()
method to include the interest rate.
CheckingAccount Class: Create another derived class called CheckingAccount
that inherits from Account
. This class should have the following additional attributes and methods:
transactionFee
(double) - Represents a fee charged for each withdrawal.applyTransactionFee()
- Deducts the transaction fee from the account balance for each withdrawal.- Override the
withdraw(double amount)
method to include the transaction fee.
CreditAccount Class: Create a third derived class called CreditAccount
that inherits from Account
. This class should have the following additional attributes and methods:
creditLimit
(double) - Represents the maximum negative balance allowed.- Override the
withdraw(double amount)
method to check if the withdrawal amount exceeds the credit limit and handle it accordingly.
Your task is to write the C++ code for all four classes (Account
, SavingsAccount
, CheckingAccount
, and CreditAccount
) and demonstrate their functionality. Create objects of each class and perform operations to showcase their unique features. Ensure that you properly demonstrate the inheritance relationships between these classes.
Note: Provide the complete code for all four classes and a code snippet that demonstrates their usage, including deposits, withdrawals, interest calculation, and fee application. Handle the error conditions appropriately.
TestData
- SavingsAccount: 12344, "Ramaguru R", 1000.0, 5.0
- CheckingAccount: 54421, "Anu", 1500.0, 2.0
- CreditAccount: 181818, "Ammu", 500.0, 1000.0
- Deposit 200.0 in SavingsAccount
- Withdraw 1000.0 from CheckingAccount
- Withdraw 1000.0 from CheckingAccount
- Withdraw 500.0 from CreditAccount
- Withdraw 2000.0 from CreditAccount
After every deposit and withdraw print the account details.
Output
Savings Account Information
Account Number: 12344
Account Holder: Ramaguru R
Balance: ₹1205
Interest Rate: 5%
Checking Account Information
Account Number: 54421
Account Holder: Anu
Balance: ₹498
Transaction Fee: ₹2
ERROR: Insufficient funds for withdrawal.
Checking Account Information
Account Number: 54421
Account Holder: Anu
Balance: ₹498
Transaction Fee: ₹2
Credit Account Information
Account Number: 181818
Account Holder: Ammu
Balance: ₹500
Credit Limit: ₹1000
ERROR: Withdrawal exceeds credit limit.
Credit Account Information
Account Number: 181818
Account Holder: Ammu
Balance: ₹500
Credit Limit: ₹1000
Comments