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:
y = Ax2 + Bx + C
These are floating point quantities which should be read as doubles.
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:
For
When your program works, submit over the web here.
| CSc 220 Assignment 3 |