Solved

about formulas

Posted on 2002-05-18
5
183 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 50 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

726 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