Основы программирования
| English | Русский |
|---|---|
| variable/ˈveərɪəbl/ | переменной |
| data type/ˈdeɪtə taɪp/ | тип данных |
| constant/ˈkɒnstənt/ | постоянно |
| flowchart/ˈfləʊtʃɑːt/ | блок-схема |
| structured English/ˈstrʌktʃəd ˈɪŋɡlɪʃ/ | структурированный английский |
| pseudocode/ˈsuːdəʊkəʊd/ | псевдокод |
| assignment/əˈsaɪnmənt/ | присваиванием |
| identifier/aɪˈdentɪfaɪə/ | идентификатор |
| operators/ˈɒpəreɪtəz/ | операторы |
| precedence/ˈpresɪdəns/ | приоритет |
| concatenation/kənˌkætəˈneɪʃn/ | конкатенацией |
| library routines/ˈlaɪbrəri ruːˈtiːnz/ | библиотечные процедуры |
| program library/ˈprəʊɡræm ˈlaɪbrəri/ | библиотека программ |
| insert/ˈɪnsɜːt/ | insert |
The number that did not fit
- On 4 June 1996 the first Ariane 5 rocket veered off course and destroyed itself 37 seconds after launch, with four satellites on board.
- The cause was one conversion: a 64-bit decimal value describing the rocket's sideways speed was copied into a 16-bit integer. Ariane 5 was faster than Ariane 4, the number was too big for the box, and the guidance computer shut down.
- Every variable has a data type 数据类型, and the type decides what fits. Choosing it is the first job in turning a design into code.
- This lesson is the basics: constants, variables, types, expressions, input and output, and the ready-made routines you may call.
From design to code
- A design arrives as a flowchart 流程图 or as structured English 结构化英语. You turn it into pseudocode 伪代码, and later into a real language.
- Find the variables 变量 and their types. Input and output boxes become
INPUTandOUTPUT; decision diamonds becomeIF … ELSE … ENDIForCASE; loop arrows becomeWHILE,REPEAT … UNTILorFOR; process boxes become assignments. - Check by tracing a small input through your pseudocode before you call it finished.

Each flowchart symbol becomes one kind of pseudocode statement
Constants and variables
- A constant 常量 holds a value that never changes while the program runs:
CONSTANT Pi = 3.14159. A variable holds one that may change, and is declared with a type:DECLARE Radius : REAL. - Use a constant for a fixed value that appears in several places, such as a tax rate or a maximum score.
- The benefits the mark scheme lists: it is set once and cannot be changed accidentally; a change is made in one place and reaches every statement that uses it; the identifier 标识符 gives the value a meaningful name.

A variable can be reassigned; a constant cannot
Переменная — это помеченная коробка
Каждое присваивание хранит одно значение в именованной коробке; повторное присвоение того же имени перезаписывает его. Пройдите по программе и следите за тем, как каждая коробка принимает свое текущее значение.
Константа хранит фиксированное значение, которое не меняется во время выполнения программы, в то время как переменную можно переназначать.
Константы (например, Pi или максимальный балл) делают код понятнее и позволяют изменить повторяющееся значение в одном месте.
Какие являются преимуществами использования константы для значения, такого как ставка налога? Выберите все подходящие варианты.
Три преимущества, указанные в критериях оценки: безопасность, единая точка изменения и читаемость. Скорость не входит в их число.
The six data types
INTEGERfor whole numbers (a count, an index, a loop counter).REALfor numbers with a fractional part (a price, an average).CHARfor one character in single quotes,'A'.STRINGfor text in double quotes,"Hello".BOOLEANforTRUEorFALSE(a flag such asFound).DATEfor a calendar date.- Read the type off how the variable is used: a decimal point means
REAL,TRUEmeansBOOLEAN, single quotes meanCHAR, an array index orDIVandMODmeanINTEGER. Write the type in capitals as the guide spells it.
Worked example: state the appropriate data type
Found ← FALSEisBOOLEAN: it holds a truth value.Initial ← 'K'isCHAR: one character in single quotes.Name ← "Li Wei"isSTRING: text in double quotes.Price ← 12.99isREAL: it has a fractional part.Count ← Count + 1isINTEGER: a counter that goes up in whole steps.- One mark per correct type, so answer every row even when unsure; a blank cannot score.
Соотнесите каждое значение с типом данных, с которым должна быть объявлена переменная.
Десятичная точка, одинарные кавычки, двойные кавычки и логическое значение указывают на один тип.
Assignment and expressions
- Assignment 赋值 uses the arrow:
Total ← Total + 1,Average ← Sum / Count. - Arithmetic operators 运算符 are
+ - * /, plusDIVfor whole-number division andMODfor the remainder:7 DIV 2 = 3and7 MOD 2 = 1. - Comparisons are
=,<>,<,>,<=,>=; logic isAND,OR,NOT. - Precedence 优先级, highest first:
NOT, then* / DIV MOD, then+ -, then comparisons, thenAND, thenOR. Use brackets when unsure.
Каково значение 7 DIV 2?
DIV — целочисленное деление: 7 ÷ 2 = 3 остаток 1, поэтому DIV дает 3.
Каково значение 7 MOD 2?
MOD дает остаток: 7 ÷ 2 оставляет остаток 1.
Какой символ присваивает значение переменной в этом псевдокоде?
Присваивание использует ←; = — сравнение.
Соотнесите каждый оператор псевдокода с его функцией.
← хранит, = сравнивает; DIV дает частное, а MOD — остаток (7 DIV 2 = 3, 7 MOD 2 = 1).
Input and output
OUTPUT "Enter your name:"prompts;INPUT Namereads the keyboard into the variable;OUTPUT "Hello, ", Nameprints several items separated by commas.- Strings are joined with
&, called concatenation 拼接:"A" & "BC"is"ABC". - Keep the quotes straight:
"7"is a string,7is a number, and'7'is a single character.
Built-in functions and library routines
- A program library 程序库 holds routines that are already written, compiled and tested; calling one is faster and safer than writing your own. The Paper 2 insert 附页 lists the library routines 库例程 you may use, with their exact names.
- Strings:
LENGTH(s),LEFT(s, n),RIGHT(s, n),MID(s, start, n)with positions counted from 1,TO_UPPER(s),TO_LOWER(s). Conversion:NUM_TO_STR(x),STR_TO_NUM(s),IS_NUM(s),ASC(c),CHR(n). - Numbers and dates:
INT(x)cuts to the whole part;RAND(n)gives a real from 0 up to but not including n, soINT(RAND(6)) + 1is a dice roll;DAY,MONTH,YEAR,DAYINDEX,SETDATE,TODAY;EOF(f)for files.

The common string routines on s = "COMPUTER", positions 1 to 8
Какая процедура преобразует строку в заглавные буквы в псевдокоде 9618?
UCASE — название IGCSE и здесь не принимается. Используйте точные названия, напечатанные во вставке Paper 2.
Worked example: evaluate each expression
- Given
Word ← "Program",Code ← 'Q'andN ← 7. Work from the inside out. LENGTH(Word)is7.MID(Word, 4, 2)is"gr": two characters from position 4.LEFT(Word, 3) & "!"is"Pro!".TO_UPPER(RIGHT(Word, 2))is"AM": the inner function runs first.ASC(Code) - ASC('A')is16, because'Q'is 81 and'A'is 65.N DIV 2 + N MOD 2is3 + 1 = 4.NUM_TO_STR(N) & "th"is"7th".INT(N / 2)is3, the whole part of 3.5.
С Word ← "Program" значением MID(Word, 4, 2) является "____".
Позиции нумеруются с 1: P-r-o-g-r-a-m, поэтому позиция 4 — это g, а два символа отсюда — gr.
Worked example: find the error
- Each statement may misuse a function or an operator. Describe the error, or write NO ERROR.
Result ← 2 & 4:&joins strings, but 2 and 4 are integers, so+is needed.SubString ← MID("pseudocode", 4, 1): NO ERROR, one character from position 4,"u".Answer ← LENGTH(42):LENGTHtakes a string, not an integer.Flag ← "TRUE": a Boolean isTRUEwithout quotes; with quotes it is a string.
Result ← 2 & 4 правильно сохраняет 6 в Result.
& соединяет строки. Для двух целых чисел оператором является +; это ошибка, которую экзамен требует описать.
Marks that slip away
- The IGCSE names
UCASE,LCASE,VALandSTRare not accepted at A Level. UseTO_UPPER,TO_LOWER,STR_TO_NUM,NUM_TO_STR. - Single quotes make a
CHAR, double quotes make aSTRING.'A'and"A"are different types. - String positions start at 1, not 0.
MID(s, 1, 1)is the first character. RAND(n)never returns n itself, andINTcuts off the fraction rather than rounding.
You've got it
- design → pseudocode: find the variables and types, then map each flowchart symbol to a statement and trace a small input
- constant set once, changed in one place, named; variable declared with one of six types read off how it is used
←assigns;DIVwhole-number division,MODremainder; precedenceNOT→* / DIV MOD→+ -→ comparisons →AND→OR- use the insert's library routines with their exact 9618 names:
LENGTH,MID,TO_UPPER,NUM_TO_STR,INT,RAND