Plotting graph using ccc_win

Hi Everyone,

Using the ccc_win library, i want to make a program that takes a polynomial equation from the user as a string and substitutes in it from x=-10 to x=10 every 0.1 points,

then join the points with lines to plot the graph, but i actually don't know how to make the substitution part

Your helps or hints are much appreciated

Regards

I previously wrote something similar in another post where it takes a command string and the parser breaks it down into horizontal / vertical commands.

It may give you some ideas: http://www.cplusplus.com/forum/beginner/131331/#msg709455

Thanks a lot for this, but i believe it's too complicated for my objective :)
Horstmann's Graphics Libraries are a specialized thing that is designed and used only in an academic setting.

If you are going to Drexel then you ought to have some on-campus help for dealing with the graphics. (It is unlikely anyone here will bother downloading and installing them just to help you...)


As for the equation, you should be familiar already with the mathematical concept of substitution.

Your user will give you everything as a string... which you must convert to numbers. You will need to be able to parse a string like

    "3 * 4 + 5"

properly. A simple recursive descent parser will do. Don't forget to handle parentheses. Here's the gotcha: now you have to deal with strings that look like:

    "3x + 5"

I recommend a simple trick that precludes any need to modify the parser itself. Use the mathematical writing construct of putting two things adjacent to each other to represent multiplication.

Hence, modify your parser to understand:

    "3 4 + 5"

i.e:

    "3(4)+5"

as (3*4)+5. Then, when you get a string full of "x"s from your user, you can do a simple replace of "x" with
"(" + current_value_of_x + ")". So, for an x of -10, do a string replace of "(-10)" for every "x":

    "3x + 5"    -->    "3(-10) + 5"

Run it through the parser as normal to calculate the final value: -25.


After calculating all the corresponding values, plot them using the Horstmann's graphics.


This is not a 'do it in a day' kind of homework. You'll need a week or so to get through it.

Hope this helps.
Topic archived. No new replies allowed.