Question: Define a class Shape in c++ having an attribute Area and a pure virtual function Calculate_Area. Also include the following in this class .
Define a class Shape in c++ having an attribute Area and a pure virtual function Calculate_Area. Also include the following in this class
. ● A constructor that initializes Area to zero.
● A method Display_Area() that displays the value of member variable “Area”.
● A virtual method Print_Area() that displays the value of member variable “Area”. Now derive three classes from Shape; Circle having attribute radius, Square having attribute Length and Rectangle having attributes Length and Breadth. Include the following in each class.
● A constructor that takes values of member variables as argument.
● A method Display_Area() that overrides Display_Area() method of Shape class.
● A method Print_Area() that overrides Print_Area() method of Shape class.
● A method Calculate_Area() that calculates the area as follows: Area of Circle= PI* Radius^2 Area of Square=Length^2 Area of Rectangle=Length*Breadth Make a driver program to test above classes.
Step by Step Solution
3.42 Rating (155 Votes )
There are 3 Steps involved in it
include using namespace std class Shape protected double x y public void setd... View full answer
Get step-by-step solutions from verified subject matter experts
