Skip to main content
Class: S.Y.B. Tech. Semester: III
Subject: Object Oriented Programming Laboratory (PCIT212)
Practical No.: 02
CO1: Develop C++ programs using fundamental programming constructs and object-oriented concepts
for solving practical problems. (BTL-Apply)
---------------------------------------------------------------------------------------------------------------------------------------
1. Aim
To implement a Banking Management System using classes, objects, constructors, destructors, static data
members, friend functions, and dynamic memory allocation in C++.
2. Course Outcome Mapping
CO1: Develop C++ programs using fundamental programming constructs and object-oriented concepts for
solving practical problems.
3. Learning Objectives
After completing this experiment, students will be able to:
1. Understand the concepts of classes and objects in C++.
2. Apply constructors and destructors for object initialization and cleanup.
3. Use static data members to maintain common information among multiple objects.
4. Implement friend functions for controlled access to private class members.
5. Allocate and deallocate memory dynamically using new and delete operators.
6. Design a simple Banking Management System based on real-world banking operations.
4. Learning Outcomes
Upon successful completion of this experiment, students will be able to:
1. Develop object-oriented programs using classes and objects.
2. Design banking applications using constructors, destructors, and dynamic memory allocation.
3. Implement deposit, withdrawal, and balance enquiry operations.
4. Analyze and debug object-oriented C++ programs.
5. Interpret and validate banking transaction outputs.
Sanjivani Rural Education Society’s
Sanjivani College of Engineering, Kopargaon-423603
(An Autonomous Institute Affiliated to Savitribai Phule Pune University, Pune)
NAAC ‘A’ Grade Accredited, ISO 2001:2018 Certified
Department of Information Technology
NBA Accredited-UG Programme
5. Software and Hardware Requirements
1. Software Requirements
 Operating System: Windows/Linux
 Compiler: GCC, MinGW, Code::Blocks, Visual Studio Code
 Programming Language: C++
2. Hardware Requirements
 Intel Core i3 Processor or higher
 4 GB RAM minimum
 10 GB free disk space
6. Real-Time Industry Scenario
Core Banking System (CBS)
Banks such as State Bank of India (SBI), HDFC Bank, ICICI Bank, Axis Bank, and Bank of Baroda
use Core Banking Systems to manage millions of customer accounts efficiently.
A Banking Management System performs operations such as:
 Customer Account Creation
 Cash Deposit
 Cash Withdrawal
 Balance Enquiry
 Interest Calculation
 Transaction Management
Typical Banking Workflow
1. Customer opens a bank account.
2. Initial deposit is recorded.
3. Account details are stored.
4. Deposit and withdrawal transactions are processed.
5. Balance is updated automatically.
6. Account summary is generated.
The Banking Management System developed in this experiment simulates a simplified Core Banking System.
7. Theory
7.1 Classes
Definition:
A class is a user-defined data type that groups data members and member functions into a single unit.
Syntax:
class ClassName
{
// Data Members
// Member Functions
};
7.2 Objects
Definition
An object is an instance of a class.
Syntax
ClassName objectName;
Example
BankAccount acc1;
7.3 Constructors
Definition
A constructor is a special member function that initializes an object automatically when it is created.
Syntax
ClassName()
{
}
Advantages
 Automatic initialization
 Reduces programming errors
 Improves code reliability
7.4 Destructors
Definition
A destructor is automatically invoked when an object is destroyed.
Syntax
~ClassName()
{
}
Industry Usage
Used for releasing memory, closing files, and database connections.
7.5 Static Data Members
Definition
Static members are shared among all objects of a class.
Syntax
static int totalAccounts;
Industry Usage
Used to maintain:
 Total Customers
 Total Employees
 Total Transactions
7.6 Friend Functions
Definition
A friend function can access private members of a class.
Syntax
friend void display(BankAccount);
Advantages
 Controlled data access
 Better modularity
7.7 Dynamic Memory Allocation
Definition
Dynamic memory is allocated during runtime using new and released using delete.
Syntax
BankAccount *acc = new BankAccount;
delete acc;
Industry Usage
Used in:
 Banking Systems
 Hospital Software
 ERP Applications
8. Problem Statement
Design and implement a Banking Management System using C++ object-oriented programming concepts.
The system should perform:
 Create multiple bank accounts
 Deposit amount
 Withdraw amount
 Display account information
 Maintain total number of accounts using a static member
 Display account details using a friend function
 Allocate account objects dynamically using new and release memory using delete
9. Algorithm
1. Start.
2. Create a BankAccount class.
3. Declare account number, customer name, and balance as private data members.
4. Declare a static variable to count total accounts.
5. Create a constructor to initialize account details.
6. Create a destructor.
7. Create member functions:
 Deposit
 Withdraw
 Display Balance
8. Create a friend function to display complete account details.
9. Dynamically allocate memory for account objects.
10. Perform deposit and withdrawal operations.
11. Display account details.
12. Release dynamically allocated memory.
13. Stop.
10. Pseudocode
BEGIN
Create BankAccount Class
Declare
Account Number
Customer Name
Balance
Static TotalAccounts
Constructor initializes values
Destructor releases resources
Friend Function displays account details
Allocate memory using NEW
Input customer details
Deposit Amount
Withdraw Amount
Display Account Details
Display Total Accounts
Delete allocated memory
END
11. Sample Code
#include<iostream>
#include<string>
using namespace std;
class BankAccount
{
private:
int accountNumber;
string customerName;
double balance;
static int totalAccounts;
public:
// Default Constructor
BankAccount()
{
accountNumber = 0;
customerName = "Unknown";
balance = 0;
totalAccounts++;
cout << "nDefault Constructor Called";
}
// Parameterized Constructor
BankAccount(int accNo, string name, double bal)
{
accountNumber = accNo;
customerName = name;
balance = bal;
totalAccounts++;
cout << "nParameterized Constructor Called";
}
// Destructor
~BankAccount()
{
cout << "nDestructor Called for Account : "
<< accountNumber;
}
void deposit(double amount)
{
balance = balance + amount;
}
void withdraw(double amount)
{
if(balance >= amount)
balance = balance - amount;
else
cout<<"nInsufficient Balance.";
}
static void showTotalAccounts()
{
cout<<"nTotal Bank Accounts : "
<<totalAccounts;
}
friend void displayAccount(BankAccount);
};
// Static member initialization
int BankAccount::totalAccounts = 0;
// Friend Function
void displayAccount(BankAccount acc)
{
cout<<"n--------------------------------";
cout<<"nAccount Number : "<<acc.accountNumber;
cout<<"nCustomer Name : "<<acc.customerName;
cout<<"nBalance : "<<acc.balance;
cout<<"n--------------------------------";
}
int main()
{
int n;
cout<<"Enter Number of Customers : ";
cin>>n;
// Dynamic Memory Allocation
BankAccount *account = new BankAccount[n];
int accNo;
string name;
double balance;
double depositAmount;
double withdrawAmount;
for(int i=0;i<n;i++)
{
cout<<"nEnter Account Number : ";
cin>>accNo;
cout<<"Enter Customer Name : ";
cin>>name;
cout<<"Enter Initial Balance : ";
cin>>balance;
account[i] = BankAccount(accNo,name,balance);
cout<<"Enter Deposit Amount : ";
cin>>depositAmount;
account[i].deposit(depositAmount);
cout<<"Enter Withdrawal Amount : ";
cin>>withdrawAmount;
account[i].withdraw(withdrawAmount);
}
cout<<"nn========= ACCOUNT DETAILS =========";
for(int i=0;i<n;i++)
{
displayAccount(account[i]);
}
BankAccount::showTotalAccounts();
delete[] account;
return 0;
}
Sample Input:
Enter Number of Customers : 2
Enter Account Number : 1001
Enter Customer Name : Arun
Enter Initial Balance : 25000
Enter Deposit Amount : 5000
Enter Withdrawal Amount : 3000
Enter Account Number : 1002
Enter Customer Name : Rahul
Enter Initial Balance : 15000
Enter Deposit Amount : 2000
Enter Withdrawal Amount : 5000
Output
Parameterized Constructor Called
Parameterized Constructor Called
========= ACCOUNT DETAILS =========
--------------------------------
Account Number : 1001
Customer Name : Arun
Balance : 27000
--------------------------------
--------------------------------
Account Number : 1002
Customer Name : Rahul
Balance : 12000
--------------------------------
Total Bank Accounts : 2
Destructor Called for Account : 1002
Destructor Called for Account : 1001
12. Conclusion
Thus, a Banking Management System was successfully implemented using classes, objects,
constructors, destructors, static data members, friend functions, and dynamic memory allocation
in C++. The program demonstrated object-oriented programming concepts through real-world banking
operations such as account creation, deposit, withdrawal, balance enquiry, and account management.
13. Viva/Oral Questions
1. What is a class in C++?
2. What is an object?
3. What is the purpose of a constructor?
4. What is a destructor?
5. What is the difference between a constructor and a destructor?
6. What is a static data member?
7. Why are static member functions used?
8. What is a friend function?
9. Why is dynamic memory allocation required?
10. What is the difference between new and malloc()?
11. What is the purpose of the delete operator?
12. What is the difference between delete and delete[]?
13. How does encapsulation improve software design?
14. What happens if dynamically allocated memory is not deallocated?
15. Explain the advantages of object-oriented programming.
Text Books:
1. Object Oriented Programming with C++, E. Balagurusamy, McGraw Hill Education, 8th Edition,
2023.
2. Mastering C++, K. R. Venugopal and Rajkumar Buyya, McGraw Hill Education, 2nd Edition,
2017.
3. Programming with C++, D. Ravichandran, McGraw Hill Education, 3rd Edition, 2018.
Reference Books:
1. Programming Principles and Practice Using C++, Pearson Education, 3rd Edition, 2024.
2. The C++ Programming Language, Bjarne Stroustrup, Addison-Wesley Professional, 4th Edition,
2013.
3. C++ Primer, Stanley B. Lippman, Josée Lajoie, and Barbara E. Moo, Pearson Education, 5th
Edition, 2012.
4. Object-Oriented Programming in C++, Robert Lafore, SAMS Publishing, 4th Edition, 2002.
Prepared By, Approved By,
Mr.A.S.Dalvi Dr. M. A. Jawale
Subject In-charge HOD-IT