19 08. Basic Interfaces Polymorphism Lab 202110910
19 08. Basic Interfaces Polymorphism Lab 202110910
Shapes
NOTE: You need a public StartUp class with the namespace Shapes.
Build hierarchy of interfaces and classes:
circle.Draw();
rect.Draw();
Examples
Input Output
3 *******
4 ** **
5 ** **
* *
** **
** **
*******
****
* *
* *
* *
****
MathOperation
NOTE: You need a public StartUp class with the namespace Operations.
Examples
Output
5
11
9.9
Solution
Created MathOperation class should look like this:
Animals
NOTE: You need a public StartUp class with the namespace Animals.
Create a class Animal, which holds two fields:
Console.WriteLine(cat.ExplainSelf());
Console.WriteLine(dog.ExplainSelf());
Examples
Output
I am Pesho and my fovourite food is
Whiskas
MEEOW
I am Gosho and my fovourite food is Meat
DJAAF
Solution
Abstract methods:
o CalculatePerimeter(): doulbe
o CalculateArea(): double
Virtual methods:
o Draw(): string
Extend the Shape class with two children:
Rectangle
Circle
Each of them need to have:
Fields:
o height and width for Rectangle
o radius for Circle
Encapsulation for these fields
A public constructor
Concrete methods for calculations (perimeter and area)
Override methods for drawing