MC140.01 / MC140.02

Fall 2000

Assignment 3

due Wednesday 4 October 2000, 12noon

The goal of this assignment is to reinforce use of statements
like *if/else* and *while* statements and
introduce the following new concepts:
constants,
boolean operators,
mathematical operators and functions,
2-dimensional arrays
and error handling.
As well, this assignment introduces some principles
of computer graphics, like coordinate systems.

This assignment is worth 3% of your term mark. It will be marked out of 30 points.

You should begin with a correct version of assignment #2.

**1. Menu.** (3 points)

Like assignment #2, this program should print a menu containing
options for the user.
For this assignment, put the following options in your menu:

[R] draw rectangle [T] draw triangle [C] draw circle [Q] quit enter option:Based on the option entered by the user, your program should call a function to print out each shape.

**2. Grid.** (6 points)

Unlike assignment #2, this program will use math to determine
how to print the shapes.
To do this, we begin by defining a 2-dimensional grid of points,
and we will "plot" in that grid.
Define a global variable, **grid**, as follows:

#define MAX 21 char grid[MAX][MAX];

**3. Rectangle.** (7 points)

Write a function to draw a rectangle, centered at the origin of the grid.
For example, a rectangle of height 4 and width 7 would look like Figure 1B.

Let the user specify the height and width of the rectangle. Limit the height and width to be within the bounds of the grid. Check that the user's input is within these limits.

**4. Triangle.** (7 points)

Write a function to draw a right triangle, so that its
right angle is at the origin of the grid.
For example, a triangle of height 7 and width 10 would look like Figure 1C.

Let the user specify the height and width of the triangle. Limit the height and width to be within the bounds of the grid. Check that the user's input is within these limits.

**5. Circle.** (7 points)

Write a function to draw a circle, centered at the origin of the grid.
For example, a circle of radius 6 would look like Figure 1D.

Let the user specify the radius of the circle. Limit the radius to be within the bounds of the grid. Check that the user's input is within these limits.

A. sample grid | B. sample rectangle | C. sample triangle | D. sample circle |

**6. Submit your ".c" file electronically, as with assignment #1.**

**7. Tips.**

Check the class FAQ page frequently for updates on the assignment:

*http://www.cs.bc.edu/~sklar/mc140/faq.html*