0% found this document useful (0 votes)
10 views

Csharp Lab Task

The document outlines various programming assignments for a C# course, focusing on concepts of encapsulation, inheritance, and polymorphism. It includes tasks such as implementing classes for a CommissionEmployee, Library Management System, Hospital Management System, Airline Reservation System, Banking System, and more, each requiring specific attributes and methods. The assignments aim to reinforce object-oriented programming principles through practical coding exercises.

Uploaded by

aguzenathaniel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Csharp Lab Task

The document outlines various programming assignments for a C# course, focusing on concepts of encapsulation, inheritance, and polymorphism. It includes tasks such as implementing classes for a CommissionEmployee, Library Management System, Hospital Management System, Airline Reservation System, Banking System, and more, each requiring specific attributes and methods. The assignments aim to reinforce object-oriented programming principles through practical coding exercises.

Uploaded by

aguzenathaniel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

DCIT 201: PROGRAMMING I

ASSIGNMENT 4
INSTRUCTIONS: Answer one (1) question from each section by writing appropriate C# code.

ENCAPSULATION

QUESTION 1.
You are required to create a CommissionEmployee class in C# to represent an employee who earns
compensation based on a percentage of their total sales. The class must enforce encapsulation
principles by restricting direct access to sensitive attributes.

Class
CommissionEmployee

Class Attributes

first_name (string): The employee's first name.


last_name (string): The employee's last name.
social_security_number (string) The employee's social security number.
gross_sales (float): The employee's total gross sales (must be ≥ 0.0).
commission_rate (float): The percentage of gross sales paid as commission (must be between 0.0
and 1.0).

Methods
Constructor – Initializes all attributes . Also prevent the (default) no argument constructor from being
called

Getters and Setters – Update and retrieve class attributees

earnings() - Returns the employee’s earnings using the formula: grossSales *


commissionRate

Implementation Tasks
A. Implement the CommissionEmployee class in C# with proper encapsulation.
B. Create an instance of the CommissionEmployee class.
C. Update the employee’s grossSales and commissionRate, then display the updated details.
D.. Calculate and display the employee’s earnings using the earnings() method.
QUESTION 2.
You are required to implement a Library Management System in C# using encapsulation principles. The
system should manage books and library members, allowing members to borrow and return books while
tracking book availability.

Class 1
Book Class

Class Attributes
book_id (string): Unique identifier for the book.
title (string): Title of the book.
author (string): Author of the book.
available_copies (int): Number of available copies .

Methods

Constructor – Initializes all attributes.

Getters and Setters – Retrieve and update attributes .

borrow_book() – Reduces available_copies by 1 if a copy is available.

return_book() – Increases available_copies by 1.


Class 2
Member Class

Class Attributes
member_id (string): Unique identifier for the member.
name (string): Name of the member.
borrowed_book (Book or Null): Tracks the borrowed book .
-

Methods
Constructor – Initializes member_id and name.

Getters and Setters – Retrieve and update attributes .

borrow_book(Book book) – Allows borrowing if the member has no book and the book is
available.

return_book() – Returns the borrowed book and updates availability.

Implementation Tasks

A.Implement the Book and Member classes in C# with proper encapsulation


B. Creates a book and a member.
C. Simulates borrowing and returning the book.
QUESTION 3.
You are required to implement a Hospital Management System in C# using encapsulation principles.
The system should securely manage patient and doctor details while ensuring proper validation.

Class 1
Patient Class

Class Attributes:

patient_id (string): Unique identifier for the patient.


name (string): Name of the patient.
age (int): Age of the patient (private attribute).
diagnosis (string): Current diagnosis of the patient (private attribute).

Methods

Constructor – Initializes all attributes .

Getters and Setters – Retrieve and update attributes while ensuring data integrity.

setAge(age) – Ensures age is greater than 0; otherwise, prints "Invalid age."

setDiagnosis(String diagnosis) – Ensures diagnosis is not empty; otherwise, prints


"Diagnosis cannot be empty."

Class 2
Doctor Class

Class Attributes
doctor_id (string): Unique identifier for the doctor.
name (string): Name of the doctor.
specialization (string): Doctor’s field of specialization.

Methods

– Initializes doctor_id, name, and specialization.

