Writing 0478 Pseudocode From Memory
邊玩邊學
回答這些題目賺取能量,接著就能釣魚、探索。不需要帳號。
給老師: 為 Writing 0478 Pseudocode From Memory(Computer Science、CIE)準備好可直接使用的課程投影片, 複習筆記——用於你的課程,或把這個主題當成互動班級活動,讓學生以即時遊戲的方式進行。
課程筆記
Exam Context and Importance
- Paper 2 (1h45m, 75 marks) requires pseudocode answers; programming-language code earns no marks.
- The only exception is the final 15-mark scenario question, where pseudocode, Python, VB, or Java are accepted.
- No pseudocode reference sheet is provided in the exam; you must reproduce constructs from memory.
- Mark schemes are written in Cambridge pseudocode, so accuracy in syntax is vital to earn marks.
- Focus on logic over syntax, but incorrect pseudocode loses marks even if logic is right.
General Style Rules
- Keywords are in UPPER CASE (e.g., IF, THEN, ELSE, ENDIF, REPEAT, UNTIL, WHILE, DO, ENDWHILE, FOR, NEXT, CASE OF, OTHERWISE, ENDCASE, DECLARE, CONSTANT, INPUT, OUTPUT, PROCEDURE, ENDPROCEDURE, CALL, FUNCTION, RETURNS, RETURN, ENDFUNCTION, OPENFILE, READFILE, WRITEFILE, CLOSEFILE, ARRAY, OF, STEP).
- Identifiers use Pascal case (e.g., NumberOfPlayers, TotalToPay); start with a capital letter, contain only letters/digits, no underscores or accented letters.
- Identifiers are case-insensitive (Countdown = CountDown) and must not be keywords.
- Single letters allowed only conventionally: i, j for indices, X, Y for coordinates.
- Indentation: 4 spaces for block contents, 2 spaces for THEN/ELSE and CASE clauses.
- Comments start with // and run to end of line; multi-line comments use // on each line.
Data Types, Declarations, and Constants
- Five basic data types: INTEGER, REAL, CHAR, STRING, BOOLEAN.
- Literals: integers (5, -3), reals always with digit both sides of point (4.7, 0.3, -4.0, 0.0), chars in single quotes ('x'), strings in double quotes ("text"), Booleans TRUE/FALSE.
- Declaration syntax: `DECLARE <identifier> : <data type>` (e.g., `DECLARE Counter : INTEGER`).
- Constant syntax: `CONSTANT <identifier> ← <value>` (e.g., `CONSTANT HourlyRate ← 6.50`).
- Constant value must be a literal only; never a variable, constant, or expression.
Assignment and Operators
- Assignment uses left arrow `←` (e.g., `Counter ← 0`); `=` is only for equality in conditions.
- Arithmetic operators: `+`, `-`, `×`, `/`, `^` (power). Multiplication/division bind tighter than addition/subtraction; use parentheses for clarity.
- Integer division: `DIV(x, y)` returns quotient with fraction discarded (e.g., `DIV(10,3)` = 3); `MOD(x, y)` returns remainder (e.g., `MOD(10,3)` = 1).
- Relational operators: `=`, `<`, `≤`, `>`, `≥`, `<>` (not equal).
- Logical operators: AND, OR, NOT; operands and results are BOOLEAN.
Input and Output
- `INPUT <variable>` reads a single value into a variable (may be an array element).
- `OUTPUT <value1>, <value2>, ...` outputs comma-separated values.
- `INPUT` does not display a prompt; use a separate `OUTPUT` before it.
- Example: `OUTPUT "You have ", Lives, " lives left"`.
Selection (IF and CASE)
- IF syntax: `IF <condition> THEN <statements> ENDIF` (with optional ELSE).
- THEN and ELSE clauses are indented 2 spaces; nested IFs continue this pattern.
- CASE syntax: `CASE OF <identifier> <value> : <statement> ... OTHERWISE <statement> ENDCASE`.
- Case clauses are tested in order; first match runs, then control jumps to after ENDCASE.
- OTHERWISE must be last; each case should be a single value; complex logic better as IF.
- Example: `CASE OF Move 'W' : Position ← Position - 10 'E' : Position ← Position + 10 OTHERWISE OUTPUT "Beep" ENDCASE`.
Iteration (Loops)
- FOR loop: `FOR <identifier> ← <value1> TO <value2> <statements> NEXT <identifier>`; counter must be INTEGER.
- FOR loop runs inclusive of end values; if start > end, body runs zero times; STEP can be added (e.g., `FOR Index ← 10 TO 1 STEP -1`).
- REPEAT...UNTIL: `REPEAT <statements> UNTIL <condition>` — body always runs at least once, condition tested at bottom.
- WHILE...DO...ENDWHILE: `WHILE <condition> DO <statements> ENDWHILE` — condition tested at top, body may run zero times.
- Do not confuse REPEAT (post-condition) with WHILE (pre-condition).
Arrays
- Declaration: `DECLARE <name> : ARRAY[<lower>:<upper>] OF <type>` (e.g., `DECLARE StudentNames : ARRAY[1:30] OF STRING`).
- 2D arrays: `DECLARE NoughtsAndCrosses : ARRAY[1:3, 1:3] OF CHAR`.
- State lower bound explicitly (usually 1) because default varies.
- Access elements with brackets: `StudentNames[1] ← "Ali"`, `NoughtsAndCrosses[2,3] ← 'X'`.
- Fill arrays using loops: `FOR Index ← 1 TO 30 StudentNames[Index] ← "" NEXT Index`.
String and Library Routines
- `LENGTH("Happy Days")` returns 10.
- `SUBSTRING("Happy Days", 1, 5)` returns "Happy" (identifier, start, length).
- `UCASE("Happy")` returns "HAPPY"; `LCASE('W')` returns 'w'.
- `ROUND(<identifier>, <places>)` rounds a REAL to given decimal places.
- `RANDOM()` returns a random number between 0 and 1 inclusive.
- Example: `Value ← ROUND(RANDOM()×6, 0)` gives a whole number 0-6.
Procedures and Functions
- Procedure definition: `PROCEDURE <name>(<params>) <statements> ENDPROCEDURE`; called with `CALL <name>(<args>)`.
- Function definition: `FUNCTION <name>(<params>) RETURNS <type> <statements> RETURN <value> ENDFUNCTION`; called without CALL as part of an expression.
- Example procedure: `PROCEDURE Line(Size : INTEGER) ... ENDPROCEDURE` then `CALL Line(60)`.
- Example function: `FUNCTION SumSquare(Number1 : INTEGER, Number2 : INTEGER) RETURNS INTEGER RETURN Number1×Number1 + Number2×Number2 ENDFUNCTION`; used as `OUTPUT SumSquare(10,20)`.
File Handling
- Open file: `OPENFILE "FileA.txt" FOR READ` or `FOR WRITE`.
- Read: `READFILE "FileA.txt", <variable>`; Write: `WRITEFILE "FileB.txt", <variable>`.
- Close: `CLOSEFILE "FileA.txt"`.
- A file can be opened in one mode at a time; WRITE creates a new file (overwrites existing).
- Always close files when done.
Common Mistakes to Avoid (Recall Checklist)
- Using `=` instead of `←` for assignment.
- Lower-case keywords, or identifiers with underscores or leading lower-case.
- Missing closing keywords: ENDIF, ENDWHILE, NEXT <identifier>, ENDCASE, ENDPROCEDURE, ENDFUNCTION.
- Writing conditions in words ("x is greater than y") instead of symbols (`x > y`).
- Using CALL on a function, or omitting CALL on a procedure call.
- Declaring arrays without bounds, or indexing out of bounds.
- Using variable/expression as constant value.
- Forgetting separate OUTPUT prompt before INPUT.
- Confusing REPEAT...UNTIL with WHILE...DO...ENDWHILE.
- Using undeclared variables or wrong data types.
投影片
練習題
免費預覽——59 題中的 8 題。註冊即可查看全部。
1.Which of the following is the correct assignment operator in Cambridge 0478 pseudocode?
Easy- A=
- B←
- C:=
- D→
2.In Cambridge 0478 pseudocode, keywords must be written in upper case (e.g., IF, THEN, ENDIF).
EasyTrue or false?
3.Which of the following is the correct declaration of an integer variable named Counter?
Easy- ADECLARE Counter : INTEGER
- BDECLARE Counter: Integer
- CINTEGER DECLARE Counter
4.In Cambridge 0478 pseudocode, identifiers may contain underscores (e.g., TotalScore).
EasyTrue or false?
5.What is the value of MOD(10, 3) in Cambridge 0478 pseudocode?
Easy- A3
- B1
- C0
- D3.33
6.A REPEAT...UNTIL loop always executes its body at least once.
EasyTrue or false?
7.Which of the following is the correct way to declare a 1D array of 30 strings?
Medium- ADECLARE StudentNames : ARRAY[1:30] OF STRING
- BDECLARE StudentNames : ARRAY[30] OF STRING
- CDECLARE StudentNames : ARRAY[1 TO 30] OF STRING
- DDECLARE StudentNames : ARRAY[1:30] STRING
8.A procedure must be called using the keyword CALL.
EasyTrue or false?
歷屆試題
這個主題的歷屆試題練習即將推出。
即將推出