National College of Business Administration & Economics (DHA CAMPUS)
FALL-2024
Subject: Object-Oriented Programming (A)
Assignment 1
Class: BSCS (SCM, A&F, HRM, MKT) Semester – 2th Shift: Weekend
Total 20
Instructor Marks:
Name:
Abdullah Khan Shahani
Student Portal
Name: ID:
Note: Attempt all questions.
Question 1: Classes, Constructors, and Loops (10 Marks)
Create a class Product to manage information about items in a store.
1. Define a class Product with:
o A constructor that initializes the product's name, price, and quantity.
o A method calculate_total_price() that calculates and returns the total price of the product (price ×
quantity).
2. Write a program to:
o Create three Product objects with the following details:
Product 1: Name = "Notebook", Price = 50, Quantity = 4
Product 2: Name = "Pen", Price = 20, Quantity = 10
Product 3: Name = "Eraser", Price = 5, Quantity = 8
o Use a loop to calculate and print the total price for each product.
Question 2: Inheritance and Functions (10 Marks)
Write a Python program to demonstrate inheritance in a Library Management System.
1. Create a base class Library with:
o An attribute books (a list of book titles, initialized in the constructor).
o A method display_books() that prints all the book titles in the library.
2. Create a subclass Borrower that inherits from Library and includes:
o A method borrow_book(book_name) that checks if the requested book is available in the library. If
the book is available, print "You have borrowed [book_name]" and remove it from the list of books.
If not, print "Sorry, [book_name] is not available."
3. Write a program to:
o Initialize the library with the books ["Python Basics", "OOP Concepts", "Data Structures"].
o Create a Borrower object.
o Borrow the book "Python Basics" and then try to borrow "Machine Learning".