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. Objects Performing Maths Functions

Objects Performing Maths Functions

Scheduled Pinned Locked Moved C#
csharpdesigndata-structureshelptutorial
2 Posts 2 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.
  • W Offline
    W Offline
    Wayne Phipps
    wrote on last edited by
    #1

    I have a table that I require calculations to be performed against. To achieve this, I have written several methods for the required functions. I have no problem with this solution although it does appear limited. As an example, I have created a form which is passed the DataTable. The form allows the user to choose the required function EG Divide, Mltiple, Add or Subtract and then asks what value/column the function should be performed against, what factor value/column should be used in the calculation and finally, asks where the result should be stored. Now if the user wants to Divide the value in columnA by the value in columnB and store the result somewhere, it all works fine. But imagine if the user wants to perform a further calculation on the result, at present the result has to be stored somewhere else and a second pass performed using the desired function. The only way I have though about solving this problem is to create some kind of math object which can be lnked in a daisy-chain or stored in an array so that multiple calculations can be performed therfore creating an equation. Has anyone had any experience of doing this or similar? Any ideas on removing the restrictions of the curent design? Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students LearnVisualStudio.Net

    H 1 Reply Last reply
    0
    • W Wayne Phipps

      I have a table that I require calculations to be performed against. To achieve this, I have written several methods for the required functions. I have no problem with this solution although it does appear limited. As an example, I have created a form which is passed the DataTable. The form allows the user to choose the required function EG Divide, Mltiple, Add or Subtract and then asks what value/column the function should be performed against, what factor value/column should be used in the calculation and finally, asks where the result should be stored. Now if the user wants to Divide the value in columnA by the value in columnB and store the result somewhere, it all works fine. But imagine if the user wants to perform a further calculation on the result, at present the result has to be stored somewhere else and a second pass performed using the desired function. The only way I have though about solving this problem is to create some kind of math object which can be lnked in a daisy-chain or stored in an array so that multiple calculations can be performed therfore creating an equation. Has anyone had any experience of doing this or similar? Any ideas on removing the restrictions of the curent design? Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students LearnVisualStudio.Net

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Using a DataTable is rather inefficient with lots of overhead you don't need for a simple state machine and what could be done using simple state variables. Store your result in a variable just like you do for your controls you dropped onto the form in the designer. Read the operands from the form, calculate, and store the result in the variable. If you want to remember all the results use a growable list like ArrayList or Stack. A stack is what your more advanced calculators use to store previous results, and stacks are what are typically used by calculators to evaluate expressions. You can find lots of information on the web about evaluating expressions to perform calculations. Even if you want to stick with using a DataTable add a column for metadata about the operands and/or operators you have stored in the DataRows. You could, for example, push the result of a calculation into a new DataRow with information that states whether the data is an operand, operator, or result. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

      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