Explore BrainMass

Analyze Pseudocode

This content was STOLEN from BrainMass.com - View the original, and get the solution, here!

The following are a few examples of pseudocode:

>> Example 1


read Customer_Order_Record
if Quantity > 100 then

Discount = 20


if Quantity > 12 then

Discount = 10



Total = Price* Quantity
Total = Total - (Discount* Total)/100
Print Total


>> Example 2


Read Student_Marks_File
Pass = 0
Fail = 0
Total = 0
X = 0
while (End Of Student_Marks_File) do

Total = Total + Subject_Marks

if (Subject_Marks > 40) then

Print "Student passed in" Subject


Print "Student failed in" Subject

X = X +1
Read Next Record

Average = Total/X
Print "Average Marks of" Student_Name "are" Average


From the above examples of pseudocode containing control structures, analyze the logic implemented in the pseudocode.

© BrainMass Inc. brainmass.com September 21, 2018, 5:50 am ad1c9bdddf - https://brainmass.com/computer-science/pseudocode/analyze-pseudocode-457633

Solution Preview

First, some basic definition taken from http://www.cs.cornell.edu/Courses/cs482/2003su/handouts/pseudocode.pdf

"Algorithms will often be expressed in pseudocode, a mixture of code and English ... Pseudocode strikes a sometimes precarious balance between the understandability and informality of English and the precision of code."

(it's worth reading the whole PDF by the way).

Keep in mind that unlike a programming language where there's a defined syntax, no 'standard' way exists in writing pseudocode. The key point to keep in mind when writing one is clarity and readability while being able to convey the essence of the algorithm outlined.

That said, the following is the analysis of pseudocode in example 1:

1. (Stating the obvious) It can be seen that a pseudocode block is enclosed within the start and stop commands.
2. The next block of the algorithm

read Customer_Order_Record

performs reading of some "Customer_Order_Record" from somewhere. Notice here that the pseudocode is kept high-level and does not specify the exact mechanism of how to perform this reading and from where. The input could be read, for instance, from some IO stream off the disk or input typed by the user from the console or some data streamed from the network. The specific details are left out for implementation.

3. The next conditional statement

if Quantity > 100 then

Discount = 20 ...

Solution Summary

The solution analyzes pseudocodes.