adt week 1
# 1. Student ADT
class Student:
def __init__(self, name, roll_no):
self.name = name
self.roll_no = roll_no
def display(self):
print(f"Student Name: {self.name}, Roll No: {self.roll_no}")
# 2. Employee ADT
class Employee:
def __init__(self, name, emp_id, salary):
self.name = name
self.emp_id = emp_id
self.salary = salary
def display(self):
print(f"Employee Name: {self.name}, ID: {self.emp_id}, Salary: {self.salary}")
def update_salary(self, new_salary):
self.salary = new_salary
# 3. Date ADT
class Date:
def __init__(self, day, month, year):
self.day = day
self.month = month
self.year = year
def display(self):
print(f"Date: {self.day:02d}/{self.month:02d}/{self.year}")
def is_leap_year(self):
if (self.year % 4 == 0 and self.year % 100 != 0) or (self.year % 400 == 0):
return True
return False
# Student
s1 = Student("Alice", 101)
s1.display()
# Employee
e1 = Employee("Bob", 1001, 50000)
e1.display()
e1.update_salary(55000)
print("After salary update:")
e1.display()
# Date
d1 = Date(16, 1, 2026)
d1.display()
print("Leap year?", d1.is_leap_year())
Comments
Post a Comment