LEBANESE UNIVERSITY
FACULTY OF ENGINEERING – BRANCH III
Aya Haidar Ahmad
[email protected] Exercice : Class Shapes
Objective:
A. Using Visual Studio, create a new Project .
- Define the base class Shape as an abstract class
- Define an abstract method GetArea() to calculate the area (returns a double)
- Define an abstract method GetPerimeter() to calculate the perimeter (returns a double)
- Define a virtual method Display() to display
B. Define the Rectangle class, inheriting from Shape.
- Declare private fields for the width and height of the rectangle, associate properties to them
- Define a constructor to initialize width and height
- Override the GetArea method to calculate the area of the rectangle
- Override the GetPerimeter method to calculate the perimeter of the rectangle
- Override the Display method to show details specific to the rectangle
C. Deifne the Circle class, inheriting from Shape
-Define the attributes x, y (coordinates of the center), radius, with corresponding properties
-Define a constructor to initialize the attributes
-Override the GetArea method to calculate the area of the circle
-Override the GetPerimeter method to calculate the perimeter of the circle
- A Move method, to change X and Y coordinates
-Override the Display method to show details specific to the circle
NOTE: use Math.PI in the math library
Sem 5 - 2024-2025 LAB OOP C# 2
Exercice : Class Shapes
Objective:
D. Add a class named ColoredCircle having:
- Attributes: x, y, radius (the coordinates of the center) and color
- A constructor to initialize the circle's position, radius, and color
- A Move method to move the circle by adjusting X and Y coordinates
- A Scale method to scale the circle by changing its radius
- GetPerimeter and GetArea methods
-Override the Display method to show details specific to the colored circle
NOTE: You must use inheritance in this part!
Sem 5 - 2024-2025 LAB OOP C# 3
Exercice : Class Shapes
Output:
Sem 5 - 2024-2025 LAB OOP C# 4