Documente Academic
Documente Profesional
Documente Cultură
In this
course we will enforce three standards for good pseudo code
Example #1 - Computing Sales Tax : Pseudo-code the task of computing the final price
of an item after figuring in sales tax. Note the three types of instructions: input (get),
process/calculate (=) and output (display)
6. halt
Variables: price of item, sales tax rate, sales tax, final price
Note that the operations are numbered and each operation is unambiguous and effectively
computable. We also extract and list all variables used in our pseudo-code. This will be
useful when translating pseudo-code into a programming language
Example #2 - Computing Weekly Wages: Gross pay depends on the pay rate and the
number of hours worked per week. However, if you work more than 40 hours, you get
paid time-and-a-half for all hours worked over 40. Pseudo-code the task of computing
gross pay given pay rate and hours worked.
4. else
4.1 gross pay = pay rate times 40 plus 1.5 times pay rate times
(hours worked minus 40)
6. halt
This example introduces the conditional control structure. On the basis of the true/false
question asked in line 3, we execute line 3.1 if the answer is True; otherwise if the answer
is False we execute the lines subordinate to line 4 (i.e. line 4.1). In both cases we resume
the pseudo-code at line 5.
2. sum = 0
3. count = 0
6. display average
7. halt
This example introduces an iterative control statement. As long as the condition in line 4
is True, we execute the subordinate operations 4.1 - 4.3. When the condition becomes
False, we resume the pseudo-code at line 5.
Computation/Assignment
Input/Output
6. if "condition"
6.1 (subordinate) statement 1
6.2 etc ...
7. else
7.1 (subordinate) statement 2
7.2 etc ...