1.2.3 Introduction to Programming Flashcards
What is the pseudocode for a WHILE loop?
while condition
code to execute
endwhile
———–EXAMPLE————–
while answer!=”computer”
answer=input(“What is the password?”)
endwhile
What is the pseudocode for a DO WHILE/UNTIL loop?
do
code to execute
until condition
———–EXAMPLE————–
do
answer=input(“What is the password?”)
until answer==”computer”
What is the pseudocode for a for loop?
for i=x to y
code to execute
next i
———–EXAMPLE————–
for i=0 to 7
print(“Hello”)
next i
State the 7 arithmetic operators
Add (+)
Subtract (-)
Multiply (*)
Divide (/)
MOD (Remainder)
DIV (Whole part of division)
^ (Power)
State the 6 comparison operators
Equal to (==)
Not equal to (!=)
Less than (<)
Less than or equal to (<=)
Greater than (>)
Greater than or equal to (>=)
What is the pseudocode to output?
print(“hello world”)
What is the pseudocode to take an input?
VariableName=input(“Please enter your name”)
What is the pseudocode for a substring?
stringname.subString(startingPosition, numberOfCharactersToReturn)
What is the pseudocode for an IF statement?
if condition then
code to execute
elseif condition then
code to execute
else
code to execute
endif
———–EXAMPLE————–
if entry==”a” then
print(“You selected A”)
elseif entry==”b” then
print(“You selected B”)
else
print(“Unrecognised selection”)
endif
What is the pseudocode for a CASE/SWITCH statement?
switch entry:
case “A”: print(“You selected A”)
case “B”: print(“You selected B”)
default: print(“Unrecognised selection”)
endswitch
What is the pseudocode for a function?
function triple(number)
return number*3
endfunction
What is the pseudocode for a procedure?
procedure greeting(name)
print(“hello”+name)
endprocedure
What is the pseudocode for reading the contents of a file?
myFile = openRead(“sample.txt”)
while NOT myFile.endOfFile()
print(myFile.readLine())
endwhile
myFile.close()
What is the pseudocode for writing to a file?
myFile = openWrite(“sample.txt”)
myFile.writeLine(“Hello World”)
myFile.close()
What is the pseudocode to declare, populate, and print a two-item 1D array?
array names[2]
names[0]=”Ahmad”
names[1]=”Ben”
print(names[1])
What is the pseudocode to declare a 2D array and modify the first element?
Array board[8,8]
board[0,0]=”rook”
What is the pseudocode to declare a 3D array and modify the first element?
Array board[8,8,8]
board[0,0,0]=”rook”
List the 11 mnemonics used in LMC
ADD
SUB
STA
LDA
BRA
BRP
BRZ
INP
OUT
HLT
DAT
Write the LMC code to take two inputs and output the biggest of them.
What is the pseudocode to output the length of a string?
stringname.length
What is the pseudocode for the substring command?
stringname.subString(startingPosition, numberToReturn)
What is the pseudocode to get a set number of characters from the left or right hand side of a string?
stringname.left(numberOfCharacters)
stringname.right(numberOfCharacters)
What is the pseudocode to convert a string to and from upper case?
stringname.upper
stringname.lower
How do you convert a character to its ASCII value?
ASC(‘A’)
Returns 65 as the ASCII value
How do you convert a character from its ASCII value?
CHR(65)
Returns ‘A’
Explain the following piece of LMC code
Subtracts num2 from num1 and outputs the answer