Solved

about formulas

Posted on 2002-05-18
5
179 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
5 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Dan
 really nice to see the link u had given for c++.
me too intrested in it!

0
 
LVL 11

Expert Comment

by:griessh
Comment Utility
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
Comment Utility
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now