header

Homework 8

Output Specifications

Draw the graph of the function y = f(x) on a graphics window that is 701 pixels wide and 701 pixels high. The background will be white, the coordinate axes will be black, and the grid lines will be light red.

Input Specifications

The user will enter:

  1. the function as a space-delimited infix expression.
  2. the world-coordinates of the lower-left corner of the graphics window.
  3. the world-coordinates of the upper-right corner of the graphics window.
  4. the distance between vertical grid lines (in world coordinates).
  5. the distance between horizontal grid lines (in world coordinates).

Process Requirements

1. Reset the graphics window based on the coordinates of the lower-left and upper-right corners.

2. Draw the gridlines in red. The gridlines are drawn out from the origin as far as needed. For example, suppose the vertical gridlines are 2 units apart (in the world coordinate system). Starting at the origin and going to the right, the vertical gridlines would be at x = 2, x = 4, x = 6, and so on until you have gone as far as you can go on the graphics window. Then, starting at the origin and going to the left, the vertical gridlines would be at x = -2, x = -4, x = -6, and so on until you have gone as far as you can go in that direction. Keep in mind that the origin may not be at the center of the graphics window. In fact, it may not even be in the graphics window at all.

3. Draw the coordinate axes in black. Draw a horizontal line through the origin from minimum x to maximum x. Draw a vertical line through the origin from minimum y to maximum y.

4. Draw the graph of the function from minimum x to maximum x.

Sample Run

The images below illustrate three graphs generated by this program. (Both the console window and the graphics window have been made smaller to reduce the size of the image.)

y = sin(x)

Graph of cubic equation

Sample Run

Project Submission

I've done some of the work for you in Hmwk08.cpp. Submit your project file and your C++ program file as email attachments.