------------------------------------------------------------------------------
MC logo
CSc 220 Assignment 2
[^] CSc 220 Programming Assignments
------------------------------------------------------------------------------

90 pts

A Graphic Experience

Due: Sept 25

You are to write a C program to read in several numerical parameters describing a quadratic function and plot the function. The plot will be a simple text-oriented graph, turned sideways from the usual: the x axis will be vertical and y horizontal.

Input

The input consists of the following numbers:

Note that the input numbers must appear in the correct order, but their arrangement on lines is indifferent. The C scanf function will read them this way.

You may assume that the input is correct.

Output

The output is a text-based graph. Its (horizontal) y axis takes up 70 characters of space, and its (vertical) x axis uses nx lines. Place a 70-character line above and below the graph, with a statement of the y value range to which it corresponds At the right (70 characters past the left edge), place a vertical line made of | characters. On the first line, and at intervals of nxsep lines, replace the | with + and give the x value for that line. Give the value to the right of the line.

Inside the area defined by the axes, place one * on each line for which its y value is in in range. Place it correctly according to the y value.

Notes

Each line of the output will represent one x value. The first one being startx, and the others being spaced at increments of (endx - startx) / (nx - 1). Loop through these values. For each one, compute the corresponding y value. If it is within the range starty to endy, compute its distance beyond starty, and scale to the distance of 70 characters. Print the *, with the spaces to locate it correctly.

When reading in double quantities, use the scanf conversion %lf. If you use simple %f, something interesting may happen.

Examples

For the input:

-1.5 18.0 -16.5
0.0 10.0
-5.0 40.0
41
5
My program produces the output:
y = -5.00 - 40.00
----------------------------------------------------------------------   x =
                                                                      + 0.00
                                                                      |
                                                                      |
*                                                                     |
      *                                                               |
            *                                                         + 1.25
                 *                                                    |
                      *                                               |
                           *                                          |
                                *                                     |
                                    *                                 + 2.50
                                        *                             |
                                            *                         |
                                               *                      |
                                                  *                   |
                                                     *                + 3.75
                                                       *              |
                                                         *            |
                                                           *          |
                                                             *        |
                                                              *       + 5.00
                                                               *      |
                                                                *     |
                                                                *     |
                                                                 *    |
                                                                *     + 6.25
                                                                *     |
                                                               *      |
                                                              *       |
                                                             *        |
                                                           *          + 7.50
                                                         *            |
                                                       *              |
                                                     *                |
                                                  *                   |
                                               *                      + 8.75
                                            *                         |
                                        *                             |
                                    *                                 |
                                *                                     |
                           *                                          + 10.00
----------------------------------------------------------------------
y = -5.00 - 40.00

For

0.25 3.0 5.0
-8.0 2.0
-5.0 10.0
41 4
I get
y = -5.00 - 10.00
----------------------------------------------------------------------   x =
        *                                                             + -8.00
       *                                                              |
      *                                                               |
     *                                                                |
    *                                                                 + -7.00
    *                                                                 |
   *                                                                  |
   *                                                                  |
   *                                                                  + -6.00
   *                                                                  |
   *                                                                  |
    *                                                                 |
    *                                                                 + -5.00
     *                                                                |
      *                                                               |
       *                                                              |
        *                                                             + -4.00
         *                                                            |
          *                                                           |
            *                                                         |
              *                                                       + -3.00
               *                                                      |
                 *                                                    |
                    *                                                 |
                      *                                               + -2.00
                        *                                             |
                           *                                          |
                             *                                        |
                                *                                     + -1.00
                                   *                                  |
                                      *                               |
                                          *                           |
                                             *                        + 0.00
                                                 *                    |
                                                    *                 |
                                                        *             |
                                                            *         + 1.00
                                                                *     |
                                                                      |
                                                                      |
                                                                      + 2.00
----------------------------------------------------------------------
y = -5.00 - 10.00
The y axis is admittedly rather simple. If you wish to make a nicer-looking one, feel free to do so.

When your program works, submit over the web here.
<<CSc 220 Assignment 1 CSc 220 Assignment 3>>