Group 9 Report
Group 9 Report
Group 9 Report
Submitted by
P Sharmila Reddy ( 366)
P Tharun (384)
P Navadeep (357)
Parath Singh (309)
Pratiksha (097)
2024-25
Question 9:-
Assume that a bank maintains two kinds of accounts for customers, one called
as savings and the other as current account. The savings account provides
compound interest and withdrawal facilities but no cheque book facility. The
current account provides cheque book facility but no interest. Current
account holders should also maintain a minimum balance and if the balance
falls below this level a service charge is imposed. Create a class account that
stores customer name, account number and type of account. From this derive
the classes cur_acct and sav_acct to make them more specific to their
requirements
. Include necessary member functions in order to achieve the following tasks:
(a) Accept the deposit from a customer and update the balance.
(b) Display the balance.
c) Compute and deposit interest.
(d) Permit withdrawal and update the balance.
(e) Check for the minimum balance, impose penalty, necessary and update
the balance.
The concepts used in our question are: Front function , Class , Object ,
Inheritance , Consturctors .
SOURCE CODE
#include <iostream>
#include <string>
using namespace std;
class Account {
protected:
string customerName;
int accountNumber;
string accountType;
double balance;
public:
Account(const string &name, int number, const string &type, double
initialBalance = 0.0)
: customerName(name), accountNumber(number), accountType(type),
balance(initialBalance) {}
virtual void deposit(double amount) {
if (amount > 0) balance += amount;
cout << "Deposited: " << amount << ". Current Balance: " << balance
<< endl;
}
virtual void displayBalance() const {
cout << "Account Number: " << accountNumber << endl;
cout << "Account Holder: " << customerName << endl;
cout << "Account Type: " << accountType << endl;
cout << "Current Balance: " << balance << endl;
}
virtual void withdraw(double amount) {
if (amount > 0 && balance >= amount) {
balance -= amount;
cout << "Withdrawn: " << amount << ". Updated Balance: " <<
balance << endl;
} else {
cout << "Insufficient funds or invalid withdrawal amount." << endl;
}
}
virtual void front() const {
// Placeholder for specialization in derived classes
}
};
class CurAcct : public Account {
static constexpr double MIN_BALANCE = 500.0;
static constexpr double SERVICE_CHARGE = 50.0;
public:
CurAcct(const string &name, int number)
: Account(name, number, "Current") {}
void checkMinBalance() {
if (balance < MIN_BALANCE) {
balance -= SERVICE_CHARGE;
cout << "Balance below minimum. Service charge of " <<
SERVICE_CHARGE << " imposed." << endl;
}
}
void front() const override {
cout << "Current Account (Min Balance: " << MIN_BALANCE << ",
Service Charge: " << SERVICE_CHARGE << ")" << endl;
}
};
class SavAcct : public Account {
static constexpr double INTEREST_RATE = 0.05;
public:
SavAcct(const string &name, int number)
: Account(name, number, "Savings") {}
void computeDepositInterest() {
double interest = balance * INTEREST_RATE;
balance += interest;
cout << "Interest of " << interest << " has been deposited." << endl;
}
void front() const override {
cout << "Savings Account (Interest Rate: " << INTEREST_RATE * 100
<< "%)" << endl;
}};
int main() {
SavAcct Sacc("John Doe", 101);
CurAcct Cacc("Jane Smith", 102);
Sacc.front();
Sacc.deposit(1000);
Sacc.computeDepositInterest();
Sacc.displayBalance();
cout << endl;
Cacc.front();
Cacc.deposit(1000);
Cacc.withdraw(600);
Cacc.checkMinBalance();
Cacc.displayBalance();
return 0;
}
OUTPUT
Savings Account (Interest Rate: 5%)
Deposited: 1000. Current Balance: 1000
Interest of 50 has been deposited.
Account Number: 101
Account Holder: John Doe
Account Type: Savings
Current Balance: 1050
Current Account (Min Balance: 500, Service Charge: 50)
Deposited: 1000. Current Balance: 1000
Withdrawn: 600. Updated Balance: 400
Balance below minimum. Service charge of 50 imposed.
Account Number: 102
Account Holder: Jane Smith
Account Type: Current
Current Balance: 350
CONCLUSION:-
In this mini project, we have successfully implemented a banking system using
object-oriented programming (OOP) concepts in C++. We created a base class
Account that serves as the foundation for two derived classes: CurAcct for
current accounts and SavAcct for savings accounts. Each class encapsulates its
specific functionalities, adhering to the requirements outlined in the problem
statement.
The key features of the project include:
1. Deposit Functionality: Both account types allow deposits, and the
balance is updated accordingly.
2. Interest Calculation: The savings account computes and deposits
interest, based on a fixed interest rate.
3. Withdrawal Mechanism: Withdrawals are permitted, and the balance is
adjusted accordingly, with necessary validation for sufficient funds.
4. Minimum Balance Check: The current account checks if the balance
falls below a required minimum, imposing a service charge if necessary.
By using classes, inheritance, and polymorphism, we effectively modeled the
real-world concept of bank accounts with different behaviors and constraints.
The use of a base class (Account) and derived classes (CurAcct and SavAcct)
ensures code reusability and maintains a clear structure.