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.
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:
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.
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.
No comments:
Post a Comment