Learn with Yasir

Share Your Feedback

๐Ÿงช Lab Task: University Portal System (OOP in Python)


๐Ÿงช Lab Task: University Portal System (OOP in Python)

๐ŸŽฏ 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:

  • Student
  • Teacher

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:

  • name
  • email (private โ†’ encapsulation)
  • password (private โ†’ encapsulation)

Constructor:

Initialize all attributes using __init__()

Methods:

  • login(email, password) โ†’ default login method
  • show_info() โ†’ display user information (except password)

๐Ÿ”ท 2. Subclass: Student

Inherits from:

  • User

Additional Attributes:

  • roll_no
  • program

Methods:

  • Override login() method:

    • Show message: "Student login successful"
    • Validate email and password
  • Override show_info():

    • Display student details

๐Ÿ”ท 3. Subclass: Teacher

Inherits from:

  • User

Additional Attributes:

  • teacher_id
  • department

Methods:

  • Override login() method:

    • Show message: "Teacher login successful"
    • Validate email and password
  • 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__() constructor
  • super() 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"
  • 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