Getters and Setters – Retrieve and update attributes with proper validation.

treat_patient(patient) – Logs patient_id and diagnosis, then prints "Patient


<patient_id> treated for <diagnosis> successfully."

Implementation Tasks

A. Implement the Patient and Doctor classes in c# with encapsulation.


B. Create a Patient object with the following details:
Patient ID: "P001"
Name: "John Smith"
Age: 45
Diagnosis: "Fever"

C. Creates a Doctor object with the following details:


Doctor ID: "D101"
Name: "Dr. Alice”
Specialization: "General Medicine"

D. Performs the following operations:


Set the patient's diagnosis to "Flu".
Treat the patient and log the treated patient info.
QUESTION 4

You need to design an Airline Reservation System in C# using encapsulation to securely manage flight
details, passenger information, and reservation operations..

Class 1
Flight Class

Class Attributes:
flight_number (string): Unique identifier for the flight.

destination (string): Flight destination.

capacity (int): Total number of seats (private attribute).

booked_seats (int): Seats currently booked (private attribute).

Methods

Constructor – Initializes all attributes.

Getters and Setters – Retrieve and update attribute values with validation.

set_capacity(int capacity) – Ensures capacity is greater than or equal to booked_seats;


otherwise, prints "Invalid capacity: must be at least the number of booked
seats."

book_seat() – Increases booked_seats by 1 if seats are available; otherwise, prints "No


available seats."

cancel_seat() – Decreases booked_seats by 1 if at least one seat is booked; otherwise, prints


"No bookings to cancel."
Class 2
Passenger Class

Class Attributes:

passenger_id (string): Unique identifier for the passenger.


name (string): Passenger's name.
contact_number (string): Passenger's contact number (private attribute).
flight_booked (string or Null): Flight number of the booked flight (initially Null).

Methods

Constructor – Initializes all attributes.

Getters and Setters – Retrieve and update attributes with validation.

set_contact_number(String contact_number) – Ensures contact number is exactly 10


digits; otherwise, prints "Invalid contact number. Must be 10 digits."

book_flight(String flight_number) – Assigns flight_booked to flight_number if


not already booked; otherwise, prints "Passenger already has a booked flight."

cancel_flight() – Sets flight_booked to None if a booking exists; otherwise, prints "No


booking exists to cancel."

Implementation Tasks

A. Implement the Flight and Passenger classes in C# using encapsulation.


B. Creates a Flight object with
Flight Number: "AI101"
Destination: "New York"
Capacity: 200
Booked Seats: 150

C. Creates a Passenger object with


Passenger ID: "P123"
Name: "Sarah Connor"
Contact Number: "9876543210"

D. Performs the following operations


Book a seat for the passenger and update flight details.

Attempt to book again (should not allow duplicate booking).

Cancel the booking and update flight details.

Attempt to cancel again (should not allow cancellation if no booking exists).

Attempt to set an invalid flight capacity (less than booked seats).

Attempt to set an invalid contact number (not 10 digits).

QUESTION 5
Design a Banking System in C# using encapsulation principles. The system should securely manage
customer accounts, transactions, and financial analytics.

Class 1
BankAccount Class

Class Attributes:
account_number (String): The account number of the bank account.
account_holder (String): The name of the account holder.
balance (float): The current balance in the account (must be ≥ 0.0).
interest_rate (float): The annual interest rate for the account (must be between 0.0 and
1.0).
Methods

Constructor: Initializes all attributes while ensuring valid balance and interest rate.
Getters and Setters: Retrieve and updates attributes
deposit(float amount): Adds the specified amount to the balance.
withdraw(flaot amount): Deducts the specified amount from the balance (if sufficient funds are
available).
calculateInterest(): Returns the annual interest earned using the formula: balance *
interest_rate.

Implementation Tasks
A. Implement the BankAccount class with encapsulation in c#.
B. Create an instance of the BankAccount class.
C. Update the account balance and display updated details
D. Calculate and display annual interest earned.

INHERITANCE

QUESTION 1
Extend a CommissionEmployee class into a subclass called BasePlusCommissionEmployee. The system
should manage employees who earn based on commission, and those who have a base salary in
addition to commissions.

