Solved

about formulas

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

729 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