0% found this document useful (0 votes)
13 views16 pages

CS-116 OOP - Week 4 Classes and Objects Practice in Python

The document outlines a lecture on Classes and Objects in Python for a CS-116 Object Oriented Programming course at NED University. It includes practice problems for students to create various classes such as Student, Vehicle, Employee, Restaurant, and Inventory, along with their attributes and methods. The session aims to enhance understanding of class documentation and practical application of object-oriented programming concepts.

Uploaded by

fyasir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views16 pages

CS-116 OOP - Week 4 Classes and Objects Practice in Python

The document outlines a lecture on Classes and Objects in Python for a CS-116 Object Oriented Programming course at NED University. It includes practice problems for students to create various classes such as Student, Vehicle, Employee, Restaurant, and Inventory, along with their attributes and methods. The session aims to enhance understanding of class documentation and practical application of object-oriented programming concepts.

Uploaded by

fyasir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

NED University of Engineering and Technology

Department of Computer and Information Systems Engineering

CLASSES AND OBJECT IN PYTHON


Practice Problems

CS-116 Object Oriented Programming


Spring 2025
Ms. Fauzia Yasir
CS 116 - Lecture 04
Classes and Object 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

1. Define 5 Student type instances and initialize


all instance attributes with appropriate values.
2. Print consolidated/complete info for each
student
3. Print average marks of each subject.

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

1. Write a Python program to create a Vehicle class


with name ,max_speed, seats, and mileage instance
attributes.
2. Also define all setter and getter methods
3. Define a class attribute color with a default value white. i.e.,
Every Vehicle should be white.
4. Define an instance method seating_capacity() to print name
of vehicle along with its seats
5. The default fare charge of any vehicle is seating capacity *
100. Define an instance method find_fare()
12
CS 116 - Lecture 04
Classes and Object in Python

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:

2. Now add items to the menu.


3. Make table reservations.
4. Take customer orders.
5. Print the menu.
6. Print table reservations.
7. Print customer orders.
Note: Use dictionaries and lists to store the data.
14
CS 116 - Lecture 04
Classes and Object in Python

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.

You might also like