Programming Concepts Flashcards

(42 cards)

1
Q

What is a variable?

A

A variable is an identifier that can change in the lifetime of a program.

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

What are the four variable requirements?

A
  • In mixed case (Pascal case)
  • Only contain letters (A-Z, a-z)
  • Only contain digits (0-9)
  • Start with a capital letter and not a digit
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Example variable declaration

A

DECLARE GameOver : BOOLEAN

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

What is a constant

A

A constant is an identifier set once in the lifetime of a program generally named in all uppercase letters.

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

INTEGER

A

Whole numbers: 5, 0, -5

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

REAL

A

Numbers with a fractional part (decimal): 3.14, -2.5, 0.0

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

CHAR

A

Single character: ‘a’, ‘B’, ‘6’, ‘£’

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

STRING

A

Sequence of characters: “Hello world”, “ABC”, “@#!%”

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

BOOLEAN

A

True or false values: True, False

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

INPUT and OUTPUT example

A

INPUT Answer
OUTPUT “Your answer is”, Answer

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

What is sequence?

A
  • Sequence is when lines of code run one after another in the order they are written, from first to last.
  • It is essential for the correct flow of a program — instructions out of order can cause errors or unexpected results.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

IF Statements syntax

A

IF Answer ← “Yes”
THEN
OUTPUT “Correct”
ELSE
OUTPUT “Wrong”
ENDIF

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

CASE OF Statements syntax

A

INPUT Move

CASE OF Move
‘W’ : Position ← Position - 10
‘E’ : Position ← Position + 10
‘A’ : Position ← Position - 1
‘D’ : Position ← Position + 1
OTHERWISE
OUTPUT “Beep”
ENDCASE

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

What are the two type of selection statements?

A
  • IF Statements
  • CASE OF Statements
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the two type of condition - controlled loops?

A
  • While Loops
  • Repeat Until Loops
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is an example of a count - controlled loop?

A
  • FOR Loops
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

FOR Statements syntax

A

FOR X ← 1 TO 10
OUTPUT “Hello”
NEXT X

18
Q

WHILE Loops syntax

A

INPUT Temperature
WHILE Temperature > 37 DO
OUTPUT “Patient has a fever”
INPUT temperature
END WHILE

19
Q

REPEAT UNTIL Statements Syntax

A

REPEAT
INPUT Colour
UNTIL Colour ← “red”

20
Q

Totalling Syntax

A

Total ← 0
FOR I ← 1 to 10
INPUT Num
TOTAL ← TOTAL + Num
NEXT I
OUTPUT Total

21
Q

Counting Syntax

A

Count ← 0
FOR I ← 1 to 10
INPUT Num
IF Num > 5
THEN
Count ← Count + 1
ENDIF
NEXT I
OUTPUT Count

22
Q

String Handling Uppercase

A

Name ← “Sarah”
OUTPUT UCASE(Name)

23
Q

String Handling Lowercase

A

Name ← “SARAH”
OUTPUT LCASE(Name)

24
Q

String Handling Length

A

Password ← “letmein”
OUTPUT LENGTH(Password)

25
String Handling Substring
Word ← "Revision" OUTPUT SUBSTRING(Word, 1, 3)
26
Logical Operators
- = (equal to) - < (less than) - <= (less than or equal to) - > (greater than) - >= (greater than or equal to) - <> (not equal to)
27
BOOLEAN Operators
- AND: Returns True if both conditions are True - OR: Returns True if one or both conditions are True - NOT: Returns the opposite of the condition (True if False, False if True)
28
Arithmetic Operators
- DIV (10 , 3) returns 3 (whole number division) - MOD (10 , 3) returns (Remainder after division) - * (Multiplication Operator)
29
What's the difference between a function and procedure?
A Function returns a value whereas a procedure does not.
30
What are parameters?
Parameters are values that are passed into a sub program.
31
Uses of subroutines
- Avoid duplicating code and can be reused throughout a program - Improve the readability and maintainability of code - Perform calculations, to retrieve data, or to make decisions based on input
32
What are procedures and functions?
Functions and procedures are a type of sub program, a sequence of instructions that perform a specific task or set of tasks.
33
Procedure Syntax
PROCEDURE CalculateArea(length: INTEGER, width: INTEGER) area ← length * width OUTPUT "The area is ",area END PROCEDURE
34
Calling a Procedure
CALL CalculateArea CALL CalculateArea(5,3)
35
Function Syntax
FUNCTION calculate_area(length: INTEGER, width: INTEGER) RETURNS INTEGER area ← length * width RETURN area ENDFUNCTION // Output the value returned from the function inside the subroutine OUTPUT(calculate_area(5,3))
36
Local Variables
- A variable declared inside a specific scope (like a function or code block). - It’s accessible only within that block and is destroyed once the block finishes executing.
37
Global Variables
- A variable declared outside all functions or procedures. - It has global scope, meaning it can be accessed and modified from anywhere in the program.
38
Library Routines
A piece of reusable, pre-written code made available through modules or functions that can be used in different parts of a program.
39
Two examples of library routines
- ROUND - RANDOM
40
RANDOM Syntax
# Outputs 1.95 RANDOM(1,6)
41
ROUND Syntax
Cost ← 1.9556 OUTPUT ROUND(Cost,2) # Outputs 1.95
42
Ways to maintain a program
**Use comments** - to explain the purpose of each section of code - for example, logic / syntax **Use meaningful identifier names to** - clearly identify the purpose - of variables, constants, arrays, procedures **Use procedures and functions** - to avoid repeated code - simplify logic **Use indentation and white space** - to make the program readable