Page 1 of 1

create one base class Shape and three child classes Circle, Square, and Triangle with the following data members and mem

Posted: Fri Apr 29, 2022 7:12 am
by answerhappygod
create one base class Shape and three child classes Circle,
Square, and Triangle with the following data members and member
functions,
Protected Data Members of class Shape
such as: c_radius, s_area, s_length, s_width, t_base, t_height
(int) c_area, t_area (float) pie = 3.1416 (const int)
Public Member Functions of class Shape such as:
void calculateArea() – It will print “Parent Class is
generic”.
void Display() – It will print “Your Name and Roll Number.
Inherited Data Members of class Circle such as:
It will inherit c_radius and c_area from shape class.
Public Member Functions of class Circle such as:
void calculateArea() – It will take input c_radius and calculate
area and display area of the circle.
void Display() – It will take input c_radius and calculate,
store in c_area and display area of the circle.
Inherited Data Members of class Square such as: It will inherit
s_length, s_width and s_area from shape class.
Public Member Functions of class Square such as:
int calculateArea(int a) – It will initialize s_length and
s_width with a and calculate and return area of the square.
void Display() – It will take input s_length and s_width and
calculate area, store in s_area and display area of the square.
Inherited Data Members of class Triangle such as: It will
inherit t_base, t_height and t_area from shape class.
Public Member Functions of class Triangle such as: float
calculateArea(int b, int h) –
It will initialize t_base and t_height with b and h and
calculate and return area of the triangle.
void Display() – It will take input t_base and t_height and
calculate area, store in t_area and display area of the
triangle.
Do the following operations in main function:
1. Create objects of class Shape, Circle, Square, and Triangle
and call member function calculateArea().
2. Create objects of class Shape, Circle, Square, and
Triangle and call member function Display().