http://www.sci.brooklyn.cuny.edu/~sd.../Program6.html
the link above are specifications to making a so called "simple" program, but how would this be done? especially the graphing of sin, cos and tan?
Printable View
http://www.sci.brooklyn.cuny.edu/~sd.../Program6.html
the link above are specifications to making a so called "simple" program, but how would this be done? especially the graphing of sin, cos and tan?
You create a loop that goes from 0.0 to 10.0 (the example in the link I think got it wrong by saying 0.0 to 20.0) in increments of (hi-lo)/(num of points) so:Quote:
graph(sin,0.0,10.0,20);
Once you've got all the values stored in an array, you need to normalize them based on the height of the screen display. Then it is a simple matter of going through the stored values in the array and outputting a symbol at the appropriate height based on the normalized value.Code:void graph( double (*func)(double),double lo,double hi, int number )
{
double pt;
double inc = (hi-lo)/number;
for( pt = lo; lo <= hi; pt += inc )
{
/* Call the function for the given pt value, you would need to
do something with the return value, i.e. store it in an array perhaps
for later use */
func(pt);
}
}
how would you print an asterisk based on the height?
probably create a 2d char array:-
Then print out the 2d array using a nested for loop.Code:[ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][*][ ][ ][ ]
[ ][*][*][ ][*][*][ ]
[ ][*][ ][ ][ ][*][ ]
How you gets the stars into the array will be of course your main problem.