Computer Science Canada

help quick before tomorrows exam!

Author:  Ryan [ Thu Jan 23, 2003 8:55 pm ]
Post subject:  help quick before tomorrows exam!

Hey, may seem a dumb question but i can't remember if you can have more than one output variable from a procedure. i have to do some review before my exam tomorrow, and the context the question is from is this:

Write a turing program to determine if a triangle is really a triangle given the length of it's sides.

we just learned about subprograms recently, so i apologize for the question.

I think i need to accept several inputs all from one variable then cast them into different variables. if i'm correct, then i believe i need to put more than one variable as the output at the start.

procedure Sides (var length : int, var lengths : real)


thanls for any help!

Ryan

Author:  Tony [ Thu Jan 23, 2003 9:06 pm ]
Post subject: 

procedures don't output variables... thats functions Confused

and you can have unlimited number of arguments passed into the procedure...

so
code:

function triangle(side1:real, side2:real, side3:real):boolean

var largeside:real :=0

if side1>largeside then
largeside := side1
end if

if side2>largeside then
largeside := side2
end if

if side3>largeside then
largeside := side3
end if

if largeside < side1+side2+side3-largeside then
return true
else
return false
end if

end triangle


A bit of explanation there... this is a function and returns a value... true if its a triangle, false if its not.

Those 3 if statments are semplified version of the bubble sord with loop removed, needed to find the largest side.

last if statment makes sure that largest side is less then sum of 2 others and returns "true", otherwise the triangle is impossible so the function return false.

Good luck on your exam


: