Presentation is loading. Please wait.

Presentation is loading. Please wait.

More on Psuedo-Code Sangeetha Parthasarathy 1/23/01.

Similar presentations


Presentation on theme: "More on Psuedo-Code Sangeetha Parthasarathy 1/23/01."— Presentation transcript:

1 More on Psuedo-Code Sangeetha Parthasarathy 1/23/01

2 Modules Reusing work: Sometimes, one finds that an algorithm has to do same thing in different places. For example: To calculate average of the grades for students. One does not how many students in Advance, so we use an module that accepts the grades of number of students and finding their average. We could redefine the same set of statements of n of students, but that would be a repetition. If a change is to made in the statement, it would led to the problem of changing it certain places and forget to change in some places. This would led to algorithm in inconsistent state.

3 To avoid the above problems, one includes modules in psuedo- code. A module consists of three components: Input: Information that must be supplied to the module from outside. If module does need input from outside, then input is specified none. Process: A logic (specification) stating what the module does. Output: A result achieved due to processing performed in the module. The output is a value can be assigned to a variable. If module does not produce any value, then output is specified as none. If module returns a value, then there must be RETURN statement.

4 An Example of Module For example we might include to accept student number : Module: Name: getStudentNumber Input:None Output:studentNumber Process: PRINT(Please enter a student number) READ(studentNumber) RETURN(studentNumber)

5 Recursion Achieve Repetition in alternate way: You have seen in earlier sessions that repetition can be achieved by WHILE or FOR loops. However there is alternate to achieve repetition called recursion. Recursion is used in Modules that take at least one input. A recursive module always directly returns an output when some condition involving input(s) is true.


Download ppt "More on Psuedo-Code Sangeetha Parthasarathy 1/23/01."

Similar presentations


Ads by Google