CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: "((3+5)*4)-(40/2)-10)" =????

  1. #1
    Join Date
    Aug 2001
    Posts
    60

    Unhappy "((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.

  2. #2
    Join Date
    May 2002
    Location
    Russia
    Posts
    1,571
    There are many tools and libs for math operations. Search the site, plz.

  3. #3
    Ejaz's Avatar
    Ejaz is offline Elite Member Power Poster
    Join Date
    Jul 2002
    Location
    Lahore, Pakistan
    Posts
    4,211
    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.

  4. #4
    Join Date
    Dec 2002
    Location
    Moscow
    Posts
    8

    code

    i have this program code, but it wrote in Delphi
    if you want, i may write it here

  5. #5
    Join Date
    Dec 2002
    Location
    Moscow
    Posts
    8

    code

    wow, i found thiscode on c++
    write your email and i send it in *.rar format

  6. #6
    Join Date
    Aug 2001
    Posts
    60

    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.

  7. #7
    Join Date
    Dec 2002
    Location
    Moscow
    Posts
    8

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)