[go: up one dir, main page]

0% found this document useful (0 votes)
45 views3 pages

Assignment 2

The document outlines an assignment for a course on Object Oriented Programming at the University of Management & Technology. It includes four questions requiring the creation of classes for a banking system, employee management, temperature monitoring, and library book tracking, each with specific requirements for data encapsulation and validation. Students are expected to demonstrate their implementations through practical examples for each class.

Uploaded by

nashabrtb
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)
45 views3 pages

Assignment 2

The document outlines an assignment for a course on Object Oriented Programming at the University of Management & Technology. It includes four questions requiring the creation of classes for a banking system, employee management, temperature monitoring, and library book tracking, each with specific requirements for data encapsulation and validation. Students are expected to demonstrate their implementations through practical examples for each class.

Uploaded by

nashabrtb
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/ 3

University of Management & Technology

Department of Artificial Intelligence


School of Systems and Technology
Fall Semester 2025
Instructor’s Name: Sardar Waqar Khan Subject: Object Oriented Programming
Course Code Assignment #: 02
Total Marks 10 Due Date: 02-5-2025

You will submit the handwritten version of assignment.


(CLO-3) (10 marks)

Question # 1:

You are hired to build part of a banking software system.


The bank wants to make sure that no one can directly access or change the customer's account number or
balance from outside the BankAccount class.
Only official transactions like deposit and withdraw should be allowed to modify the balance.
Additionally, customers should be able to view their current balance safely.

Task:

• Model a BankAccount class with private data members: accountNumber and balance.
• Provide public methods: deposit(amount), withdraw(amount), and getBalance().
• Ensure that:
o deposit only allows positive amounts.
o withdraw checks if there are sufficient funds before deducting.

Demonstrate the class by creating an object, depositing money, withdrawing some, and displaying the final
balance.

Question # 2.

An HR software company needs a basic Employee management system.


The HR department must be able to set and get employee names, IDs, and salaries.
However, they need strict control: salaries must never be negative, and no one should directly access
employee information without using functions.

Task:

• Create an Employee class with private attributes: name, id, and salary.
• Write setter and getter functions for each attribute.
• Add validation in the setter of salary to reject negative values.
• Demonstrate the program by creating an Employee, setting values, and printing the employee's details.
Question #3.

You are building software to monitor a cold storage facility where temperatures must stay between -50°C and
150°C.
The temperature values should not be accessible or set freely from outside.

Task:

• Create a TemperatureSensor class with a private attribute temperature.


• Provide public methods to set and get the temperature:
o setTemperature(float) — only allows temperatures between -50°C and 150°C.
o getTemperature() — returns the current value.
• Create an object and test different temperatures to verify validations.

Question # 4.

A small community library wants to keep track of its book stock.


They need to make sure that people can borrow and return books, but the number of copies should never
become negative.
Also, users should not directly change the number of available copies.

Task:

• Create a Book class with private attributes: title, author, and copiesAvailable.
• Provide public methods:
o borrowBook() — decrease copiesAvailable if copies are left.
o returnBook() — increase copiesAvailable when a book is returned.
o getDetails() — print book info and copies available.
• Create a few Book objects and demonstrate borrowing and returning.

You might also like