Skip to content
Snippets Groups Projects
Commit 02c9e137 authored by Rudi Buss's avatar Rudi Buss
Browse files

Update Exercise 4 - Polygon.txt

parent 6f2f8a46
No related branches found
No related tags found
No related merge requests found
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.
(The area of polygon is not output)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment