-
December 14th, 2002, 05:40 AM
#1
"((3+5)*4)-(40/2)-10)" =????
When user enter any string on EditBox like... "((3+5)*4)-(40/2)-10)".
how to make my program give the numerical result from the string.
-
December 14th, 2002, 05:53 AM
#2
There are many tools and libs for math operations. Search the site, plz.
-
December 14th, 2002, 05:56 AM
#3
Dear Phogang,
to do mathematical tasks like that, u'll have to use data structures, by using 2 stacks, the desired operations can be achieved, for that in one stack u'll put the operands and in other the operators.
suppose the expration is 2 + 1 , then
parsing from left, first u get 2, put it in one stack, then u get an
operator (+ here), u put it in the other stack, now again u get another operand (1), since the experation has ended, pop last operand, store it in a variable, then pop operator (+), agian pop oprand ( 2 ) and then perform the addition.
The main point is never override the perorities of opertors( like * or / )can't be put below lower precidence operators (like +,-), if any situation arises, then first perform the steps mentioned above, get their result, and store that result in the operand stack.
if u encounter ( ), then store ( in operators stack, when u receive ), again start poping till u get ( in operators stack, perfrom arithematics and store the result in the operands stack.
I'll try to arrange the code for u, since I don't have it right now.
Hope this will give u some idea, for further details, u can consult
any nice book of data structures using C/C++ in stacks session.
Regards,
Ejaz.
Last edited by Ejaz; December 14th, 2002 at 06:06 AM.
-
December 14th, 2002, 08:34 AM
#4
code
i have this program code, but it wrote in Delphi
if you want, i may write it here
-
December 14th, 2002, 09:05 AM
#5
code
wow, i found thiscode on c++
write your email and i send it in *.rar format
-
December 14th, 2002, 09:28 PM
#6
dear sir vovkin
my email address is phogang@hotmail.com
thank you very much for your sourcecode (zip format is best, my machine do not have winrar)
thank you.
-
December 16th, 2002, 07:41 AM
#7
code
i sent from e-mail vovkin@kernel.lv
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|