Monday, 31 August 2020

Chapter 15 // Exercise 11 - 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 11

Find the average maximum temperatures for each month of the year for two or more locations (e.g., Cambridge, England, and Cambridge, Massachusetts; there are lots of towns called "Cambridge") and graph them together. As ever, be careful with axes, labels, use of color, etc.

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


I should've spend a lot longer on this instead of hacking something together but I really want to move onto the next chapter as graphing data is not my idea of fun...besides excel can do it much nicer and faster and there's got to be a C# library out there somewhere that allows you to call Excel graphs from within your code.


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

With that though, I'm finally onto the last graphics chapter.

Sunday, 30 August 2020

Chapter 15 // Exercise 10 - 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 10

What kind of data is unsuitable for a line graph or a bar graph? Find an example and find a way of displaying it (e.g., as a collection of labelled points).

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

If you have a graph that is "x amount of people voted yes and y voted no"; this would make a great bar chart. However, charts such as "Age and time spent watching Filthy Frank" would make a better scatter graph. An example from Maths Is Fun; Icecream Sales and Temperature:

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

The red line is there due to my laziness with the notch spacing. If the top Y value is more than the length, you end up with teeny tiny gaps between each notch. 

Saturday, 29 August 2020

Chapter 15 // Exercise 9 - 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 9

Find another data set of heights (an inch is 2.54cm) and graph them with your program from the previous exercise. For example, search the web for "height distribution" or "height of people in the United States" and ignore a lot of rubbish or ask your friends for their heights. Ideally, you don't have to change anything for the new data set. Calculating the scaling from the data is a key idea. Reading in labels from input also helps minimise changes when you want to reuse code.

Github: https://github.com/l-paz91/principles-practice/blob/master/Chapter%2015/exercise%209


For this one I quickly googled "height data set" on images then used the first image that came up. It contained height and weight pairs. I have no idea what unit they were in, I guessed kg and cm but they seem a bit low for that but whatever.


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

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


Monday, 24 August 2020

Chapter 15 // Exercise 6, 7 - 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 6, 7

6. Design and implement a bar graph class. Its basic data is a vector<double> holding N values, and each value should represented by a "bar" that is a rectangle where the height represents the value.
7. Elaborate the bar graph class to allow labeling of the graph itself and its individual bars. Allow the use of colour.


Exercise 6 - The basic bar graph with just bars set to certain heights:

Chapter 15 // Exercise 6, 7 - Principles & Practice Using C++

This takes in a vector of doubles and resizes itself depending on the window size. The number of notches are also dependent on the size of the graph and how many bars there are.

Exercise 7 - It's not exactly excel but it'll do. The bars are coloured by random ints so occasional bars may be identical. The notch marking on the Y axis also isn't entirely accurate as it's rounded down in the Axis constructor but whatever. The bar labels and fill colours can be turned off by just providing a bool value and you can set the axis labels to anything once you've created the barchart object.

Chapter 15 // Exercise 6, 7 - Principles & Practice Using C++