CS-116 OOP - Week 4 Classes and Objects Practice in Python
CS-116 OOP - Week 4 Classes and Objects Practice in Python
Last Time . . .
2
CS 116 - Lecture 04
Classes and Object in Python
Today’s Session . . .
Using Python
• More Classes and Objects Examples
• Classes documentation
3
CS 116 - Lecture 04
Classes and Object in Python
Documenting a Class
4
CS 116 - Lecture 04
Classes and Object in Python
Documenting a Class
Output:
5
CS 116 - Lecture 04
Classes and Object in Python
Documenting a Class
Output:
6
CS 116 - Lecture 04
Classes and Object in Python
Practice Problems
7
CS 116 - Lecture 04
Classes and Object in Python
CS 116 - Lecture 04
Classes and Object in Python
Practice Problems
9
CS 116 - Lecture 04
Classes and Object in Python
Practice Problems
10
CS 116 - Lecture 04
Classes and Object in Python
Practice Problems
11
CS 116 - Lecture 04
Classes and Object in Python
Practice Problems
Practice Problem 4
Practice Problems
Practice Problem 5
1. Write a Python class Employee with attributes like emp_id, emp_name, emp_salary, and
emp_department and methods like calculate_emp_salary,emp_assign_department, and
print_employee_details.
Sample Employee Data:
"ADAMS", "E7876", 50000, "ACCOUNTING"
"JONES", "E7499", 45000, "RESEARCH"
"MARTIN", "E7900", 50000, "SALES"
"SMITH", "E7698", 55000, "OPERATIONS“
2. Use 'assign_department' method to change the department of an employee.
3. Use 'print_employee_details' method to print the details of an employee.
4. Use 'calculate_emp_salary' method takes two arguments: salary and hours_worked,
which is the number of hours worked by the employee. If the number of hours worked
is more than 50, the method computes overtime and adds it to the salary. Overtime is
calculated as following formula:
overtime = hours_worked - 50
Overtime amount = (overtime
13 * (salary / 50))
CS 116 - Lecture 04
Classes and Object in Python
Practice Problems
Practice Problem 6
1. Write a Python class Restaurant with attributes like menu_items, book_table, and
customer_orders, and methods like add_item_to_menu, book_tables, and
customer_order.
Perform the following tasks now:
Practice Problems
Practice Problem 7
1. Write a Python class Inventory with attributes like item_id,
item_name, stock_count, and price, and methods like
add_item, update_item, and check_item_details.
2. Use a dictionary to store the item details, where the key is the
item_id and the value is a dictionary containing the item_name,
stock_count, and price.
15
A Quick Recap . . .
Practice Python Syntax for classes and objects.