Part a) Create a base class called shape. Use this class to store two double type values that could be used to compute the area of figures. Derive two specific classes called triangle and rectangle from the base shape. Add to the base class, a member function get_data() to initialize base class data members and another member function display_area() to compute and display the area of figures. Make display_area() as a virtual function and redefine this function in the derived classes to suit their requirements. Using these three classes, design a program that will accept dimensions of a triangle or a rectangle interactively, and display the area.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter12: Adding Functionality To Your Classes
Section12.4: Class Inheritance And Polymorphism
Problem 5E
icon
Related questions
Question
write c++ code.
Q1.
Part a) Create a base class called shape. Use this class to store two double type values
that could be used to compute the area of figures. Derive two specific classes called
triangle and rectangle from the base shape. Add to the base class, a member function
get_data() to initialize base class data members and another member function
display_area() to compute and display the area of figures. Make display_area() as a virtual
function and redefine this function in the derived classes to suit their requirements.
Using these three classes, design a program that will accept dimensions of a triangle or a
rectangle interactively, and display the area.
Part b) Overload the +' operator in triangle and rectangle classes. The overload function
should add the values of (sides of) two triangles (and similarly the sides of two rectangles)
and make a bigger triangle (and bigger rectangle) and return the area of big triangle(and
big rectangle).
Transcribed Image Text:Q1. Part a) Create a base class called shape. Use this class to store two double type values that could be used to compute the area of figures. Derive two specific classes called triangle and rectangle from the base shape. Add to the base class, a member function get_data() to initialize base class data members and another member function display_area() to compute and display the area of figures. Make display_area() as a virtual function and redefine this function in the derived classes to suit their requirements. Using these three classes, design a program that will accept dimensions of a triangle or a rectangle interactively, and display the area. Part b) Overload the +' operator in triangle and rectangle classes. The overload function should add the values of (sides of) two triangles (and similarly the sides of two rectangles) and make a bigger triangle (and bigger rectangle) and return the area of big triangle(and big rectangle).
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr