Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Separation Code Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
FeZbOy




PostPosted: Tue Nov 29, 2005 8:32 am   Post subject: Separation Code Help

Kay, here is what I am trying to accomplish, plus a bit of background.

In calculus, my teacher taught about different functions and stuff, which inspired me to create a turing program to help my friends and I. In creating this program, I decided I need to seperate the equation in order to find the numbers, and the operation enacted on the numbers. This is where I come to help. I have the code kinda where I can figure it out, but I am stumped.

So can any programmers help? Please?


code:

proc separate (str : string, var oper : string, var num1, num2 : int)
    var reals : array 0 .. 9 of int := init (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
    var nums : array 1 .. 30 of string
    for i : 1 .. 30
        nums (i) := ""
    end for
    var Var : boolean
    var p : int := 1
    for i : p .. length (str)
        Var := false
        for l : 0 .. 9
            if str (i) = intstr (reals (l)) then
                nums (i) += str (i)
                Var := true
                exit
            end if
        end for
        if not Var then
            p := i + 1
        else
            p += 1
        end if
    end for
    put nums (1)
    put nums (2)
    num1 := strint (nums (1))
    num2 := strint (nums (2))
end separate

var oper : string
var num1, num2 : int
separate ("55x3", oper, num1, num2)


Thanks,

Corey Zerf
Sponsor
Sponsor
Sponsor
sponsor
jamonathin




PostPosted: Wed Nov 30, 2005 1:48 pm   Post subject: (No subject)

Hey man I didn't even see ur topic, lol. I see not too many people wanted to help yas out, so i figured I would.

It's all explained in the code, if you need any more clearence, juss ask.

code:
proc separate (str : string)
    var holdNumber : string := "" %This holds the information from eq'n
    var oper : flexible array 1 .. 0 of string %Operations Variable - Notice we start at 0
    var nums : flexible array 1 .. 0 of int %Numbers Variable
    for i : 1 .. length (str) %Checking the entire length of the eq'n
        if strintok (str (i)) then %If the current 'character' is a whole number
            holdNumber += str (i) %Since it's a int#, add the STRING value to hold
        else %if its not a whole number (i.e. decimal/operation)
            new oper, upper (oper) + 1 %Make a new operation variable (started at 0)
            new nums, upper (nums) + 1 %Make a new number variable (started at 0)
            % It's the current character thats not a whole number so make . .
            oper (upper (oper)) := str (i) % . . oper equal to that
            nums (upper (nums)) := strint (holdNumber) %Give the held number to nums
            holdNumber := "" %Start holdNumber, over
        end if
    end for
   
    % if we dont put this in, the eq'n (55x3) will result in (55x) with no 3
    % this is because we have mroe numbers than operators (by 1)
    new nums, upper (nums) + 1 %So make one more
    nums (upper (nums)) := strint (holdNumber) %make it equal to whatever was last saved
   
    % D I S P L A Y I N G
    % we go up to the max number of 'oper' because if we went to the max of nums,
    % there would be one too many for oper, therefore program crashes
    for i : 1 .. upper (oper) %Showing spaces to provd we've seperated
        put nums (i), " ", oper (i), " " ..
    end for
    % Since there's one more, show it!
    put nums (upper (nums))
   
    %Showing more seperation (\n is same as: put "")
    put "\n\n\nOperations in Equation:"
    put "-----------------------"
    for i : 1 .. upper (oper)
        put oper (i)
    end for
    put "\nNumbers in Equation"
    put "-------------------"
    for i : 1 .. upper (nums)
        put nums (i)
    end for

end separate

separate ("55x3+55522342-5*2/6=10")

% Enjoy.
ZeroPaladn




PostPosted: Thu Dec 01, 2005 9:59 am   Post subject: (No subject)

i would have posted, if i understood what he was trying to dowith tat program :\
jamonathin




PostPosted: Thu Dec 01, 2005 11:48 am   Post subject: (No subject)

ZeroPaladn wrote:
i would have posted, if i understood what he was trying to dowith tat program :\

Separation Code - seperate code Razz.

Me to oactually, i had to read it acouple times. He said he was in calculus so i figured his equation was 55x^3 (cubed) and he was going to be taking the derivitve. I guess he still can tho with that code. Confused
FeZbOy




PostPosted: Tue Dec 06, 2005 11:24 am   Post subject: (No subject)

Sweet, Thx
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: