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

Exp5 Python OOP FileHandling 1

The document outlines an experiment for a Python course focusing on Object-Oriented Programming and File Handling. It includes exercises for creating systems such as a Hospital Patient Management System, Vehicle Rental System, Online Shopping System, Employee Payroll System, and Banking System, each demonstrating different OOP concepts. Additionally, it covers file handling tasks like managing student results and counting word frequency in a text file.

Uploaded by

adityadey347
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 views8 pages

Exp5 Python OOP FileHandling 1

The document outlines an experiment for a Python course focusing on Object-Oriented Programming and File Handling. It includes exercises for creating systems such as a Hospital Patient Management System, Vehicle Rental System, Online Shopping System, Employee Payroll System, and Banking System, each demonstrating different OOP concepts. Additionally, it covers file handling tasks like managing student results and counting word frequency in a text file.

Uploaded by

adityadey347
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

Course : PAMCA602: Python for Data Science

Experiment 5: Work with OOP and File Handling

Faculty: Dr. L.M. Jenila Livingston

Date: 29-07-2026

Part A – Object-Oriented Programming (5 Questions)

Exercise 1 – Hospital Patient Management System

Scenario

A multi-specialty hospital wants to digitize its patient registration process. Each patient is
assigned a unique Patient ID and their consultation fee depends on the department they visit.
Develop a Python program using Object-Oriented Programming.

Create a class Patient with the following attributes:

• Patient ID
• Patient Name
• Age
• Department
• Consultation Fee

Implement methods to:

• Accept patient details.


• Display patient details.
• Calculate the total payable amount after adding an 18% service charge.

Sample Input

Enter Patient ID : P101


Enter Patient Name : Rahul
Enter Age : 45
Enter Department : Cardiology
Enter Consultation Fee : 800

Expected Output

Patient Details
-------------------------
Patient ID : P101
Patient Name : Rahul
Department : Cardiology
Consultation Fee : ₹800
Service Charge (18%) : ₹144
Total Amount : ₹944

Exercise 2 – Vehicle Rental System (Inheritance)

Scenario

A vehicle rental company rents both Cars and Bikes. The rental charge calculation differs for
each type of vehicle.

Create a base class Vehicle and derived classes Car and Bike.

Implement methods to:

• Accept vehicle details.


• Calculate rental charges.
• Display rental information.

Sample Input 1

Vehicle Type : Car


Vehicle Number : TN74AB1234
Rental Days : 5
Rent per Day : 1500

Expected Output

Vehicle Type : Car


Rental Days : 5
Total Rental Amount : ₹7500

Sample Input 2

Vehicle Type : Bike


Vehicle Number : TN09CD5678
Rental Days : 3
Rent per Day : 500

Expected Output

Vehicle Type : Bike


Rental Days : 3
Total Rental Amount : ₹1500

Sample Input 3

Vehicle Type : Car


Vehicle Number : KL07EF4321
Rental Days : 7
Rent per Day : 1800

Expected Output

Vehicle Type : Car


Rental Days : 7
Total Rental Amount : ₹12600

Exercise 3 – Online Shopping System (Encapsulation)

Scenario

An online shopping website stores customer purchase details. The total bill should be
accessible only through class methods.

Create a class ShoppingCart with private attributes:

• Customer Name
• Product Name
• Quantity
• Price

Implement methods to:

• Accept details.
• Calculate total bill.
• Display bill.

Sample Input

Customer Name : Divya


Product Name : Laptop
Quantity : 2
Price : 45000

Expected Output

Customer Name : Divya


Product Name : Laptop
Total Bill : ₹90000

Exercise 4 – Employee Payroll System (Method Overriding)

Scenario
A company employs both Permanent Employees and Contract Employees. The salary
calculation differs for each category.

Create

• Employee (Base Class)


• PermanentEmployee
• ContractEmployee

Override the salary calculation method.

Salary Calculation Specification

Permanent Employee

Component Percentage
HRA 20% of Basic Salary
DA 10% of Basic Salary

Formula

Gross Salary = Basic Salary + HRA + DA

Contract Employee

Component Percentage
Allowance 15% of Basic Salary

Formula

Gross Salary = Basic Salary + Allowance

Sample Input 1

Employee Type : Permanent


Employee Name : Arun
Basic Salary : 50000

Expected Output

Employee Name : Arun


Employee Type : Permanent

Basic Salary : ₹50000


HRA (20%) : ₹10000
DA (10%) : ₹5000

Gross Salary : ₹65000


Sample Input 2

Employee Type : Contract


Employee Name : Divya
Basic Salary : 40000

Expected Output

Employee Name : Divya


Employee Type : Contract

Basic Salary : ₹40000


Allowance (15%) : ₹6000

Gross Salary : ₹46000

Sample Input 3

Employee Type : Permanent


Employee Name : Rahul
Basic Salary : 65000

Expected Output

Employee Name : Rahul


Employee Type : Permanent

Basic Salary : ₹65000


HRA (20%) : ₹13000
DA (10%) : ₹6500

Gross Salary : ₹84500

Exercise 5 – Banking System (Polymorphism)

Scenario

A bank provides two types of accounts:

• Savings Account
• Current Account

Create a base class Account.

Implement different versions of the calculate_interest() method for each account type using
method overriding.

Interest Calculation Specification


Account Type Interest Rate
Savings Account 4% per annum
Current Account 2% per annum

Formula

Interest = (Balance × Interest Rate) / 100

Final Balance = Balance + Interest

Sample Input 1

Account Type : Savings


Balance : 200000

Expected Output

Savings Account

Account Balance : ₹200000


Interest Rate : 4%
Interest Earned : ₹8000

Final Balance : ₹208000

Sample Input 2

Account Type : Current


Balance : 150000

Expected Output

Current Account

Account Balance : ₹150000


Interest Rate : 2%
Interest Earned : ₹3000

Final Balance : ₹153000

Sample Input 3

Account Type : Savings


Balance : 50000

Expected Output

Savings Account
Account Balance : ₹50000
Interest Rate : 4%
Interest Earned : ₹2000

Final Balance : ₹52000

Part B – File Handling (2 Questions)

Exercise 6 – Student Result File Manager

Scenario

A university wants to maintain the semester results of its students in a text file for future
reference. Develop a Python program to automate this process.

Write a Python program to:

1. Accept the number of students.


2. For each student, accept the following details:
o Register Number
o Student Name
o CGPA
3. Determine the Grade based on the CGPA using the table below.
4. Store the Register Number, Student Name, CGPA, and Grade in a file named
[Link].
5. Read the contents of the file and display all student records in a formatted manner.

Grade Table

CGPA Grade
9.0 – 10.0 S
8.0 – 8.99 A
7.0 – 7.99 B
6.0 – 6.99 C
5.0 – 5.99 D
Below 5.0 F

Sample Input

Enter Number of Students : 2

Enter Register Number : 26MCA1001


Enter Student Name : Anu
Enter CGPA : 8.9

Enter Register Number : 26MCA1002


Enter Student Name : Rahul
Enter CGPA : 9.2

Expected Output

Student Records

26MCA1001 Anu 8.9 A

26MCA1002 Rahul 9.2 S

Exercise 7 – Word Frequency Counter

Scenario

A publishing company wants to analyze the content of a document.

Write a Python program to:

• Read a text file named [Link].


• Count the total number of words.
• Count the occurrences of a user-specified word (case-insensitive).
• Display the results.

Sample Input

[Link]

Python is easy.
Python is powerful.
Python supports OOP.

Program Input

Enter the word to search : python

Expected Output

Total Number of Words : 9

Occurrences of 'python' : 3

You might also like