Friday 26 June 2020

Chapter 14 // Exercise 16 - 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 16

Define a class Controller with four virtual functions on(), off(), set_level(int), and show(). Derive at least two classes from Controller. One should be a simple test class where show() prints out whether the class is set to on or off and what is the current level. The second derived class should somehow control the line color of a Shape; the exact meaning of "level" is up to you. Try to find a third "thing" to control with such a Controller class.

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


I really did not understand the point of this. It just made no sense to me. With the test class I don't know if he means to print it using shapes like a Text class in which case; we can't as we won't be able to attach anything to a Simple_window from within the Controller class or to print it using cout and display it in the console window.

He didn't specify what return type the functions had to be so I allowed show to return a shape that could be passed to the window to be displayed.

This exercise to me was a very confusing way of trying to get you to use inheritance. Maybe I completely misinterpreted it.


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

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

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

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

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

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

No comments:

Post a Comment