1.2.3 Introduction to Programming Flashcards

1
Q

What is the pseudocode for a WHILE loop?

A

while condition
code to execute
endwhile

———–EXAMPLE————–

while answer!=”computer”
answer=input(“What is the password?”)
endwhile

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the pseudocode for a DO WHILE/UNTIL loop?

A

do
code to execute
until condition

———–EXAMPLE————–

do
answer=input(“What is the password?”)
until answer==”computer”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the pseudocode for a for loop?

A

for i=x to y
code to execute
next i

———–EXAMPLE————–

for i=0 to 7
print(“Hello”)
next i

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

State the 7 arithmetic operators

A

Add (+)
Subtract (-)
Multiply (*)
Divide (/)
MOD (Remainder)
DIV (Whole part of division)
^ (Power)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

State the 6 comparison operators

A

Equal to (==)
Not equal to (!=)
Less than (<)
Less than or equal to (<=)
Greater than (>)
Greater than or equal to (>=)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the pseudocode to output?

A

print(“hello world”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the pseudocode to take an input?

A

VariableName=input(“Please enter your name”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the pseudocode for a substring?

A

stringname.subString(startingPosition, numberOfCharactersToReturn)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the pseudocode for an IF statement?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the pseudocode for a CASE/SWITCH statement?

A

switch entry:
case “A”: print(“You selected A”)
case “B”: print(“You selected B”)
default: print(“Unrecognised selection”)
endswitch

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the pseudocode for a function?

A

function triple(number)
return number*3
endfunction

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the pseudocode for a procedure?

A

procedure greeting(name)
print(“hello”+name)
endprocedure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the pseudocode for reading the contents of a file?

A

myFile = openRead(“sample.txt”)

while NOT myFile.endOfFile()
print(myFile.readLine())
endwhile

myFile.close()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the pseudocode for writing to a file?

A

myFile = openWrite(“sample.txt”)

myFile.writeLine(“Hello World”)

myFile.close()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the pseudocode to declare, populate, and print a two-item 1D array?

A

array names[2]

names[0]=”Ahmad”
names[1]=”Ben”

print(names[1])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the pseudocode to declare a 2D array and modify the first element?

A

Array board[8,8]

board[0,0]=”rook”

17
Q

What is the pseudocode to declare a 3D array and modify the first element?

A

Array board[8,8,8]

board[0,0,0]=”rook”

18
Q

List the 11 mnemonics used in LMC

A

ADD
SUB

STA
LDA

BRA
BRP
BRZ

INP

OUT

HLT

DAT

19
Q

Write the LMC code to take two inputs and output the biggest of them.

A
20
Q

What is the pseudocode to output the length of a string?

A

stringname.length

21
Q

What is the pseudocode for the substring command?

A

stringname.subString(startingPosition, numberToReturn)

22
Q

What is the pseudocode to get a set number of characters from the left hand side of a string?

A

stringname.left(numberOfCharacters)

23
Q

aWhat is the pseudocode to get a set number of characters from the right hand side of a string?

A

stringname.right(numberOfCharacters)

24
Q

What is the pseudocode to convert a string to and from upper case?

A

stringname.upper

stringname.lower

25
Q

How do you convert a character to its ASCII value?

A

ASC(‘A’)

Returns 65 as the ASCII value

26
Q

How do you convert a character from its ASCII value?

A

CHR(65)

Returns ‘A’

27
Q

Explain the following piece of LMC code

A

Subtracts num2 from num1 and outputs the answer