Create an application named ShapesDemo that creates several objects that descend from an abstract class called GeometricFigure. Each GeometricFigure includes a height, a width, and an area. Provide get and set accessors for each field except area; the area is computed and is read-only. The class includes an abstract method called computeArea( ) that computes the area of the Geometric Figure.
GeometricFigure base class is provided.
abstract class GeometricFigure
{
protected int height;
protected int width;
protected int area;
public GeometricFigure(int h, int w)
{
Height = h;
Width = w;
}
public abstract double ComputeArea();
public int Height
{
get
{
return height;
}
set
{
height = value;
}
}
public int Width
{
get
{
return width;
}
set
{
width = value;
}
}
public int Area
{
get
{
return area;
}
}
}
Create two additional classes:
In the Main( ) method, implement Rectangle and Triangle objects.
Create an instance of a Rectangle class, that takes height = 10 and width = 5 as input. Display the height, width and the area of the rectangle.
Rectangle rect1 = new Rectangle( 10, 5);
Create another instance of the Triangle class, that takes height = 25 and width = 15 as input. Display the height, width and the area of the Triangle.
Triangle tr1 = new Triangle(25, 15);
Refer to abstract Animal class, inherited Dog and Cat classes, and DemoAnimals program in the textbook included in the section, Creating and Using Abstract Classes.
Sample output:
Area of the rectangle with height = 3 and width = 4 is: 12
Area of the triangle with height = 10 and width = 20 is: 100
Press any key to continue . . .