Base Class
CommissionEmployee

Class Attributes
first_name (String): The employee’s first name.
last_name (String): The employee’s last name.
social_security_number (String): A unique identifier for the employee.
gross_sales (float): The employee’s total sales amount.
commission_rate (float): The commission percentage (between 0 and 1).

Methods
Constructor: Initializes all attributes.
earnings(): Returns commission earnings (gross_sales * commission_rate).
displayEmployeeDetails(): Prints employee details and their earnings.

Derived Class
BasePlusCommission

Class Attributes
Inherits all fields from CommissionEmployee.
base_salary (float): A guaranteed base salary for the employee.

Methods
Constructor: Calls the superclass constructor and initializes inherited attributes and base_salary.
earnings(): Returns total earnings as base_salary + (gross_sales *
commission_rate).
set_base_salary(float new_salary): Updates the base salary with validation (must be ≥ 0).

Implementation Taaks
A. Create an instance of Commission-Only Employees in C#
B. Create an instance of BasePlusCommission Salary
C. Calculate and Display Earnings on each employee
D. Update baseSalary for a BasePlusCommissionEmployee instance and print the update
earnings.
QUESTION 2

You are tasked with developing a Vehicle Rental Management System using inheritance in C#. The
system should manage different types of vehicles.

Base Class
Vehicle

Class Attributes
vehicle_id (String): Unique vehicle identifier.
brand (String): Brand name of the vehicle.
model (String): Model name.
is_available (Bool): Vehicle availability status (default: True).

Methods
Constructor: Initializes all attributes and sets is_available = True.
rent_vehicle(): If available, marks the vehicle as rented; otherwise, displays an error message.
return_vehicle(): Marks the vehicle as available and confirms the return.

Derived Class
Car

Class Attributes
seating_capacity (int): Number of seats in the car.

Constructor
Initializes all inherited attributes and seating_capacity.

Methods

calculate_rental_cost(int days): Calculates rental cost using the formula 1000 * days
+ seating_capacity * 50. Prints "Rental cost for <days> days: <calculated amount>"
Implementation Tasks
A. Create a Car Instance
B. Rent and return a vehicle
C. Calculate Rental Cost

QUESTION 3
You are tasked with designing an E-Commerce System to manage different types of users and orders
using inheritance principles.

Base Class
User

Class Attributes
user_id (String): Unique identifier for the user.
name (String): User’s full name.

Methods
Constructor: Initializes user_id and name.
print_user_details(): Displays the user’s ID and name.

Derived Class
Customer - Extends User Class

Class Attributes
email: str → Customer’s email address.
cart_item1: str | Null → First item added to the cart.
cart_item2: str | Null → Second item added to the cart.

Methods
Constructor: Calls the parent constructor and initializes
email,cart_item1 and cart_item2 as None.
add_item_to_cart(String item) : Adds an item to the cart.
ViewCart(): Displays cart items if they exist.

Derived Class
Order - Extends Customer Class

Class Attributes
orderId: String → Unique identifier for the order.
orderItem1: String | null → First ordered item.
orderItem2: String | null → Second ordered item.

Methods
Constructor: Calls the parent constructor and initializes orderId.
PlaceOrder(): Transfers cart items to order details and clears the cart.
PrintOrderDetails(): Displays the order ID, customer details, and ordered items.

Implementation Tasks
A. Create Users:
Customer("C001", "Alice", "[email protected]")
Customer("C002", "Bob", "[email protected]")
B.Customers Add Items to Cart:
Alice: "Laptop", "Mouse"
Bob: "Smartphone", "Headphones"

C. Place Orders:
Alice places an order with her cart items.
Bob places an order with his cart items.

E. View Users and Orders:


Print details using PrintUserDetails()() and PrintOrderDetails()

QUESTION 4
You are tasked with designing a Hospital Management System to manage different types of staff and
their roles using inheritance principles.

Base Class
Staff

Class Attributes
staffId (String): Unique identifier for each staff member.
name (String): Name of the staff member.
department (String): Department where the staff member works.

Constructor
Initializes staffId, name, and department.

Methods
displayDetails(): Prints "Staff ID: <staff_id>, Name: <name>,
Department: <department>"
Derived Class
Doctor - Inherits Staff, representing a doctor with a specialization.

Class Attributes
Inherits staffId, name, and department from Staff.
specialization (String): Doctor’s area of expertise.
years_of_experience (int): Number of years the doctor has practiced.

Constructor
Calls the superclass constructor to initialize inherited attributes.
Initializes specialization and years_of_experience

Methods
displayDetails(): Prints
"Doctor ID: <staff_id>, Name: <name>, Department: <department>, Specialization:
<specialization>, Experience: <years_of_experience> years"

Derived Class
Nurse - Inherits Staff, representing a nurse with shift details..

Class Attributes
Inherits staffId, name, and department from Staff.
shift (String): Assigned shift (e.g., "Day", "Night").
patients_assigned (int): Number of patients under care

Constructor
Calls the superclass constructor to initialize inherited attributes.
Initializes shift and patients_assigned
Methods
displayDetails(): Prints
"Nurse ID: <staff_id>, Name: <name>, Department: <department>, Shift: <shift>, Patients
Assigned: <patients_assigned>"

Independent Class
HospitalManagementSystem

Methods
register_doctor(Doctor doctor): Calls display_details() on the Doctor instance.

register_nurse(Nurse nurse): Calls display_details() on the Nurse instance.

Implementation Tasks

A.Create Staff Members:


Doctor("S001", "Dr. Smith", "Cardiology", "Cardiology", 15")
Doctor("S002", "Dr. Lee", "Neurology", "Neurology", 8")
Nurse("S003", "Nurse Kelly", "Emergency", "Night", 5")

B. Register and Display Staff Details:


Call register_doctor() for each doctor.

Call register_nurse() for the nurse


QUESTION 5
You are tasked with designing a Restaurant Management System to manage various staff roles using
inheritance principles. This system will focus on role-specific responsibilities and task delegation.

Base Class
Employee - Represents a general restaurant employee.

Class Attributes
employee_id (String): Unique identifier for the employee.
name (String): Name of the employee.

Constructor
Initializes employee_id and name

Methods
display_details(): Prints "Employee ID: <employee_id>, Name: <name>"

Derive Class
Chef - Represents a chef with additional details.

Class Attributes
Inherits employee_id and name from Employee.
specialty (String): Type of cuisine the chef specializes in.

Constructor
Calls the superclass constructor to initialize inherited attributes.
Initializes specialty.

Methods
display_details(): Prints
"Chef ID: <employee_id>, Name: <name>, Specialty: <specialty>"
prepare_dishes(): Prints
"Chef <name> is preparing <specialty> dishes."
Derive Class
Waiter - Represents a Waiter with additional details.

Class Attributes
Inherits employee_id and name from Employee.
assigned_section (String): Section of the restaurant assigned to the waiter.

Constructor
Calls the superclass constructor to initialize inherited attributes.
Initializes assigned_section

Methods
display_details(): Prints
"Waiter ID: <employee_id>, Name: <name>, Section: <assigned_section>"
serve_customers(): Prints
"Waiter <name> is serving customers in the <assigned_section> section."

Independent Class
RestaurantManagementSystem - Handles employee tasks.

Methods
assign_chef_task(Chef chef): Calls prepare_dishes() on the Chef instance.

assign_waiter_task(Waiter waiter): Calls serve_customers() on the Waiter


instance.

Implementation Tasks
A. Create Employees:
Chef("E001", "Alice", "Italian")
Waiter("E002", "Bob", "Outdoor")
B. Assign Tasks:
Call assign_chef_task() for the chef.
Call assign_waiter_task() for the waiter.

POLYMORPHISM

QUESTION 1

You are tasked with designing a Transportation Management System to handle various types of vehicles
and their operations using polymorphism. The system must demonstrate both runtime polymorphism
(method overriding) and compile-time polymorphism (method overloading).

Abstract Class
Vehicle

Class Attributes

vehicle_id (String): Unique identifier for the vehicle.

model (String): Model name of the vehicle.

fuel_level (float): Current fuel level in liters.

Constructor

Calls the superclass constructor to initialize inherited attributes.


Initializes vehicle_id, model, and fuel_level.

Methods

refuel(float liters): Adds fuel and prints the updated fuel level.
calculate_range(): Abstract method to be implemented in subclasses.

Derive Class
Car - Extends Vehicle

Class Attributes

Inherits vehicle_id, model, and fuel_level from Vehicle.

fuel_efficiency (float): Kilometers per liter.

Constructor
Initializes fuel_efficiency.

Methods

Overrides calculate_Range(): range = fuelLevel * fuelEfficiency. Prints "Car <model> can


travel <range> km with current fuel level."

Independent Class

TransportationManager

Method
operate_vehicle(Vehicle vehicle): Calls calculate_range() on any
Vehicle instance, demonstrating runtime polymorphism.
Implementation Tasks
A. Create Vehicles:
Car("C001", "Sedan", 50, 15)
B. Refuel Sedan using refuel()
C. Use operate_Vehicle() to process all

QUESTION 2
You are tasked with designing a Banking System that demonstrates both compile-time (method
overloading) and run-time polymorphism (method overriding). The system should handle different
types of accounts and operations.

Base Class
BankAccount

Class Attributes

account_Holder_Name (String) – Name of the account holder

account_Number (String) – Unique account number

balance (float) – Current account balance

Constructor

Initializes all attributes

Methods

deposit(float amount): Increases balance and prints the updated balance.

deposit(float amount, String note): Overloaded method that also prints the
transaction note.
withdraw(float amount): Decreases balance if funds are available, else prints an error.

display_Account_Details(): Prints account details (overridden in subclasses).

Derive Class
savingsAccount - Extends Bank Account

Class Attributes

interest_Rate (float) – Annual interest rate

Constructor

Calls the superclass constructor to initialize inherited attributes.

Intializes interest_Rate

Methods

Overrides withdraw(float amount): Prevents withdrawal if balance falls below $100.

calculate_Interest(): Computes annual interest and displays it.

Overrides display_Account_Details(): Includes interest_Rate in account details

Implementation Tasks
A. Create Accounts:
SavingsAccount("Alice", "SA123", 500, 3%)

B. Deposit to savings accounts using one and two arguments.

C. Withdraw from SavingsAccount, testing the minimum balance limit.


D. Display account details for both.

QUESTION 3

You are tasked with designing an E-Commerce System to handle various types of products and dynamic
pricing using polymorphism.

Abstract Class
Product

Class Attributes

product_Id (String) – Unique product ID

product_Name (String) – Name of the product

base_Price (float) – Original price of the product

Constructor

Intializes all attributes

Methods

apply_Discount(float percentage): Reduces price by a given percentage.

calculate_Final_Price(): Abstract method for product-specific price calculations.

Derive Class
Electronics

Class Attributes
warranty_period (int): Warranty duration in months.
Constructor

Calls the superclass constructor to initialize inherited attributes.

Intializes warranty_period

Methods

Overrides calculate_final_price(): Computes final price after warranty-based adjustments.

Derive Class
Clothing

Class Attributes
size (String): Size of the clothing item.

fabric_charge (float): Additional cost based on fabric quality.

Constructor

Calls the superclass constructor to initialize inherited attributes.

Intializes size and fabric_charge

Methods

Overrides calculate_final_price(): Computes final price by adding fabric charges.

Derive Class
Cart
Methods

add_Product(Product product): Adds a product to the cart.

calculateTotalPrice(...products): Overloaded method to calculate total cost for


multiple products.

Implementation Tasks
A. Create Products
Electronics("E001", "Laptop", 1000.0, 24)
Clothing("C001", "Winter Jacket", 200.0, "M", 20.0)

B. Apply 10% discount to Laptop

C. Calculate final price of Laptop and Winter Jacket.

D. Add both to Cart and calculate total price

QUESTION 4

You are tasked with designing a Staff Management System for an organization. The system must
demonstrate polymorphism to calculate staff Annual salary

Abstract Class
StaffMember

Class Attributes

name (String) – Staff member’s name

id (String) – Unique identifier

Constructor
Initializes all attributes

Methods

get_Annual_Salary(): Abstract method to calculate annual pay.

toString(): Returns staff details.

Derive Class
Staff

Constructor

Calls the superclass constructor to initialize inherited attributes.

Methods

add_Staff(StaffMember staff): Adds a staff member.

get_Annual_Salary(int monthly_Salary): Computes total monthly salary.

display_Staff(): Prints staff details.

Implementation Tasks
A. Create a staff Member
B. Display Staff Details
C. Calculate total Annual Salary

QUESTION 5

You are tasked with designing a Church Management System that demonstrates method overriding
(runtime polymorphism) and method overloading (compile-time polymorphism).
Abstract Class
StaffMember

Class Attributes

name (String): Member’s name.

member_Id (String): Unique identifier.

Constructor
Initializes name and member_Id.

Methods
get_Contribution(): Returns 0.0 (default for general members).
give_Offering( double amount): Prints "Offering given: <amount>".

Derive Class
Pastor - Inherits ChurchMember

Class Attributes
tithe (double): Monthly tithe contribution.

Constructor
Initializes name, member_Id, and tithe

Methods
Override get_Contribution(): Returns tithe.
Overload give_Offering(double amount, String message): Prints "Offering
given: <amount>. Note: <message>".

Implementation Tasks
A. Create Staff Members
StaffMember("John Doe", "M001") for a general memnber
Pastor("Rev. Smith", "P001", 500.0)

B. Check Contributions : get_contribution() for both members.

C. Give Offerings:
General member calls give_offering(100.0).
Pastor calls give_offering(200.0, "For the church renovation").

ABSTRACTION

QUESTION 1
You are tasked with implementing abstraction in a payroll system using C#. The system
should define an abstract Employee class as a base for different types of employees.

Abstract Class
Employee

Encapsulated Class Attributes


name (String): Employee’s name.
employee_id (String): Unique identifier.

Constructor
Initializes name and employee_id.

Methods
Getter methods: Provide access to name and employee_id.
Abstract method calculate_pay(): Must be implemented by subclasses.

Derive Class
FullTimeEmployee - Extends Employee
Encapsulated Class Attributes
salary (float): The full-time employee’s salary.

Constructor
Initializes name, employee_id, and salary.

Methods
get_salary(): Returns salary
Implement calculate_pay() to return: "FullTimeEmployee Pay: <salary>".

Implementation Tasks
A. Create the abstract Employee class with the specified attributes and methods in C#
B. Implement the FullTimeEmployee subclass and define calculate_pay().
C. Instantiate a FullTimeEmployee object.
D. Display the employee’s details using the getter methods.

QUESTION 2
You are tasked with designing a Medical Record Management System using C#. The
system should enforce abstraction by defining a base class for different types of medical
personnel while allowing specific roles and specializations to vary.

Abstract Class
MedicalPersonnel

Encapsulated Class Attributes


name (String): The name of the medical personnel.
id (String): A unique identifier for the personnel.
Constructor
Initializes name and id.

Methods
Getter methods: Provide access to name and id.
perform_duties(): Defines the duties of medical personnel (must be implemented in subclasses).
get_specialization(): Defines the specialization of the personnel (must be implemented in
subclasses).
display_details(): Prints the name and ID of the personnel.

Derive Class
Doctor - Extends MedicalPersonnel

Encapsulated Class Attributes


specialization (String): The medical specialty (e.g., Cardiologist, Pediatrician).

Constructor
Initializes name, id, and specialization.

Methods
Implement perform_duties() to return:
"Doctor <name>: Diagnoses patients, prescribes medication, and conducts surgeries."

Implement get_specialization()to return specialization.

Derive Class
Nurse - Extends MedicalPersonnel
Encapsulated Class Attributes
department (String): The department the nurse works in (e.g., ICU, Emergency).

Constructor
Initializes name, id, and department.

Methods
Implement perform_duties() to return:
"Nurse <name>: Provides patient care, administers medications, and assists doctors."
Implement get_specialization() to return department

Implementation Tasks
A. Create the MedicalPersonnel abstract class with the required methods.
B. Implement the Doctor subclass, ensuring they define perform_duties() and
get_specialization().
C. Write statements to:
Create a list of at least one Doctor, one Nurse.
Use a loop to:

Call display_details() for each object.


Call perform_duties() for each object.
Call get_specialization() for each object.
QUESTION 3
You are tasked with designing a Device Management System for a tech company that manages different
types of devices used by employees. The system must use abstraction to provide a blueprint for
handling various device operations while allowing specific implementations for different device types.

Abstract Class
Device

Class Attributes
device_id (String): Unique identifier.
brand (String): Device brand.
model (String): Device model.

Constructor
Initializes device_id, brand, and model

Abstract Methods
calculate_power_consumption(): Computes power consumption in kWh.
calculate_maintenance_cost(): Computes yearly maintenance cost.
getDetails(): Returns device details.

Derive Class
Laptop - Extends Device

Class Attributes
processor_power (float): Processor power in watts.

daily_usage_hours (float): Daily usage in hours.

maintenance_cost_per_year (float): Fixed yearly maintenance cost.


Constructor
Initializes all class fields including inherited ones

Methods
Override calculate_power_consumption(): (processorPower *
dailyUsageHours * 365) / 1000

Override calculate_maintenance_cost(): returns maintenanceCostPerYear

Override getDetails(): Returns device details.

Implementation Tasks
A. Create a Laptop instance
B. Display Device details.
C. Display Power consumption.
D. Display Maintenance cost.

QUESTION 4
You are tasked with creating a 2D Shape Management System for a design application that allows users
to manage, resize, and render various 2D shapes. Use abstraction to define the core operations for all
shapes and provide specific implementations for different shape types.

Interface
shape2D

Methods:
draw(): Displays the shape's details.
resize(float factor): Scales the shape by a given factor.
move(float delta_x, float delta_y): Adjusts the shape's position

Class
Rectangle - Implements 2D interface
Class Attributes

color: String → Defines the rectangle’s color.

position_x: float → X-coordinate of the rectangle.

position_y: float → Y-coordinate of the rectangle.

width: float → Width of the rectangle.

height: float → Height of the rectangle.

Constructor:
Initializes all attributes.

Methods:
draw(): Prints the rectangle’s color, position, width, and height.
resize(float factor): Scales width and height by factor.
move(float delta_x, float delta_y): Updates position based on the given deltas.

Class
shapeManager

Class Atrributes
Shape(Shape2D): Stores a Shape2D object.

Methods
add_shape(Shape2D shape): Adds a new shape to the manager.

draw_shape(): Calls draw() on all stored shapes.

resize_shape(float factor): Resizes all shapes by the given factor.


move_shape(float delta_x, float delta_y): Moves all shapes by the
given deltas.

Implementation Tasks
A. Create Shapes:
Rectangle: Red, (2,3), 5,10.

B. Add to ShapeManager and perform:

● Draw the rectangle.


● Resize rectangle by 2.0x.
● Move rectangle (-1.0,1.0), then draw again.

QUESTION 5

Design a University Management System in C# for managing departments, hostels, and


students. The system should use interfaces for abstraction

Interface
Department
Attributes
dept_name(String)→ Name of the department.
dept_head(String) → Head of the department.

Methods:
print_department_details(): Displays department details.

Class
Student - Implements department

Class Atrributes
student_name(String)→ Student’s full name.

regd_no(String)→ Student’s registration number.

elective_subject(String)→ Elective subject of the student.

avg_marks(float) → Student’s average marks.

hostel_name(String)→ Name of the assigned hostel.

hostel_location(String)→ Location of the hostel.

number_of_rooms(int)→ Number of rooms in the hostel.

Methods
set_student_details(): Inputs and assigns student details, including
department and hostel.
get_student_details(): return all student information.

Implements print_department_details(): Prints department details.

migrate_hostel(String new_hostel, String new_location, int


new_rooms): Updates the student’s hostel details.

Class
UniversityManager

Class Atrributes
student_record(Student) → Stores a single student's information at a time.

Methods
admit_student(Student student): Assigns the given student as the current
record.

display_student_details(): Prints the details of the stored student.

update_hostel(String new_hostel, String new_location,int


new_rooms): Modifies the hostel details of the stored student.

Implementation Tasks
A. Define Interface for Departments
B. Create a Student class that implements Department.
C. Create a UniversityManager class to handle student-related operations.
D. Admit a new student by providing all necessary details.
E. Migrate a student by updating their hostel details.
F. Display student details using displayStudentDetails()

You might also like