OOP Lab Exercise in Python | University Portal System
Practice object-oriented programming in Python with a university portal system lab exercise covering classes, inheritance, encapsulation, and polymorphism.
๐ฏ Objective
To design a simple University Portal System using Object-Oriented Programming concepts in Python, demonstrating:
- Constructor usage
- Inheritance
- Encapsulation
- Method Overriding
- Polymorphism
๐ Problem Statement
You are required to build a University Portal System where different types of users (Students and Teachers) can log in and access their information.
The system should be designed using a base class User and two derived classes:
StudentTeacher
Each user type should have its own login behavior and protected data.
๐๏ธ Requirements
๐ท 1. Base Class: User
Create a class User with the following:
Attributes:
nameemail(private โ encapsulation)password(private โ encapsulation)
Constructor:
Initialize all attributes using __init__()
Methods:
login(email, password)โ default login methodshow_info()โ display user information (except password)
๐ท 2. Subclass: Student
Inherits from:
User
Additional Attributes:
roll_noprogram
Methods:
-
Override
login()method:- Show message:
"Student login successful" - Validate email and password
- Show message:
-
Override
show_info():- Display student details
๐ท 3. Subclass: Teacher
Inherits from:
User
Additional Attributes:
teacher_iddepartment
Methods:
-
Override
login()method:- Show message:
"Teacher login successful" - Validate email and password
- Show message:
-
Override
show_info():- Display teacher details
๐ Encapsulation Requirement
-
Email and password must be private attributes
-
Access them only through:
- Getter methods (optional)
- Internal class methods
๐ Students should NOT access email or password directly.
๐ Polymorphism Requirement
Create a function:
def portal_login(user, email, password):
user.login(email, password)๐ This function should work for both:
- Student object
- Teacher object
โ Same method name (login())
โ Different behavior depending on object type
๐งพ Sample Input/Output
Example 1: Student Login
Student login successful
Welcome: Ali Ahmed
Roll No: 23
Program: BSCS
Example 2: Teacher Login
Teacher login successful
Welcome: Dr. Khan
Department: Computer Science
Teacher ID: T-102
๐ป Expected Implementation Structure
Students should use:
__init__()constructorsuper()to call parent constructor- Method overriding in both subclasses
- Private variables for encapsulation
- Polymorphism through function call
โญ Bonus Features (Optional for Extra Marks)
-
Add login validation:
- If email/password is wrong โ show
"Invalid credentials"
- If email/password is wrong โ show
-
Add
logout()method -
Store multiple users in a list and loop login attempts
๐งช Evaluation Criteria (Marks Distribution)
| Concept | Marks |
|---|---|
| Class & Constructor | 5 |
| Inheritance | 5 |
| Encapsulation | 5 |
| Method Overriding | 5 |
| Polymorphism | 5 |
| Output & Logic | 5 |
| Total | 30 Marks |