Pages

Monday, 15 June 2020

Chapter 14 // Exercise 12 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2017 and the graphics files found here:
https://github.com/l-paz91/principles-practice/tree/master/Graphics%20Files

Chapter 14 // Exercise 12

Modify Binary_tree to draw its nodes using a virtual function. Then, derive a new class from Binary_tree that overrides that virtual function to use a different representation for a node (e.g., a triangle).

Github: https://github.com/l-paz91/principles-practice/tree/master/Chapter%2014/Exercise%2012


So I kinda cheated on this one and didn't implement any virtuals. Instead of creating new classes and new version of draw_lines for each Binary_tree type I simply created an enum that holds a node shape and then in draw_lines() it checks the shape type and then draws that shape using the types we've already defined:

Chapter 14 // Exercise 12 - Principles & Practice Using C++

This way, their individual draw_lines() can be called without having to change init_node() at all...which I really didn't want to do because I already don't understand what I wrote and it was only a week ago.

Chapter 14 // Exercise 12 - Principles & Practice Using C++

No comments:

Post a Comment