Computer Science Canada

procedures and functions-project ideas needed?

Author:  Jimbo1991 [ Tue Apr 22, 2008 12:08 pm ]
Post subject:  procedures and functions-project ideas needed?

i have a final project to do with turing, in which procedures and functions need to be used, can anybody give me some ideas that i could do for it? thanks

Author:  Tony [ Tue Apr 22, 2008 12:31 pm ]
Post subject:  RE:procedures and functions-project ideas needed?

absolutely anything. You should be refactoring your code into usable functions anyway.

Author:  Jimbo1991 [ Tue Apr 22, 2008 12:33 pm ]
Post subject:  Re: procedures and functions-project ideas needed?

and what exactly does that mean? im a noob when it comes to turing

Author:  Tony [ Tue Apr 22, 2008 12:35 pm ]
Post subject:  RE:procedures and functions-project ideas needed?

not just Turing
Wikipedia: Refactoring
Quote:
Code refactoring is any change to a computer program's code that improves its readability or simplifies its structure without changing its results.

Author:  Jimbo1991 [ Tue Apr 22, 2008 12:37 pm ]
Post subject:  RE:procedures and functions-project ideas needed?

im still lost, even with wikipedia, how about an example please?

Author:  Tony [ Tue Apr 22, 2008 12:42 pm ]
Post subject:  RE:procedures and functions-project ideas needed?

Turing:

function say_hello()
   put "hello"
end say_hello

put "the program will now greed you"
say_hello()
put "the program is now finished"

Author:  Jimbo1991 [ Tue Apr 22, 2008 12:45 pm ]
Post subject:  RE:procedures and functions-project ideas needed?

o ok, il have to check it out the next time i have a computer that has turing on it

Author:  Tony [ Tue Apr 22, 2008 12:58 pm ]
Post subject:  RE:procedures and functions-project ideas needed?

you could read more on this in tutorials via the Turing Walkthrough

Author:  Saad [ Tue Apr 22, 2008 3:22 pm ]
Post subject:  Re: RE:procedures and functions-project ideas needed?

Tony @ Tue Apr 22, 2008 12:42 pm wrote:
Turing:

function say_hello()
   put "hello"
end say_hello

put "the program will now greed you"
say_hello()
put "the program is now finished"


Perhaps you were in a hurry but it should be procedure not function

Turing:

procedure say_hello ()
    put "hello"
end say_hello

put "the program will now greed you"
say_hello ()
put "the program is now finished"



To answer your orignal question. Functions and procedures are used to put repetative code only once.

Consider the following

Turing:

function GetInput (what : string) : string
    put what
    var input : string
    get input
    result input
end GetInput

var firstName := GetInput ("Please enter your first name")
var lastName := GetInput ("Please enter your last name")


Vs.

Turing:

var firstName, lastName : string
put "Please enter your first name"
get firstName
put "Please enter your last name"
get lastName

Author:  Jimbo1991 [ Wed Apr 23, 2008 12:52 pm ]
Post subject:  RE:procedures and functions-project ideas needed?

finaly i understand! thanks


: