SlideShare a Scribd company logo
1 of 6
Pseudocode
Cheat Sheet
What is pseudocode?
Pseudo-code isanalternative methodof describinganalgorithmthatusestextinsteadof adiagram.
Pseudo-code canbe thoughtof as a simplifiedformof programmingcode.
The prefix ‘pseudo’means‘false’or‘notgenuine’.
Writingpseudocode allowsustolaydownthe logicof a problemina “almostlike real code”waywithouthavingtoworryaboutthe actual strict rules
and syntax of a particularlanguage.
So what isthis cheat sheet?
Thischeat sheetprovidesadvice onthe formatinwhich youshouldwrite pseudocodewhenansweringOCRexamquestions. Practice makesperfect.
Throughoutyourcourse practice producingpseudocodebefore youcode upsolutionstoproblemsand itwill become secondnature inthe exam.
Rulesfor writing pseudo-code
By definition,thereare nohard andfast rulesforwritingpseudo-code,butcertainguidelineswill ensure thatthe algorithmisclear:
 Describe eachstepof the algorithmas brieflyaspossible.
 Use UPPERCASEletterswithkeywordsandotherpartsof the pseudo-code whichare closertoa programminglanguage.
 User lowercase letterswithpartsof the pseudo-code whichare closertoEnglish.
 If you use keywordstoshowthe beginningandendof a blockof code,thenthe code inside the blockshouldbe indented.
 NumberedorbulletedlistswritteninEnglishisNOTenoughforA’Level exams!
Pseudocode
Cheat Sheet
Concept Example Pseudocode Notes
Variables x=3
name="Bob"
Variables areassigned usingthe= operator
global userid = 123 Variables declared insidea function or procedure are assumed to be local to that subroutine.
Variables in themain program can be made global with the keyword global.
Casting str(3) returns "3"
int("3") returns 3
float("3.14") returns 3.14
Variables should betypecast usingthe int, str, and float functions.
Outputting to screen PRINT("hello") PRINT(string)
Taking input from user name = INPUT("Please enter your name") Variable = INPUT(prompt to user)
Iteration – Count
controlled
FOR I = 0 to 7
PRINT("Hello")
NEXT i
This would print hello 8 times (0-7 inclusive).
Iteration – Condition
controlled
WHILE answer != "computer”
answer = INPUT("What is the password?")
ENDWHILE
WhileLoop
DO
Answer = INPUT("What is the password?")
UNTIL answer == "computer"
Do Until Loop
Logical operators WHILE x <=5 AND flag == FALSE AND OR NOT
Comparison operators == Equal to
!= Not equal to
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
Arithmetic operators + Addition e.g. x=6+5 gives 11
- Subtraction e.g. x=6-5 gives 1
* Multiplication e.g. x=12*2 gives 24
/ Division e.g. x=12/2 gives 6
MOD Modulus e.g. 12MOD5 gives 2
DIV Quotient e.g. 17DIV5 gives 3
^ Exponentiation e.g. 3^4 gives 81
Pseudocode
Cheat Sheet
Concept Example Pseudocode Notes
Selection IF entry == "a" THEN
PRINT("You selected A")
ELSEIF entry == "b" then
PRINT("You selected B")
ELSE
PRINT("Unrecognised selection")
ENDIF
IF / ELSE selection
SWITCH ENTRY:
CASE "A":
PRINT("You selected A")
CASE "B":1
PRINT("You selected B")
DEFAULT:
PRINT("Unrecognised selection")
ENDSWITCH
SWITCH / CASE selection
String handling stringname.LENGTH To get the length of a string
stringname.SUBSTRING(startingPosition, numberOfCharacters) To get a substring
Subroutines FUNCTION triple(number)
RETURN number * 3
ENDFUNCTION
Called from main program
Y =triple(7)
Function
PROCEDURE greeting(name)
PRINT("hello" + name)
ENDPROCEDURE
Called from main program
greeting("Hamish")
Procedure
PROCEDURE foobar(x:byVal, y:byRef)
…
…
ENDPROCEDURE
Unless stated values passed to subroutines can be assumed to be passed by valuein
the exam.
If this is relevantto the question byVal and byRef will be used. In the caseshown here
x is passed by valueand y is passed by reference.
Pseudocode
Cheat Sheet
Concept Example Pseudocode Notes
Arrays / Lists ARRAY names[5]
names[0] = "Ahmad"
names[1] = "Ben"
names[2] = "Catherine"
names[3] = "Dana"
names[4] = "Elijah"
PRINT(names[3])
Arrays should be 0 based and declared with the keyword array.
ARRAY board[8,8]
board[0,0] = "rook"
Example of 2D array
Reading to and writing
from files
myFile = OPENREAD("sample.txt")
x = myFile.READLINE()
myFile.CLOSE()
To open a fileto read you should useOPENREAD.
READLINE should be used to return a lineof text from the file.
The example on the left makes x the firstlineof sample.txt
ENDOFFILE() This is used to determine if the end of a filehas been reached.
myFile = OPENREAD("sample.txt")
WHILE NOT myFile.ENDOFFILE()
PRINT(myFile.READLINE())
ENDWHILE
myFile.CLOSE()
The example on the left will printoutthe contents of sample.txt
myFile = OPENWRITE("sample.txt")
myFile.WRITELINE("Hello World")
myFile.CLOSE()
To open a fileto write to openWrite is used and writeLine to add a lineof text to the
file.In the programbelow hello world is made the contents of sample.txt (any
previous contents are overwritten).
Comments PRINT("Hello World") //This is a comment Comments are denoted by //
Pseudocode
Cheat Sheet
The followingPseudocode coversObject-Orientedprogrammingandisonlyrequiredforthe full A’Level specification.
Concept Example Pseudocode Notes
Methods and
attributes
PUBLIC and PRIVATE
PRIVATE attempts = 3
PUBLIC PROCEDURE setAttempts(number)
attempts = number
ENDPROCEDURE
PRIVATE FUNCTION getAttempts()
RETURN attempts
END FUNCTION
Methods and attributes can be assumed to be public unless otherwisestated.
Where the access level is relevantto the question it will alwaysbeexplicitin the code
denoted by the keywords.
player.setAttempts(5)
PRINT(player.getAttempts())
Methods should always beinstancemethods, you are not expected to be awareof
static methods. You should call them usingobject.method as shown on the left.
Constructors and
inheritance
CLASS Pet
PRIVATE name
PUBLIC PROCEDURE NEW(givenName)
Name = givenName
ENDPROCEDURE
ENDCLASS
You should writeconstructors as you would procedures with the name new
SUPER.methodName(parameters) You should show Inheritanceby usingthe keyword inherits keyword
Superclass methods should be called with the keyword super.
CLASS dog INHERITS Pet
PRIVATE breed
PUBLIC PROCEDURE NEW(givenName, givenBreed)
SUPER.NEW(givenName)
Breed = givenBreed
ENDPROCEDURE
ENDCLASS
In the caseof the constructor the pseudocode would look likethe example on the left.
objectName = NEW className(parameters)
e.g.
myDog = NEW Dog("Fido","Scottish Terrier")
To create an instanceof an object the followingformatis used
Pseudocode
Cheat Sheet
Three examplesof writingpseudocode forthe same algorithm:Dispensingcashat a cash pointmachine.
BEGIN
INPUT CardNumber
REPEAT
INPUT PIN
IF PIN is wrong for this CardNumber THEN
OUTPUT “Wrong PIN”
END IF
UNTIL PIN is correct
INPUT Amount
IF there are enough funds THEN
Dispense Cash
Update customer’s balance
ELSE
OUTPUT “Sorry, insufficient funds”
END IF
END
BEGIN
CardNumber=INPUT(“Please enter Card Number”)
DO
Pin=INPUT(“Please enter Pin”)
IF Pin != CorrectPin
PRINT(“Wrong PIN”)
END IF
UNTIL Pin==CorrectPin
Amount=INPUT(“How much money would you like?”)
IF Amount <= CurrentBalence THEN
DispenseCash(Amount)
CurrentBalence = CurrentBalence - Amount
ELSE
PRINT(“Sorry, insufficient funds”)
END IF
END
1. Input card number
2. Repeat
a. Input pin
b. Check if pin is correct
i. If it’s not output “Wrong pin”
3. Until the pin is correct
4. Input amount
5. If there are enough funds
a. Dispense cash
b. Update customer’s balance
6. If there are not enough funds
a. Output “Sorry, insufficient funds
VERSION 1 VERSION 2 VERSION 3
This is too much like structuredEnglish.
It wouldreceive little to no credit in anexam.
This versionis good.
It useskey words,correctindentationandthelogic of
the problemcanbe clearly seen.
This wouldget decentmarksin an exam.
This is the best version.
Mathematicalcomparisonoperatorsused.
Variableassignmentshown.
Completeunderstanding of theproblemtobecoded.
This wouldget full marksin anexam.

More Related Content

Similar to Pseudocode-cheat-sheet-A4.docx

Uses & Abuses of Mocks & Stubs
Uses & Abuses of Mocks & StubsUses & Abuses of Mocks & Stubs
Uses & Abuses of Mocks & Stubs
PatchSpace Ltd
 
loopingstatementinpython-210628184047 (1).pdf
loopingstatementinpython-210628184047 (1).pdfloopingstatementinpython-210628184047 (1).pdf
loopingstatementinpython-210628184047 (1).pdf
DheeravathBinduMadha
 

Similar to Pseudocode-cheat-sheet-A4.docx (20)

Pseudocode
PseudocodePseudocode
Pseudocode
 
Uses & Abuses of Mocks & Stubs
Uses & Abuses of Mocks & StubsUses & Abuses of Mocks & Stubs
Uses & Abuses of Mocks & Stubs
 
loopingstatementinpython-210628184047 (1).pdf
loopingstatementinpython-210628184047 (1).pdfloopingstatementinpython-210628184047 (1).pdf
loopingstatementinpython-210628184047 (1).pdf
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
 
Ecs 10 programming assignment 4 loopapalooza
Ecs 10 programming assignment 4   loopapaloozaEcs 10 programming assignment 4   loopapalooza
Ecs 10 programming assignment 4 loopapalooza
 
11script
11script11script
11script
 
ppt7
ppt7ppt7
ppt7
 
ppt2
ppt2ppt2
ppt2
 
name name2 n
name name2 nname name2 n
name name2 n
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
 
test ppt
test ppttest ppt
test ppt
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt21
ppt21ppt21
ppt21
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt17
ppt17ppt17
ppt17
 
ppt30
ppt30ppt30
ppt30
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.ppt
 
ppt18
ppt18ppt18
ppt18
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmers
 
ppt9
ppt9ppt9
ppt9
 

More from MrSaem (9)

pseudocode practice.pptx
pseudocode practice.pptxpseudocode practice.pptx
pseudocode practice.pptx
 
Python Functions.pptx
Python Functions.pptxPython Functions.pptx
Python Functions.pptx
 
Backus Naur Form.pptx
Backus Naur Form.pptxBackus Naur Form.pptx
Backus Naur Form.pptx
 
3 Monitoring and control.pptx
3 Monitoring and control.pptx3 Monitoring and control.pptx
3 Monitoring and control.pptx
 
6 The digital divide.pptx
6 The digital divide.pptx6 The digital divide.pptx
6 The digital divide.pptx
 
Chapter 6 Python Fundamentals.pptx
Chapter 6 Python Fundamentals.pptxChapter 6 Python Fundamentals.pptx
Chapter 6 Python Fundamentals.pptx
 
Chapter 8 system soft ware
Chapter 8 system soft wareChapter 8 system soft ware
Chapter 8 system soft ware
 
Adt
AdtAdt
Adt
 
Recursion
RecursionRecursion
Recursion
 

Recently uploaded

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
Christopher Logan Kennedy
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 

Pseudocode-cheat-sheet-A4.docx

  • 1. Pseudocode Cheat Sheet What is pseudocode? Pseudo-code isanalternative methodof describinganalgorithmthatusestextinsteadof adiagram. Pseudo-code canbe thoughtof as a simplifiedformof programmingcode. The prefix ‘pseudo’means‘false’or‘notgenuine’. Writingpseudocode allowsustolaydownthe logicof a problemina “almostlike real code”waywithouthavingtoworryaboutthe actual strict rules and syntax of a particularlanguage. So what isthis cheat sheet? Thischeat sheetprovidesadvice onthe formatinwhich youshouldwrite pseudocodewhenansweringOCRexamquestions. Practice makesperfect. Throughoutyourcourse practice producingpseudocodebefore youcode upsolutionstoproblemsand itwill become secondnature inthe exam. Rulesfor writing pseudo-code By definition,thereare nohard andfast rulesforwritingpseudo-code,butcertainguidelineswill ensure thatthe algorithmisclear:  Describe eachstepof the algorithmas brieflyaspossible.  Use UPPERCASEletterswithkeywordsandotherpartsof the pseudo-code whichare closertoa programminglanguage.  User lowercase letterswithpartsof the pseudo-code whichare closertoEnglish.  If you use keywordstoshowthe beginningandendof a blockof code,thenthe code inside the blockshouldbe indented.  NumberedorbulletedlistswritteninEnglishisNOTenoughforA’Level exams!
  • 2. Pseudocode Cheat Sheet Concept Example Pseudocode Notes Variables x=3 name="Bob" Variables areassigned usingthe= operator global userid = 123 Variables declared insidea function or procedure are assumed to be local to that subroutine. Variables in themain program can be made global with the keyword global. Casting str(3) returns "3" int("3") returns 3 float("3.14") returns 3.14 Variables should betypecast usingthe int, str, and float functions. Outputting to screen PRINT("hello") PRINT(string) Taking input from user name = INPUT("Please enter your name") Variable = INPUT(prompt to user) Iteration – Count controlled FOR I = 0 to 7 PRINT("Hello") NEXT i This would print hello 8 times (0-7 inclusive). Iteration – Condition controlled WHILE answer != "computer” answer = INPUT("What is the password?") ENDWHILE WhileLoop DO Answer = INPUT("What is the password?") UNTIL answer == "computer" Do Until Loop Logical operators WHILE x <=5 AND flag == FALSE AND OR NOT Comparison operators == Equal to != Not equal to < Less than <= Less than or equal to > Greater than >= Greater than or equal to Arithmetic operators + Addition e.g. x=6+5 gives 11 - Subtraction e.g. x=6-5 gives 1 * Multiplication e.g. x=12*2 gives 24 / Division e.g. x=12/2 gives 6 MOD Modulus e.g. 12MOD5 gives 2 DIV Quotient e.g. 17DIV5 gives 3 ^ Exponentiation e.g. 3^4 gives 81
  • 3. Pseudocode Cheat Sheet Concept Example Pseudocode Notes Selection IF entry == "a" THEN PRINT("You selected A") ELSEIF entry == "b" then PRINT("You selected B") ELSE PRINT("Unrecognised selection") ENDIF IF / ELSE selection SWITCH ENTRY: CASE "A": PRINT("You selected A") CASE "B":1 PRINT("You selected B") DEFAULT: PRINT("Unrecognised selection") ENDSWITCH SWITCH / CASE selection String handling stringname.LENGTH To get the length of a string stringname.SUBSTRING(startingPosition, numberOfCharacters) To get a substring Subroutines FUNCTION triple(number) RETURN number * 3 ENDFUNCTION Called from main program Y =triple(7) Function PROCEDURE greeting(name) PRINT("hello" + name) ENDPROCEDURE Called from main program greeting("Hamish") Procedure PROCEDURE foobar(x:byVal, y:byRef) … … ENDPROCEDURE Unless stated values passed to subroutines can be assumed to be passed by valuein the exam. If this is relevantto the question byVal and byRef will be used. In the caseshown here x is passed by valueand y is passed by reference.
  • 4. Pseudocode Cheat Sheet Concept Example Pseudocode Notes Arrays / Lists ARRAY names[5] names[0] = "Ahmad" names[1] = "Ben" names[2] = "Catherine" names[3] = "Dana" names[4] = "Elijah" PRINT(names[3]) Arrays should be 0 based and declared with the keyword array. ARRAY board[8,8] board[0,0] = "rook" Example of 2D array Reading to and writing from files myFile = OPENREAD("sample.txt") x = myFile.READLINE() myFile.CLOSE() To open a fileto read you should useOPENREAD. READLINE should be used to return a lineof text from the file. The example on the left makes x the firstlineof sample.txt ENDOFFILE() This is used to determine if the end of a filehas been reached. myFile = OPENREAD("sample.txt") WHILE NOT myFile.ENDOFFILE() PRINT(myFile.READLINE()) ENDWHILE myFile.CLOSE() The example on the left will printoutthe contents of sample.txt myFile = OPENWRITE("sample.txt") myFile.WRITELINE("Hello World") myFile.CLOSE() To open a fileto write to openWrite is used and writeLine to add a lineof text to the file.In the programbelow hello world is made the contents of sample.txt (any previous contents are overwritten). Comments PRINT("Hello World") //This is a comment Comments are denoted by //
  • 5. Pseudocode Cheat Sheet The followingPseudocode coversObject-Orientedprogrammingandisonlyrequiredforthe full A’Level specification. Concept Example Pseudocode Notes Methods and attributes PUBLIC and PRIVATE PRIVATE attempts = 3 PUBLIC PROCEDURE setAttempts(number) attempts = number ENDPROCEDURE PRIVATE FUNCTION getAttempts() RETURN attempts END FUNCTION Methods and attributes can be assumed to be public unless otherwisestated. Where the access level is relevantto the question it will alwaysbeexplicitin the code denoted by the keywords. player.setAttempts(5) PRINT(player.getAttempts()) Methods should always beinstancemethods, you are not expected to be awareof static methods. You should call them usingobject.method as shown on the left. Constructors and inheritance CLASS Pet PRIVATE name PUBLIC PROCEDURE NEW(givenName) Name = givenName ENDPROCEDURE ENDCLASS You should writeconstructors as you would procedures with the name new SUPER.methodName(parameters) You should show Inheritanceby usingthe keyword inherits keyword Superclass methods should be called with the keyword super. CLASS dog INHERITS Pet PRIVATE breed PUBLIC PROCEDURE NEW(givenName, givenBreed) SUPER.NEW(givenName) Breed = givenBreed ENDPROCEDURE ENDCLASS In the caseof the constructor the pseudocode would look likethe example on the left. objectName = NEW className(parameters) e.g. myDog = NEW Dog("Fido","Scottish Terrier") To create an instanceof an object the followingformatis used
  • 6. Pseudocode Cheat Sheet Three examplesof writingpseudocode forthe same algorithm:Dispensingcashat a cash pointmachine. BEGIN INPUT CardNumber REPEAT INPUT PIN IF PIN is wrong for this CardNumber THEN OUTPUT “Wrong PIN” END IF UNTIL PIN is correct INPUT Amount IF there are enough funds THEN Dispense Cash Update customer’s balance ELSE OUTPUT “Sorry, insufficient funds” END IF END BEGIN CardNumber=INPUT(“Please enter Card Number”) DO Pin=INPUT(“Please enter Pin”) IF Pin != CorrectPin PRINT(“Wrong PIN”) END IF UNTIL Pin==CorrectPin Amount=INPUT(“How much money would you like?”) IF Amount <= CurrentBalence THEN DispenseCash(Amount) CurrentBalence = CurrentBalence - Amount ELSE PRINT(“Sorry, insufficient funds”) END IF END 1. Input card number 2. Repeat a. Input pin b. Check if pin is correct i. If it’s not output “Wrong pin” 3. Until the pin is correct 4. Input amount 5. If there are enough funds a. Dispense cash b. Update customer’s balance 6. If there are not enough funds a. Output “Sorry, insufficient funds VERSION 1 VERSION 2 VERSION 3 This is too much like structuredEnglish. It wouldreceive little to no credit in anexam. This versionis good. It useskey words,correctindentationandthelogic of the problemcanbe clearly seen. This wouldget decentmarksin an exam. This is the best version. Mathematicalcomparisonoperatorsused. Variableassignmentshown. Completeunderstanding of theproblemtobecoded. This wouldget full marksin anexam.