Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. calculator

calculator

Scheduled Pinned Locked Moved C#
question
10 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    the exile
    wrote on last edited by
    #1

    hi every body I want to make profetional calculator for complex operation such as to calculate this statement A+B(f*g-r)/A+B .. and somthing like that how can i do that??

    L CPalliniC R A 4 Replies Last reply
    0
    • T the exile

      hi every body I want to make profetional calculator for complex operation such as to calculate this statement A+B(f*g-r)/A+B .. and somthing like that how can i do that??

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      By learning how statements and equations (and something like that) work :) Where do you want to start?

      I are troll :)

      T 1 Reply Last reply
      0
      • T the exile

        hi every body I want to make profetional calculator for complex operation such as to calculate this statement A+B(f*g-r)/A+B .. and somthing like that how can i do that??

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #3

        the exile wrote:

        how can i do that??

        Do you know we've a wonderful article repository? [^]. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        In testa che avete, signor di Ceprano?

        Y 1 Reply Last reply
        0
        • L Lost User

          By learning how statements and equations (and something like that) work :) Where do you want to start?

          I are troll :)

          T Offline
          T Offline
          the exile
          wrote on last edited by
          #4

          thanks I know many thing about statement and stack and some thing about priorities and about prefix and postfix ..etc just I need some helps like idea and some codes

          L 1 Reply Last reply
          0
          • T the exile

            thanks I know many thing about statement and stack and some thing about priorities and about prefix and postfix ..etc just I need some helps like idea and some codes

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            the exile wrote:

            [...]and some codes

            Boy are you in the wrong place for that.

            Check out the CodeProject forum Guidelines[^]

            1 Reply Last reply
            0
            • CPalliniC CPallini

              the exile wrote:

              how can i do that??

              Do you know we've a wonderful article repository? [^]. :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              Y Offline
              Y Offline
              Yusuf
              wrote on last edited by
              #6

              ...but....but....but....those articles do not do this statement A+B(f*g-r)/A+B :-D

              Yusuf Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]

              CPalliniC 1 Reply Last reply
              0
              • Y Yusuf

                ...but....but....but....those articles do not do this statement A+B(f*g-r)/A+B :-D

                Yusuf Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]

                CPalliniC Offline
                CPalliniC Offline
                CPallini
                wrote on last edited by
                #7

                The articles were just to fool him, why parsing when you may use javascript? :laugh:

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                In testa che avete, signor di Ceprano?

                0 1 Reply Last reply
                0
                • CPalliniC CPallini

                  The articles were just to fool him, why parsing when you may use javascript? :laugh:

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  0 Offline
                  0 Offline
                  0x3c0
                  wrote on last edited by
                  #8

                  Why parse at all? Just hard-code the expressions

                  1 Reply Last reply
                  0
                  • T the exile

                    hi every body I want to make profetional calculator for complex operation such as to calculate this statement A+B(f*g-r)/A+B .. and somthing like that how can i do that??

                    R Offline
                    R Offline
                    Roger Wright
                    wrote on last edited by
                    #9

                    I'm not much of a programmer, but I'd start by modelling the data items as structs - one element for the real, the other for the imaginary part - then overload the operators to define complex functions. For instance,

                    struct Complex
                    {
                    public double Re, Im;
                    public Complex(double Re, double Im)
                    {
                    this.Re = Re;
                    this.Im = Im;
                    }
                    public Complex(Complex X)
                    {
                    Re = B.Re;
                    Im = B.Im;
                    }
                    public static Complex operator + (Complex A, Complex B)
                    {
                    Complex result = new Complex(A);
                    result.Re += B.Re;
                    result.Im += B.Im;
                    }
                    }

                    This defines a struct with two parts called Complex, with real and imaginary parts called Re and Im, respectively. Re and Im are declared as type double. Two constructors are declared, one being initialized with separate values, the other by a type Complex value. The last bit overloads the '+' operator to return a Complex sum of two Complex variables. You can add other operators to the mix by writing the code to implement them. Although structs do not have methods, operator overloads (which look just like methods) work on structs as well as classes. In your calculator application I'd define buttons to click for each overloaded operator, something like what Microsoft has done with the built in Windows Calculator utility. By the way, I didn't write or test the above - I modified an example in a book I'm studying to fit your situation. You might want to pick up a copy and read it; "Professional C# 2005 with .Net 3.0" by Wrox Press. It's quite thorough and very readable.

                    "A Journey of a Thousand Rest Stops Begins with a Single Movement"

                    1 Reply Last reply
                    0
                    • T the exile

                      hi every body I want to make profetional calculator for complex operation such as to calculate this statement A+B(f*g-r)/A+B .. and somthing like that how can i do that??

                      A Offline
                      A Offline
                      Alan Balkany
                      wrote on last edited by
                      #10

                      Here's how I would do this: 1. Make a binary tree. Leaf nodes stand for your variables (A, B, f, g...). Interior nodes stand for an operation on the values of the interior node's two sons. 2. Go through your statement and put all tokens into a list of leaf nodes. (The operations will eventually be transferred to interior nodes.) 3. Find the range of nodes where the parentheses are most deeply nested. 4. If you have the pattern [left parenthesis] [variable] [right parenthesis], delete the two parentheses nodes. (The variable could also be an interior node.) 5. In this deeply-nested region, replace the pattern [variable] [high-precedence-operation] [variable] with an interior node for the operation, with the two variables as sons. (The variables could also be other interior nodes.) 6. Repeat Step 5 for the low-precedence operations. You should now be able to apply Step 4 on the remaining interior node left in the parentheses. 7. To evaluate the expression, do a post-order traversal on the binary tree, getting the variable values for leaf nodes, and applying the operation to the two values for interior nodes. The result of the evaluation will be left in your root node. I find this approach simpler than the recursive algorithms.

                      modified on Friday, March 27, 2009 10:10 AM

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups