OOP Report
OOP Report
Kompjuterikë 2
Introduction:
Model the classes (in terms of OOP) along with their attributes and operations define the class
hierarchy and create a class diagram with Visual Studio.
Solution Approach:
Implementation:
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
Write appropriate constructors for each class, and encapsulate data using properties.
Implementation:
public class Human
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
// Testing
internal class Program
{
private static void Main()
{
Student student = new Student { FirstName = "Alice", LastName = "Johnson", Mark = 95 };
Worker worker = new Worker { FirstName = "Bob", LastName = "Smith", Wage = 1500, HoursWorked = 40 };
Console.WriteLine($"Student: {student.FirstName} {student.LastName}, Mark: {student.Mark}");
Console.WriteLine($"Worker: {worker.FirstName} {worker.LastName}, Hourly Wage:
{worker.CalculateHourlyWage()}");
}
}
Initialize an array of 10 students and sort them by mark in ascending order. Use the interface
System.IComparable<T>.
Implementation:
public class Human
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
Array.Sort(students);
Implementation:
public class Human
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
Array.Sort(workers);
Create an array of different shapes and calculate the area of each shape in another array.
Implementation:
public abstract class Shape
{
public double Width { get; set; }
public double Height { get; set; }
- Area: 20
Area: 24
Area: 28.274333882308138