Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
procedure help
Author Message
Schaef

Posted: Tue Jan 20, 2004 7:13 am   Post subject: procedure help

I was just wondering in a procedure what the things in the bracket are after proc and the name of the procedure and why the variables do not need to be assigned values

CjGaughan

Posted: Tue Jan 20, 2004 10:38 am   Post subject: (No subject)

SUBPROGRAMS

A part of a program (a subprogram) can be given a name. There are two kinds of subprograms:

1) Functions
2) Procedures

There are subprograms that are predefined (provided as part of the Turing language).

These include:

-sqrt -- a predefined function that gives the square root of a number.

randint - a predefined procedure that generates random integers

A function takes a value, such as 3, and produces a result, such as 9. In this example, the function produces the square of the number it receives; so when it receives 3 it produces 3**2 = 9

example:

function square (x : real) : real
result x**2
end square

for i : 1 .. 5
put i : 2, square (i) : 4
end for

We say that the square function is called and that actual parameter i is passed to formal parameter x.

AN EXAMPLE FUNCTION

The function shown here takes a name such as "fred jones" and produces a result string with the last name first : "Jones, Fred"

basically, the part in the brackets is the kind of variable that will be used for input.

here is an example code (calculates area of a circle):

 code: const pi := 3.141592654 function circleArea (rad : real) : real     var area : real     area := pi * rad ** 2     result area end circleArea var r : real put "Enter the radius of the circle: " .. get r put "The area of that circle is: ", circleArea (r) : 5 : 2 var choice : string put ""

dont know if this helps...but oh well
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 2 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: