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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

It's possible to evaluate a string as a mathematical expression?C++3.1

Status
Not open for further replies.

15963

Technical User
Dec 27, 2002
2
RO
Hello,

I want to ask if it's possible to evaluate a string in borland c++3.1.
For instance, everytime I start the program I read a string (ex. STR="sin(2*x)+x*x+90"), and a value for x(ex. x=10).
It's possible to use the string STR as a macro(or to use it in a file,or in any other way) that would evaluate the string STR as a function with the argument x, and would return his value?
(Just like the function below...)

float STR(int x)
{
return sin(2*x)+x*x+90;
}


Thanks
 
You'd probably have to create that macro but yes, its possible. You'll have to do the work but of you use an array or two and a few keys it shouldn't be too hard. Cyprus
 
seems you would need to create a stack to do postfix polish notation processing
 
Yep... the stack would be my suggestion. Actually of them. One for values and one for expressions. Then when you pop you do things correctly

value.pop op.pop value.pop
x + y


Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top