Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

function graphic drawing

Status
Not open for further replies.

spiriad

Programmer
Oct 26, 2007
3
RO
Hi,I want to make a program that plots the graph for a function . I know how to draw the pixels how to scale the graphic and other things, but what I don't know is how to input the funtion (eg.: x^3 + 2*x).If I use TEdit to insert the function, how can I interpret the value of the function that it's given ?How to recognize the variable ? There are any similar programs with source codes ....they may help...

Thx
 
Off the top of my head, I would take the TEdit and pull it into an AnsiString. Then I would find the length of the string, then go through each character in the string. If the character is a letter, assume it is a variable. If the character is a "special" character (i.e. ^, *, +, -, etc.) assumte you have a function. If the character is a number, well, you get the picture.



James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
So you want it to actually evaluate your input?

basically you have two ways to do it.
hard way - program math evaluator (or find working one).
I'm pretty sure there are many, and Kernigan & Ritchie I think have one as example and may be Straustroup too. Use google for say Expression Evaluator.

Easy way - get some component do that for you. But that could take some time - and you need many points for the graph.
But why not just check it out?

The components that may help you is
MSScriptControl.ScriptControl

I can give you VBS code for using it - but I never did it from C++

set VBS=createobject("MSScriptControl.ScriptControl")
VBS.Language="VBscript"
outValue = VBS.Eval(inValue)

And I've seen example of using command line tool GAWK just for that - ypou can look in that direction, too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top