Pseudocode (unit 8) Flashcards

(29 cards)

1
Q

Rule for keywords

A

Must be capital

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

How to show comments

A

//

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

State 5 data types + how are they written/delimited

A
  1. INTEGER = whole number
  2. REAL = number capable of containing a fractional part. At least 1 number on both sides of decimal point.
  3. CHARACTER = a single character. Written using single brackets ‘ ‘
  4. STRING = a sequence of characters. Written using double brackets “ “
  5. BOOLEAN = logic values true and false
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Identifiers

A

Names given to variables, constants, procedures & functions. Letters and digits only.

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

Declaration

A

States/declares data type of variable (by its identifier).
DECLARE [identifier] : [data type]

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

Constant

A

A value in a program that never changes.

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

Assignment operator

A

<— (arrow)
Format: identifier <— value

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

Array + declaration (1d & 2d)

A

Fixed-length structure of elements of identical data types, accessible using index numbers. E.g. ArrayName[Index] <— 23
1d: DECLARE identifier : ARRAY[1:30] OF data type
2d: DECLARE identifier : ARRAY[1:30, 1:30] OF data type

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

Input and output operations

A

INPUT identifier
OUTPUT values or “string”

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

Not standard arithmetic operations

A

^ = to the power of
DIV(x,y) = returns quotient/whole number left after division of x by y
MOD(x,y) = returns remainder after division of x by y

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

Not equal to symbol

A

<>

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

4 string operations

A
  1. LENGTH(identifier) = length of string
  2. LCASE(identifier) = returns string/character in lowercase
  3. UCASE(identifier) = returns string/character in uppercase
  4. SUBSTRING(identifier, start, length) = returns string of length length from position start. In pseudo code, first position is usually 1.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Round & random library routines

A
  1. ROUND(identifier, places) = returns value rounded to places d.p
  2. RANDOM() = returns random number between 0 and 1 (inclusive)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Selection

A

IF condition:
THEN
statements
ELSE
statements
ENDIF
(THEN can be placed in same line as IF, and ELSE is not needed. ELIF can be used)

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

State & explain 3 types of loops

A
  1. Count-controlled loop = for loop. Repeats loop/program set number of times.
  2. Post-condition loop = REPEAT…until loops. Repeats loop until a condition is true. Executed at least once.
  3. Pre-condition loop = while…do loop. Repeats loop while a condition is true. Tested before statements, and is only executed if condition evaluates to True. May run 0 times if condition is false beforehand.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Variable

A

Data structure used to store value in a program that can change/be overwritten any number of times.

17
Q

For loop structure

A

FOR identifier <— value1 to value2:
statements
NEXT identifier

18
Q

Repeat loop structure

A

REPEAT
statements
UNTIL condition

19
Q

While loop structure

A

WHILE condition DO
statements
ENDWHILE

20
Q

Subroutines

A

Functions & procedures. Blocks of associated code/subroutines (separated piece of named code that performs a particular task) that can be called multiple times.

21
Q

Parameter + purpose

A

Value that adds extra information to a subroutine to adjust its behavior.
Alows procedure to be reused with different data/values.

22
Q

Procedure structure

A

Does not return value.
PROCEDURE identifier (parameter:datatype)
statements
ENDPROCEDURE
To call:
CALL identifier

23
Q

Function

A

= additional parameters can be added, in order to specify what variables the function is operating on

Return a single value to the point at which they are called.
FUNCTION identifier (p) RETURNS data type
RETURN statements
ENDFUNCTION
Cannot be called, would use it in output/print statement
p = possible parameters

24
Q

File handling

A

OPENFILE “file identifier.txt” FOR file mode
statement
CLOSEFILE ‘file identifier.txt’
File mode can be READ or WRITE (new file will be created & any existing data in the file will be lost)
Statement can be:
1. READFILE ‘identifier.txt’, variable - data from file will be read from text file into variable
2. WRITEFILE ‘identifier.txt’, variable - data from variable is written into file.

25
Write an example for loop printing all elements in array in pseudo code
array <-- [] for i <-- 1 to y (length/number of times you iterate): OUTPUT array[i] NEXT i
26
State 4 ways to write program so that it can be maintained/understood by other programmers + explanation
1. Use comments to explain purpose of different sections of algorithm, e.g. logic or syntax 2. Use meaningful identifiers for variables that clearly explain their purpose, e.g. what it stores 3. Use prodecures & functions to avoid repeating code + to simplify it 4. Use indentation & white space to make program more readable
27
CASE statement
Allow one of several branches to be executed depending on value of variable. INPUT identifier CASE OF identifier value1 : statement value2 : statement OTHERWISE : statement ENDCASE
28
The function Odds(X) returns ‘Odd’ if the value of X is an odd number and returns ‘Even’ if the value of X is an even number. Write pseudocode statements to: * define the function * call the function using parameter A and store the return item in variable B (explain this)
FUNCTION Odds(X:INTEGER) RETURNS STRING IF MOD(X,2) = 0 THEN RETURN "Even" ELSE RETURN "Odd" ENDIF ENDFUNCTION Calling: B <- Odds(A) This means that the value of A (which is a parameter that is specified earlier) is put into X and undegos the process inside the function. The result (Even or Odd) is then assigned to the variable B.
29
Why is it useful to store data in a file?
Data stored in a file is a permanent copy which prevents it from being lost, so it can be used again in other programs. It can also be easily transferred to another computer like this.