PSEUDOCODEPSEUDOCODEC Programming Technique – Firdaus-Harun.com
AgendaAgendaIntro to PseudocodePseudocode vs FlowchartTechnique – Write pseudocodeExamples
What’s Pseudocode ?What’s Pseudocode ?Artificial and Informal languageHelps programmers to plan an
algorithmSimilar to everyday EnglishNot an actual programming
language
E.g : PseudocodeE.g : Pseudocode
Read A, BCalculate C = A*BDisplay CStop
TechniqueTechnique Do not write Start in every
pseudocodeParallelogram – Read / Get OR
Display / PrintRectangle – Specify the actions
◦E.g: Calculate A = B + C OR A equals to B plus C Average = total / count Final price equals price of item plus sales tax
Diamond – [Next »]
Technique (..Cont.)Technique (..Cont.)Diamond
◦Selection – IF , IF / ELSE and IF / ELSE IF
IF A is less than BBIG = BSMALL = A
ELSEBIG = ASMALL = B
◦Repetition – WHILE / DO/WHILE / FOR [Next example]
Comparative Between Comparative Between Flowchart vs PseudocodeFlowchart vs PseudocodeFlowchart
◦A graphical way of writing pseudocode
◦Rounded rectangle – terminal◦Parallelogram – input / output◦Rectangle – actions◦Diamonds – decision / conditional◦Circles – connector
E.g : FlowchartE.g : FlowchartStart
Stop
Read ARead B
Display theResult C
Calculate ResutC=A*B
Start Terminal. Program start here
Stop TerminalProgram end here
Input.Enter values for A and B
Process
Output
Comparative Between Comparative Between Flowchart vs Pseudocode Flowchart vs Pseudocode (..Cont.)(..Cont.)Pseudocode
◦No syntax rule – Independent from any programming language
◦Write in an ordinary language◦Uses a structure resembling
computer structure◦No connector between pages
E.g : PseudocodeE.g : Pseudocode
Read A, BCalculate C = A*BDisplay CStop
E.g : PseudocodeE.g : Pseudocode
Read A, B – InputCalculate C = A*B - ActionDisplay C - OutputStop - Terminal
Example 2 (Selection)Example 2 (Selection)Read A, B
IF A is less than BBIG = BSMALL = A
ELSEBIG = ASMALL = B
Write / Display BIG, SMALLStop
Example 2 (Selection)Example 2 (Selection)Read A, B - Input
IF A is less than B - SelectionBIG = B - ActionSMALL = A - Action
ELSE - SelectionBIG = A - ActionSMALL = B - Action
Write / Display BIG, SMALL - OutputStop - Terminal
Example 3 (Repetition)Example 3 (Repetition)Set count to zeroSet total to zeroRead number
WHILE ( not end-of-data )increment count by 1total = total + numberread number
IF ( count > 0 ) thenaverage = total / count
Display averageStop
AdvantagesAdvantagesConverting a pseudocode to a
programming language is much more easier than converting a flowchart.
As compared to flowchart, it is easier to modify a pseudocode of a program logic when program modifications are necessary.
LimitationsLimitationsIn the cases of pseudocode, a
graphic representation of program logic is not available.
There are no standard rules to follow for using a pseudocode. ◦Different programmers use their own
style of writing pseudocode; and hence,
◦Communication problem occurs due to lack of standardization.
Class TutorialClass Tutorial*Using previous Flowchart
tutorial.Write a pseudocode to calculate
Area and Perimeter of a trapezoid.
Write an algorithm to set a Median for given number : ………………………..