0% found this document useful (0 votes)
4 views13 pages

Python Cca

The document is a report on the object-oriented refactoring and enhancement of a procedural banking system in Python, submitted by Shreeka D R as part of a comprehensive continuous assessment at BMS Institute of Technology and Management. It includes both procedural and object-oriented implementations of the banking system, detailing functionalities such as account creation, deposits, withdrawals, and balance checks. Additionally, it discusses the pros and cons of converting from a procedural to an object-oriented programming approach.

Uploaded by

gtshadow2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views13 pages

Python Cca

The document is a report on the object-oriented refactoring and enhancement of a procedural banking system in Python, submitted by Shreeka D R as part of a comprehensive continuous assessment at BMS Institute of Technology and Management. It includes both procedural and object-oriented implementations of the banking system, detailing functionalities such as account creation, deposits, withdrawals, and balance checks. Additionally, it discusses the pros and cons of converting from a procedural to an object-oriented programming approach.

Uploaded by

gtshadow2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT

(An Autonomous Institution, Affiliated to VTU, Belagavi)

Avalahalli, Doddaballapura Main Road, Bengaluru – 560119

DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING

2024-2025/ EVEN SEM

REPORT
on

“Object-Oriented Refactoring and Enhancement of a Procedural Banking


System in Python”

As a part of Comprehensive Continuous Assessment

Submitted by:

SHREEKA D R

(BRANCH/SECTION): MECHANICAL

Submitted to

Asst. Prof. Sowmya K

Assistant Professor, Department of AI & ML

1
Banking Application Procedure Oriented
# Global list to store account information
accounts = []

# Global variable for auto-incrementing account numbers


next_account_number = 1001 # Starting account number

# Function to create a new account


def create_account():
global next_account_number

acc_no = str(next_account_number)
name = input("Enter Account Holder Name: ")
balance = float(input("Enter Initial Deposit: "))
account = [acc_no, name, balance]
accounts.append(account)

print(f"✅ Account created successfully! Your Account Number is: {acc_no}\n")


next_account_number += 1

# Function to find account index by account number


def find_account_index(acc_no):
for i in range(len(accounts)):
if accounts[i][0] == acc_no:
return i
return -1

# Function to deposit amount


def deposit():
acc_no = input("Enter Account Number for Deposit: ")
idx = find_account_index(acc_no)
if idx != -1:
amount = float(input("Enter amount to deposit: "))
accounts[idx][2] += amount
print(f"✅ ₹{amount} deposited. New balance: ₹{accounts[idx][2]}\n")
else:
print("✅ Account not found!\n")

# Function to withdraw amount


