Create a base class called shape, this class to store two double type values (value1, value2) that could be used to compute the area of figures. Derive two specific classes called triangle and rectangle from the base shape. Add accessor and mutator function to the base class, to initialize and retrieve base class data members and another member function display_area() to compute and display area of figures.. Make display_area as pure virtual function and provide its definition in the derived class to suit their requirements. Using these three classes, design a program that will accept dimensions of a triangle or a rectangle interactively and display area. Run the above program with following requirements. Provide appropriate constructor in each class. Use constructor function to initialize the data members of base class.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Create a base class called shape, this class to store two double type values (value1, value2) that could be used to compute the area of figures. Derive two specific classes called triangle and rectangle from the base shape. Add accessor and mutator function to the base class, to initialize and retrieve base class data members and another member function display_area() to compute and display area of figures.. Make display_area as pure virtual function and provide its definition in the derived class to suit their requirements.
Using these three classes, design a
Run the above program with following requirements.
- Provide appropriate constructor in each class.
- Use constructor function to initialize the data members of base class.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images