Answer
Flashcards · 0478 · Topic 8
Programming flashcards
11 cards on Topic 8. Pick a subtopic or study them all.
Study mode needs JavaScript. Every card is listed below, so you can still cover the answers and test yourself.
Choose your cards
Session complete
Worth another look:
All 11 cards
For a quick read-through or printing. Cover the right-hand side to test yourself.
Topic 8: Programming
- Variable vs constant
- A variable is a named memory location whose value can change while the program runs. A constant is a named value fixed for the whole run, so it only needs changing in one place.
- What are the five data types in Cambridge pseudocode?
- INTEGER (whole number), REAL (number with a fractional part), CHAR (a single character), STRING (zero or more characters), BOOLEAN (TRUE or FALSE).
- What are sequence, selection and iteration?
- Sequence: statements run in the order written. Selection: a path is chosen (IF ... THEN ... ELSE ... ENDIF, CASE OF ... ENDCASE). Iteration: statements are repeated (FOR, WHILE, REPEAT loops).
- FOR vs WHILE vs REPEAT ... UNTIL loops
- FOR ... NEXT: count-controlled, runs a set number of times. WHILE ... DO ... ENDWHILE: pre-condition, tested first, may run zero times. REPEAT ... UNTIL: post-condition, tested after, always runs at least once.
- What do DIV and MOD do? Give 17 DIV 5 and 17 MOD 5
- DIV gives the whole-number part of a division; MOD gives the remainder. 17 DIV 5 = 3 and 17 MOD 5 = 2.
- What do LENGTH, SUBSTRING, UCASE and LCASE do?
- LENGTH returns the number of characters. SUBSTRING(Word, Start, Length) returns part of a string, e.g. SUBSTRING("Cambridge", 1, 4) is "Camb". UCASE and LCASE convert to upper or lower case.
- Procedure vs function
- Both are named blocks of code called by name that can take parameters. A function returns a value that can be used in an expression; a procedure does not.
- Local vs global variables
- A local variable exists only inside the procedure or function where it is declared. A global variable can be used anywhere in the program. Local variables prevent accidental changes elsewhere.
- How do you declare and use a 2D array in pseudocode?
- DECLARE Grid : ARRAY[1:3, 1:4] OF INTEGER declares 3 rows and 4 columns. Grid[2, 4] is row 2, column 4. Arrays are usually processed with nested FOR loops.
- What are the steps of file handling in pseudocode?
- Open the file (OPENFILE ... FOR READ or FOR WRITE), process it (READFILE or WRITEFILE, testing EOF when reading), then close it (CLOSEFILE). Opening for WRITE replaces the old contents.
- How do you make a program maintainable?
- Use meaningful identifier names, comments, indentation, constants instead of repeated values, and procedures and functions for repeated tasks.