MCS273 Introduction to C++ Programming (January 2013)

Pie and Bar Charts


Overview

The goal of this lab is to write the program that displays a pie chart and a bar chart representing four different categories. Your program should prompt the user to enter four values to draw the corresponding pie and bar charts. You may pick the four categories of your own choice; we used the categories Freshman, Sophomore, Junior, and Senior in our program. You will write this program using appropriately designed functions and procedures that will make it easier to program and understand than the code you have written up to this point.

Your programming task

You can obtain a working solution executable by downloading the following file:

Before running chart, you must (1) make sure it is called chart; and (2) make it executable on Mac OS X by running the following commands in the directory you downloaded them to:
   chmod 755 chart
You should run chart so that you know what your goal is.

Check-offs (3 points): When I check you off, I'll verify that you have:

  1. Your program functions as required (i.e., as my program does) and has a good makefile.

  2. The program is well-designed: i.e., it has appropriate and well-named procedures and an easy to follow logic. The procedures should not be too long and should have a clear purpose (e.g., draw a pie chart and draw a partial circle, to name just two).

  3. Good testing, either in ccc_win_main (commented out) or in the debugger.

  4. The program and procedures are documented as described in C++ Style Guide.

Drawing Colors and Solid Shapes

You have been using hollow shapes so far without colors. Following are suggestions on using colors and solid shapes.

Colors

Remember to review "ccc_win.h" reference to learn the new constructors that allow you to use colors. Check the RGB Color Calculator link in Useful Links to find out how to code the color you would like to use.

Solid Shapes

There are many ways to draw solid shapes but here is one of them. I will give an example here and in class of how to draw a solid circle. You should figure out how to draw solid rectangles and partial circles.

To draw a solid circle with a certain radius, you can draw many circles of the same color many times with the radius ranging from 0.0 to the given radius. As long as the range of the radius is incremented in fine granularity, the shape drawn in the graphics window will look like a sold shape. You can experiment with different increments to see what increment works best.

for (double radius = 0.0; radius <= given_radius; radius += RADIUS_INCREMENT) {
    cwin << Circle(center, radius, color);
}