The name of your C program file must be called graph.c, files with any other name will not be marked.
On one fine day, out of a whim, you ask your good friend Doromen: "Hey, do you know what is a quadratic function?". Doromen replies: "Aqua Dramatic? A movie about undersea? How queer!". Immediately, you know you are in deep trouble. "Erm, Doromen, it is actually mathematical function of the form Y = AX2 + BX + C" "Oh?! Whats so interesting about it?" "Erm..., Doromen, they trace beautiful line if you draw them." "You must be kidding me!"
Well, now you have to write a simple graph plotter to convince Doromen....
A graph can be represented by a two-dimension char array (this is only a suggestion; you may use other arrays if you wish). The size of the graph can be represented by the number of rows and columns:
Using the default values (X-Axis at row 10, Y-Axis at column 30, scale = 0.25), a graph with several numbered points should appear on the screen as follows. Take some time to count the number of columns and rows to make sure you understand.
|
|
|
|
|
|
4 |
|
|
| 1
------------------------------+------------------------------
3 |
|
|
|
|2
|
|
|
|
|
Since each row/column represents 0.25, the coordinates for the points shown are:
Write a C program to process the following commands:
$ gcc -Wall -lm graph.c -o graph
$ ./graph // Important: Don't leave out the ./
|
|
|
|
|
|
|
|
|
|
------------------------------+------------------------------
|
|
|
|
|
|
|
|
|
|
1-Plot 2-Rescale 3-Clear 0-Exit: 1
Coefficients (a b c): 1 0 0 // Y = X^2
|
* | *
|
|
* | *
|
* | *
|
* | *
* | *
-----------------------------***-----------------------------
|
|
|
|
|
|
|
|
|
|
1-Plot 2-Rescale 3-Clear 0-Exit: 1
Coefficients (a b c): -1 0 0 // Y = -X^2
|
* | *
|
|
* | *
|
* | *
|
* | *
* | *
-----------------------------***-----------------------------
* | *
* | *
|
* | *
|
* | *
|
|
* | *
|
1-Plot 2-Rescale 3-Clear 0-Exit: 1
Coefficients (a b c): 0 0 2 // Y = 2
|
* | *
*************************************************************
|
* | *
|
* | *
|
* | *
* | *
-----------------------------***-----------------------------
* | *
* | *
|
* | *
|
* | *
|
|
* | *
|
1-Plot 2-Rescale 3-Clear 0-Exit: 1
Coefficients (a b c): 0 0 -2 // Y = -2
|
* | *
*************************************************************
|
* | *
|
* | *
|
* | *
* | *
-----------------------------***-----------------------------
* | *
* | *
|
* | *
|
* | *
|
*************************************************************
* | *
|
1-Plot 2-Rescale 3-Clear 0-Exit: 2
Scale: 0.125 // New Scale of 0.125
* | *
|
* | *
|
* | *
|
* | *
* | *
* | *
* | *
----------------------------*****----------------------------
* | *
* | *
* | *
* | *
|
* | *
|
* | *
|
* | *
1-Plot 2-Rescale 3-Clear 0-Exit: 2
Scale: 0.5 // New Scale of 0.5
|
|
* | *
|
|
|
*************************************************************
|
* | *
|
-----------------------------***-----------------------------
|
* | *
|
*************************************************************
|
|
|
* | *
|
|
1-Plot 2-Rescale 3-Clear 0-Exit: 2
Scale: 0.25 // New Scale of 0.25
|
* | *
*************************************************************
|
* | *
|
* | *
|
* | *
* | *
-----------------------------***-----------------------------
* | *
* | *
|
* | *
|
* | *
|
*************************************************************
* | *
|
1-Plot 2-Rescale 3-Clear 0-Exit: 1
Coefficients (a b c): 0 1 1 // Y = X + 1
| *
* | **
*************************************************************
| *
* | * *
|*
* * *
*|
** | *
** | *
--------------------------*--***-----------------------------
* * | *
* * | *
* |
* * | *
* |
* * | *
* |
*************************************************************
* * | *
* |
1-Plot 2-Rescale 3-Clear 0-Exit: 1
Maximum formulas exceeded. // Already plotted 5 formula.
1-Plot 2-Rescale 3-Clear 0-Exit: 3
|
|
|
|
|
|
|
|
|
|
------------------------------+------------------------------
|
|
|
|
|
|
|
|
|
|
1-Plot 2-Rescale 3-Clear 0-Exit: 1
Coefficients (a b c): 0 -1 0 // Y = -X
* |
* |
* |
* |
* |
* |
* |
* |
* |
*|
------------------------------*------------------------------
|*
| *
| *
| *
| *
| *
| *
| *
| *
| *
1-Plot 2-Rescale 3-Clear 0-Exit: 0
char graph[10][30]; //10 rows, 30 columns
....
printf("%c", graph[2][5]); //printing row 2 (3rd row), column 5 (6th
//columns
...
double rint(double x);
The function rounds the input value x to the nearest integral. e.g.
rint(2.44) gives 2.0, rint(3.56) gives 4.0.
Again, don't despair if your output is out by one row/col, we'll be
lenient on the conversion part.
A total of 18 different hosts have accessed this document in the last 556 days; your host, 216.73.216.129, has accessed it 1 times.
If you're interested, complete statistics for this document are also available, including breakdowns by top-level domain, host name, and date.