Computer Science Canada Operators and Procedures Help |
Author: | TuringBeast [ Tue Dec 06, 2011 5:32 pm ] | ||
Post subject: | Operators and Procedures Help | ||
What is it you are trying to achieve? I am trying to achieve a problem that I am having in my calculator program. What is the problem you are having? Basically, i want to make my code more efficient so what i want to do is assign a value as an operand so it functions just as an operand. Describe what you have tried to solve this problem I dont know how to solve the problem, but the only solution i could think of is use separate procedures. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) This is just a segment of my program. Don't mind the coding, it's just the operand signs that I need to fix. As you can see, each of the four procedures are the same, except for the operand signs that have been commented out in the middle of the procedure. What I want to do is make just one procedure with parameters instead of four separate procedures. I just don't know what i can incorporate in place of those operators and i don't know if I can declare an operator or not.
Please specify what version of Turing you are using I am using Turing 4.1.1 |
Author: | Insectoid [ Tue Dec 06, 2011 5:36 pm ] |
Post subject: | RE:Operators and Procedures Help |
There's no nice way to do this in Turing. You're going to need a wall of case/if statements. Basically a lot of "If char = '*' then a *= b". |
Author: | Tony [ Tue Dec 06, 2011 6:10 pm ] |
Post subject: | RE:Operators and Procedures Help |
array of function pointers, using characters in place of an index. Awww yeahhh. You'd still need a wrapped function for each operator though. |
Author: | Insectoid [ Tue Dec 06, 2011 6:14 pm ] |
Post subject: | RE:Operators and Procedures Help |
Does Turing support function pointers? |
Author: | Dreadnought [ Tue Dec 06, 2011 6:17 pm ] | ||
Post subject: | Re: Operators and Procedures Help | ||
I think Tony means something like this (correct me if I'm wrong).
|
Author: | Tony [ Tue Dec 06, 2011 6:55 pm ] |
Post subject: | RE:Operators and Procedures Help |
yup, that's the idea. |