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...



  • 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.


Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here