Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This program will draw (rather rough) graphs of functions.The function being gra

ID: 3617430 • Letter: T

Question

This program will draw (rather rough) graphs of functions.The function being graphed and the region of the graph to bedisplayed will be hardcoded into the program, but in such a waythat the program can easily be modified and recompiled to graphdifferent functions and display different sized regions of thegraph. The function f(x) = sin(3*x) for x andy in [-2, 2] will be graphed as:

You will define constants using #define for the regionto be displayed. The origin will always be at the center. You willchoose a constant X_SEMIRANGE indicating that thehorizontal range covered is [-X_SEMIRANGE, X_SEMIRANGE]and a constant Y_SEMIRANGE indicating that the verticalrange covered is [-Y_SEMIRANGE, Y_SEMIRANGE]. These aredefined, for example, by:

You will also write a function double f(double} whichholds the function to be graphed. This can be easily rewritten (andthe program recompiled) to graph different functions.

The graph will be stored in a 2-dimensional character array:

You will have to round off the double values off() to ints before storing points in the array.Do not just type cast the double value to an intas this truncates rather than rounds off the converted values.Rounding a double x can be accomplished by:

Do not call a function you write here round() becausethat will conflict with the round() function in the mathlibrary.

Sometimes the point to be graphed for f() is outside ofthe vertical range of the graph. In this case the point will not beplotted. You must check this for each point you plot. (See thegraph of f(x) = x2 above).

The first index in graph[][] corresponds to they coordinate of points on the graph and the second indexcorresponds to the x coordinate. Points on the graphdisplay move upwards as values increase butdownwards as the first index of graph[][]increases.

Many mathematical functions are available in the standardlibrary. To use these you must #include <math.h>. Ifyou are working on a Unix-like system (Linux, Mac OS X) and usingfunctions from the math library you may have to link yourprogram with the math library when you compile. Use the"-lm" switch to do this:

Explanation / Answer

please rate - thanks hopefully will get you started #include #include #include #define X_SEMIRANGE 3 #define Y_SEMIRANGE 2 char graph[Y_SEMIRANGE*20 + 1][X_SEMIRANGE*20 + 1]; double f(double x) { double fx; fx = cos(x*x); return fx; } int mod(int x) { if(x0) yy= (int)(y+0.5); else yy= (int)(y-0.5); if(yy >= -Y_SEMIRANGE*10 && yy= -X_SEMIRANGE*10 && xx
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote