SlideShare ist ein Scribd-Unternehmen logo
1 von 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.

Weitere Àhnliche Inhalte

Ähnlich wie Pseudocode-cheat-sheet-A4.docx

Pseudocode
PseudocodePseudocode
Pseudocodegrahamwell
 
Uses & Abuses of Mocks & Stubs
Uses & Abuses of Mocks & StubsUses & Abuses of Mocks & Stubs
Uses & Abuses of Mocks & StubsPatchSpace Ltd
 
loopingstatementinpython-210628184047 (1).pdf
loopingstatementinpython-210628184047 (1).pdfloopingstatementinpython-210628184047 (1).pdf
loopingstatementinpython-210628184047 (1).pdfDheeravathBinduMadha
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in pythonRaginiJain21
 
Ecs 10 programming assignment 4 loopapalooza
Ecs 10 programming assignment 4   loopapaloozaEcs 10 programming assignment 4   loopapalooza
Ecs 10 programming assignment 4 loopapaloozaJenniferBall44
 
ppt7
ppt7ppt7
ppt7callroom
 
ppt2
ppt2ppt2
ppt2callroom
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n2
name name2 n2name name2 n2
name name2 n2callroom
 
test ppt
test ppttest ppt
test pptcallroom
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
ppt21
ppt21ppt21
ppt21callroom
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
ppt17
ppt17ppt17
ppt17callroom
 
ppt30
ppt30ppt30
ppt30callroom
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.pptcallroom
 
ppt18
ppt18ppt18
ppt18callroom
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmersamiable_indian
 
ppt9
ppt9ppt9
ppt9callroom
 

Ähnlich wie 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
 

Mehr von MrSaem

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

Mehr von 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
 

KĂŒrzlich hochgeladen

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...Orbitshub
 
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...Jeffrey Haguewood
 
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 TerraformAndrey Devyatkin
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
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 Ontologyjohnbeverley2021
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
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 FresherRemote DBA Services
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
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 DevelopersWSO2
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 

KĂŒrzlich hochgeladen (20)

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...
 
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...
 
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
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
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
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
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
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
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
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

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.