To design a simple University Portal System using Object-Oriented Programming concepts in Python, demonstrating:
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:
StudentTeacherEach user type should have its own login behavior and protected data.
Create a class User with the following:
nameemail (private โ encapsulation)password (private โ encapsulation)Initialize all attributes using __init__()
login(email, password) โ default login methodshow_info() โ display user information (except password)Userroll_noprogramOverride login() method:
"Student login successful"Override show_info():
Userteacher_iddepartmentOverride login() method:
"Teacher login successful"Override show_info():
Access them only through:
๐ Students should NOT access email or password directly.
Create a function:
def portal_login(user, email, password):
user.login(email, password)
๐ This function should work for both:
โ Same method name (login())
โ Different behavior depending on object type
Student login successful
Welcome: Ali Ahmed
Roll No: 23
Program: BSCS
Teacher login successful
Welcome: Dr. Khan
Department: Computer Science
Teacher ID: T-102
Students should use:
__init__() constructorsuper() to call parent constructorAdd login validation:
"Invalid credentials"logout() method| Concept | Marks |
|---|---|
| Class & Constructor | 5 |
| Inheritance | 5 |
| Encapsulation | 5 |
| Method Overriding | 5 |
| Polymorphism | 5 |
| Output & Logic | 5 |
| Total | 30 Marks |