Friday 28 August 2020

Chapter 15 // Exercise 8 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2017 and modified versions of the graphics files used throughout the chapters. You can find those versions through the link below.

Chapter 15 // Exercise 8

Here is a collection of heights in centimetres together with the number of people in a group of that height (rounded to the nearest 5cm): (170, 7), (175,9), (180, 23), (185, 17), (190, 6), (195, 1). How would you graph that data? If you can't think of anything better, do a bar graph. Remember to provide axes and labels. Place the data in a file and read it from that file.

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


I thought about doing a scatter graph as we have Marks already implemented. Then because it would be as "simple" as replacing the rectangles with marks I decided to create a new class that could hold x and y data but then through inheritance it could be given different functionality.

I also changed how the notches were drawn as originally they were set as ints, causing quite a bit of data lost due to rounding down. CustomGraph though draws axes to fit the window and has modifiable labels. How the data is drawn though is up to the child class.

This isn't the best graph in the world but it reads in from a file or a vector:
Chapter 15 // Exercise 8 - Principles & Practice Using C++


No comments:

Post a Comment