def withdraw():
acc_no = input("Enter Account Number for Withdrawal: ")
idx = find_account_index(acc_no)
if idx != -1:
amount = float(input("Enter amount to withdraw: "))
if amount <= accounts[idx][2]:
accounts[idx][2] -= amount
print(f"✅ ₹{amount} withdrawn. Remaining balance:
₹{accounts[idx][2]}\n")
else:
print("✅ Insufficient balance!\n")
else:
print("✅ Account not found!\n")

# Function to check balance


def check_balance():
acc_no = input("Enter Account Number to Check Balance: ")
idx = find_account_index(acc_no)
if idx != -1:
print(f"✅ Current balance for account {acc_no} is ₹{accounts[idx][2]}\n")
else:
print("✅ Account not found!\n")
2
# Function to close account
def close_account():
acc_no = input("Enter Account Number to Close: ")
idx = find_account_index(acc_no)
if idx != -1:
accounts.pop(idx)
print(f"✅ Account {acc_no} closed successfully.\n")
else:
print("✅ Account not found!\n")

# Main menu
def main():
while True:
print("===== BANKING SYSTEM MENU =====")
print("1. Create Account")
print("2. Deposit")
print("3. Withdraw")
print("4. Check Balance")
print("5. Close Account")
print("6. Exit")
choice = input("Enter your choice (1-6): ")

if choice == '1':
create_account()
elif choice == '2':
deposit()
elif choice == '3':
withdraw()
elif choice == '4':
check_balance()
elif choice == '5':
close_account()
elif choice == '6':
print("✅ Exiting... Thank you for using our banking system.")
break
else:
print("✅ Invalid choice! Please try again.\n")

# Run the application


main()

3
Object-Oriented Code:
class Account:
next_account_number = 1001
accounts = []

def __init__(self, name, balance):


self.acc_no = str(Account.next_account_number)
self.name = name
self.balance = balance
Account.next_account_number += 1
Account.accounts.append(self)

def find_account(acc_no):
for account in Account.accounts:
if account.acc_no == acc_no:
return account
return None

def deposit(self, amount):


self.balance += amount
print(f"✅ ₹{amount} deposited. New balance: ₹{self.balance}\n")

def withdraw(self, amount):


if amount <= self.balance:
self.balance -= amount
print(f"✅ ₹{amount} withdrawn. Remaining balance:₹{self.balance}\n")
else:
print("✅ Insufficient balance!\n")

def check_balance(self):
print(f"✅ Current balance for account {self.acc_no} is ₹{self.balance}\n")

def close_account(self):
Account.accounts.remove(self)
print(f"✅ Account {self.acc_no} closed successfully.\n")

def main():
while True:
print("===== BANKING SYSTEM MENU =====")
print("1. Create Account")
print("2. Deposit")
print("3. Withdraw")
print("4. Check Balance")
print("5. Close Account")
print("6. Exit")
choice = input("Enter your choice (1-6): ")

if choice == '1':
name = input("Enter Account Holder Name: ")
balance = float(input("Enter Initial Deposit: "))
account = Account(name, balance)

4
print(f"✅ Account created successfully! Your Account Number is:
{account.acc_no}\n")

elif choice == '2':


acc_no = input("Enter Account Number for Deposit: ")
account = Account.find_account(acc_no)
if account:
amount = float(input("Enter amount to deposit: "))
account.deposit(amount)
else:
print("✅ Account not found!\n")

elif choice == '3':


acc_no = input("Enter Account Number for Withdrawal: ")
account = Account.find_account(acc_no)
if account:
amount = float(input("Enter amount to withdraw: "))
account.withdraw(amount)
else:
print("✅ Account not found!\n")

elif choice == '4':


acc_no = input("Enter Account Number to Check Balance: ")
account = Account.find_account(acc_no)
if account:
account.check_balance()
else:
print("✅ Account not found!\n")

elif choice == '5':


acc_no = input("Enter Account Number to Close: ")
account = Account.find_account(acc_no)
if account:
account.close_account()
else:
print("✅ Account not found!\n")

elif choice == '6':


print("✅ Exiting... Thank you for using our banking system.")
break

else:
print("✅ Invalid choice! Please try again.\n")

main()

5
6
7
OBJECT-ORIENTED CODE: Implemented display all accounts
class Account:
next_account_number = 1001
accounts = []

def __init__(self, name, balance):


self.acc_no = str(Account.next_account_number)
self.name = name
self.balance = balance
Account.next_account_number += 1
Account.accounts.append(self)

def find_account(acc_no):
for account in Account.accounts:
if account.acc_no == acc_no:
return account
return None

def deposit(self, amount):


self.balance += amount
print(f"✅ ₹{amount} deposited. New balance: ₹{self.balance}\n")

def withdraw(self, amount):


if amount <= self.balance:
self.balance -= amount
print(f"✅ ₹{amount} withdrawn. Remaining balance:₹{self.balance}\n")
else:
print("✅ Insufficient balance!\n")

def check_balance(self):
print(f"✅ Current balance for account {self.acc_no} is ₹{self.balance}\n")

def close_account(self):
Account.accounts.remove(self)
print(f"✅ Account {self.acc_no} closed successfully.\n")

def display_all_accounts():
if not Account.accounts:
print("📂 No accounts to display.\n")
else:
print("📂 All Accounts:")
for acc in Account.accounts:
print(f"Account No: {acc.acc_no}, Name: {acc.name}, Balance:
₹{acc.balance}")
print()

def main():
while True:
print("===== BANKING SYSTEM MENU =====")
print("1. Create Account")
print("2. Deposit")
print("3. Withdraw")
print("4. Check Balance")
print("5. Close Account")
print("6. Exit")
8
print("7. Display All Accounts")
choice = input("Enter your choice (1-7): ")

if choice == '1':
name = input("Enter Account Holder Name: ")
balance = float(input("Enter Initial Deposit: "))
account = Account(name, balance)
print(f"✅ Account created successfully! Your Account Number is:
{account.acc_no}\n")

elif choice == '2':


acc_no = input("Enter Account Number for Deposit: ")
account = Account.find_account(acc_no)
if account:
amount = float(input("Enter amount to deposit: "))
account.deposit(amount)
else:
print("✅ Account not found!\n")

elif choice == '3':


acc_no = input("Enter Account Number for Withdrawal: ")
account = Account.find_account(acc_no)
if account:
amount = float(input("Enter amount to withdraw: "))
account.withdraw(amount)
else:
print("✅ Account not found!\n")

elif choice == '4':


acc_no = input("Enter Account Number to Check Balance: ")
account = Account.find_account(acc_no)
if account:
account.check_balance()
else:
print("✅ Account not found!\n")

elif choice == '5':


acc_no = input("Enter Account Number to Close: ")
account = Account.find_account(acc_no)
if account:
account.close_account()
else:
print("✅ Account not found!\n")

elif choice == '6':


print("✅ Exiting... Thank you for using our banking system.")
break

elif choice == '7':


Account.display_all_accounts()

else:
print("✅ Invalid choice! Please try again.\n")

main()

9
10
11
PROS/CONS PROGRAM ORIENTED CONCEPT TO OBJECT
ORIENTED CONCEPT:

 Pros of Converting POP to OOP:


Advantage Explanation
In OOP, related data and methods are grouped inside classes, making the
1. Better Code Organization
code easier to read, debug, and manage.
OOP allows you to reuse classes and methods in multiple programs
2. Reusability
without rewriting the logic.
Easy to add new features (like interest calculation or password protection)
3. Scalability
by just extending classes.
Data (like balance) is hidden inside objects and accessed only through
4. Encapsulation
methods. This protects data integrity.
Objects (like Account, Customer) directly represent real-world entities,
5. Real-world Modeling
making it intuitive.
OOP code is modular, so changes in one class don’t break the whole
6. Maintainability
system.
7. Code Reusability Through
You can create new classes (e.g., Savings Account) from existing ones.
Inheritance

 Cons of Converting to OOP:


Disadvantage Explanation
1. More Complex for Small
For small, simple programs, POP is quicker and easier to write.
Tasks
You often write more lines (classes, objects, methods) compared to
2. More Code Overhead
straightforward POP code.
Beginners need to understand objects, methods, constructors, and
3. Requires OOP Knowledge
inheritance.
4. Slightly Slower for Simple OOP uses more memory and processing compared to POP in small-scale
Programs applications.
Tracking bugs in class hierarchies or object interactions may take more
5. Debugging Can Be Tricky
time.

12
Student USN: 1BY24ME050 Faculty Incharge:

Name: SHREEKA D R Asst. Prof. Sowmya K

Signature

USN - Student Name II SEM , MECH

13

You might also like