Realize the calculation of the areas of a rectangle and a triangle by a base class called "polygon". The class contains a virtual function called "area" which returns 0. The two derived classes are to return their areas by using this function.
Rectangle: length*width
Triangle: length* width/2
Create an instance of each class in the main program.
Then each instance is to reference a polygon object (pointer).
Set the length and width by using the respective pointers and
output their areas.
Additional task: Transform your virtual function into a purely virtual function.
Then change the main function so that it can be compiled.
(The area of polygon is not output)
\ No newline at end of file
Realize the calculation of the areas of a rectangle and a triangle by a base class called "polygon". The class contains a virtual function called "area" which returns 0. The two derived classes are to return their areas by using this function.
Rectangle: length*width
Triangle: length* width/2
Create an instance of each class in the main program.
Then each instance is to reference a polygon object (pointer).
Set the length and width by using the respective pointers and
output their areas.
Additional task: Transform your virtual function into a purely virtual function.
Then change the main function so that it can be compiled.