Learning from the "Pointers-Inheritance and Dynamic Polymorphism" and "Pointers and Dynamic Memory - new - delete" example code in the files above, create three classes that exhibit dynamic polymorphism using the functions area(), circumference(), and draw():      Polygon Class Superclass Variables: double width double height Polymorphic Member Functions: area() circumference() draw() Rectangle Class Subclass of Polygon Variables: int size = 5 double* history_width_ptr double* history_height_ptr Constructor/Destructor Constructor creates space in free memory for two arrays that can store previous values of width and height: history_width_ptr = new double[size] // allocate new memory to previous width values history_height_ptr = new double[size] // allocate new memory to previous height values Destructor delete[] history_width_ptr delete[] history_height_ptr Regular Member Functions: set_values()   Sets values for height and width based upon user input Then stores previous values (if any) into the two arrays in free storage pointed at by history_width_ptr and history_height_ptr get_values() Display the current width and height values get_historical_values() Display the historical width and height values Polymorphic Member Functions: area() circumference() draw() Example output ----------------- |                   | ----------------- You don’t have to draw to scale, but show show a symbolic example of a rectangle Right_Triangle Class Subclass of Polygon Polymorphic Member Functions: area() circumference() draw()        Learning from the "this Pointer and Methods/Functions Chaining" example code in the files above, add method/function chaining to class Rectangle. Using this-> and the return *this within your chaining functions: Add these methods/functions: get_width() multiply_by_height() multiply_by_depth() display_volume()   Within main() Create a program that constructs the class objects and demonstrates their functionalities including: Demonstrating dynamic polymorphism by calling the polymorphic member functions: area(), circumference(), and draw() Using pointers within the calls to these functions. Demonstrate dynamic memory through the use of the history arrays in free storage (the heap) used by Rectangle objects. Fill the two arrays with historical values of width and height and display their values. Demonstrate methods/functions chaining by calling up these functions through a Rectangle object in main. And any other way of showing off your code that you can think of.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
  • Learning from the "Pointers-Inheritance and Dynamic Polymorphism" and "Pointers and Dynamic Memory - new - delete" example code in the files above, create three classes that exhibit dynamic polymorphism using the functions area(), circumference(), and draw():

    

    • Polygon Class
      • Superclass
      • Variables:
        • double width
        • double height
      • Polymorphic Member Functions:
        • area()
        • circumference()
        • draw()
    • Rectangle Class
      • Subclass of Polygon
      • Variables:
        • int size = 5
        • double* history_width_ptr
        • double* history_height_ptr
      • Constructor/Destructor
        • Constructor creates space in free memory for two arrays that can store previous values of width and height:
          • history_width_ptr = new double[size] // allocate new memory to previous width values
          • history_height_ptr = new double[size] // allocate new memory to previous height values
        • Destructor
          • delete[] history_width_ptr
          • delete[] history_height_ptr
      • Regular Member Functions:
        • set_values()  
          • Sets values for height and width based upon user input
          • Then stores previous values (if any) into the two arrays in free storage pointed at by history_width_ptr and history_height_ptr
        • get_values()
          • Display the current width and height values
        • get_historical_values()
          • Display the historical width and height values
      • Polymorphic Member Functions:
        • area()
        • circumference()
        • draw()
          • Example output

-----------------

|                   |

-----------------

        • You don’t have to draw to scale, but show show a symbolic example of a rectangle
    • Right_Triangle Class
      • Subclass of Polygon
      • Polymorphic Member Functions:
        • area()
        • circumference()
        • draw()

      

  • Learning from the "this Pointer and Methods/Functions Chaining" example code in the files above, add method/function chaining to class Rectangle.
    • Using this-> and the return *this within your chaining functions:
      • Add these methods/functions:
        • get_width()
        • multiply_by_height()
        • multiply_by_depth()
        • display_volume()

 

  • Within main()
    • Create a program that constructs the class objects and demonstrates their functionalities including:
      • Demonstrating dynamic polymorphism by calling the polymorphic member functions: area(), circumference(), and draw()
        • Using pointers within the calls to these functions.
      • Demonstrate dynamic memory through the use of the history arrays in free storage (the heap) used by Rectangle objects.
        • Fill the two arrays with historical values of width and height and display their values.
      • Demonstrate methods/functions chaining by calling up these functions through a Rectangle object in main.
    • And any other way of showing off your code that you can think of.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY