?
Solved

about formulas

Posted on 2002-05-18
5
Medium Priority
?
186 Views
Last Modified: 2010-04-02
Hi;
I'd like to know how to enter an "equation or formula"
as variable.
ex:2*(p^2)*l;
by making the prog asking me about this formula, and use it as function inside the prog.
another example:
When u give an equation to a "graph"program for drawing
I need the clear example for that.
thank you
0
Comment
Question by:Mustapha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 200 total points
ID: 7018440
In scripting langiages, such as JavaScript or VBS, you caould simly call eval(s) where s is the string variable containing the equation.

Alas, C++ is a compiled langiage and there is no direct way to do this (sorry).  An indirect method would be to write some progeam code that examines the input and determines the various steps needed to do the calculations (parsing the equation).  This is a non-trival piece of coding.

Here's an example:
http://srd.yahoo.com/goo/%22Equation+parser%22+and+%22C%2b%2b%22/4/T=1021738348/F=c676cba64a1c6a937f3cbcb6ed77e21d/*http://compilers.iecc.com/comparch/article/96-04-026

Here's a good one, but written in Visual Basic:
http://www.vbweb.co.uk/show/216/

Another Indirect method would be to write a .JS file that used the eval() fn and saved its result to a text file.  You could execute that .JS file, then read the result file.

-- Dan
0
 
LVL 2

Expert Comment

by:Ixeus
ID: 7020912
You write what you call a parser, there are many parsers on the net, just search for  c++ formula parser,  this will analyze a string and calculate a return value of the formula you have.  Yes what was said was right, C++ is compiled code, no intermediate code.

-Ixeus
0
 
LVL 4

Expert Comment

by:havman56
ID: 7020999
Dan
 really nice to see the link u had given for c++.
me too intrested in it!

0
 
LVL 11

Expert Comment

by:griessh
ID: 7178802
Dear Mustapha

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "DanRollins"

comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points. The link to the Community Support area is: http://www.experts-exchange.com/commspt/


PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7199803
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses
Course of the Month14 days, 19 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question