AQA A level Computer Science
20 catatan belajar untuk AQA A-Level Computer Science, dibuat oleh cookie, dalam 12 bagian yang mengikuti topik kursus.
Notes for AQA A level Computer Science (7517), in folders for the specification's content areas in its order: programming, data structures, algorithms, theory of computation, data representation, computer systems, organisation and architecture, the consequences of computing, communication and networking, databases, functional programming and software development. Follows version 1.6 (2023). Delete any folder your course leaves out once the notes are yours.
Isi di dalamnya
Catatan pertama
Programming / Data types, operators and control
A data type decides which values a variable can hold and which operations can be applied to it. Programs depend on choosing the right type, because the same bit pattern means different things under different types.
Built-in data types
Integer stores whole numbers. Real (float) stores numbers with a fractional part. Boolean stores only true or false. Character stores a single symbol, and string stores a sequence of characters. Date/time stores a calendar date and time, usually with its own operations for comparing and adding periods.
Composite types group values. A record groups fields that can each have a different data type, so a record for a book might hold a title (string), a number of pages (integer) and a price (real). An array holds a set of elements of the same data type, each reached through an index. Some languages also provide pointer or reference types, whose values are memory addresses of objects created while the program runs. Not every language allows these to be handled explicitly.
A user-defined data type is built by the programmer from built-in types, such as a record type called Book that combines the fields above.
Arithmetic operators
The arithmetic operators are addition, subtraction, multiplication, real division, integer division, exponentiation, rounding and truncation.
Real division keeps the fractional part, so 17/5=3.4. Integer division keeps only the whole part of the quotient, and the remainder operator gives what is left over. For 17 and 5:
so the integer division result is 3 and the remainder is 2. In pseudocode these are often written DIV and MOD.
Rounding moves a real number to the nearest value with fewer decimal places, so 3.6 rounds to 4. Truncation removes the fractional part without rounding, so 3.9 truncates to 3. The two can give different answers, and a program that needs the nearest whole number must round rather than truncate.
Relational and Boolean operators
The relational operators compare two values and return true or false, testing whether they are equal, whether they differ, and how they are ordered against each other.
The Boolean operators work on true and false values. NOT reverses its operand. AND is true only when both operands are true. OR is true when at least one operand is true. XOR, or exclusive OR, is true when exactly one operand is true, so it is false when both are true.
Combining these, the expression (5 > 3) AND NOT (2 = 2) reduces step by step: 5 > 3 is true, 2 = 2 is true, NOT true is false, and true AND false is false. A short check in Python agrees:
result = (5 > 3) and not (2 == 2)
print(result) # FalseVariables and constants
A variable's value can change while the program runs. A constant's value is fixed when it is declared. A named constant has two advantages over writing the number directly. If the value changes, it is altered in one place, and the name tells a reader what the number means. A constant for the rate of VAT, for example, reads better than the bare value 0.2 scattered through a program.
String operations and random numbers
The length operation returns the number of characters in a string, so the length of "cake" is 4. The position operation returns the index at which a substring first starts, and the substring operation returns the part of a string taken from a start position for a given number of characters. Concatenation joins two strings end to end into one new string.
Character codes link characters to numbers. The character-to-code operation returns the code of a character, so in ASCII the character A has the code 65. The code-to-character operation does the reverse. Conversions between types are needed as well: a string to integer conversion turns "42" into 42, an integer to string conversion turns 42 back into "42", and float and date/time values can be converted to and from strings in the same way.
A random number generator produces values from a range that the program cannot predict in advance. Random values are used in games, simulations and sampling, and most generators are pseudo-random, meaning they produce a fixed sequence from a starting seed.
Sequence, selection and iteration
Imperative programs are built from three combining principles: sequence (statements run in order), selection (choosing between paths) and iteration (repeating a block). Nested selection puts one selection inside another, and nested iteration puts one loop inside another.
Iteration is definite when the number of repetitions is known in advance, as in a count-controlled FOR loop:
total = 0
for n in range(1, 4):
total = total + n
print(total) # 6Here the loop adds 1, 2 and 3, giving 6. Iteration is indefinite when it repeats until a condition changes. Its condition can be checked at the start or at the end of the structure. A pre-test loop checks first, so its body can run zero times:
WHILE count < 3 DO
count <- count + 1
ENDWHILEA post-test loop, such as REPEAT ... UNTIL in pseudocode, runs its body at least once before the condition is checked. Choosing between them depends on whether the body must run at least once.
Meaningful identifier names belong to every one of these structures. A variable called distance_metres explains itself in a way that d does not, and that matters more as programs grow.
Dan 19 lainnya: buka yang kamu mau dari daftar di atas.
Ulasan
Belum ada ulasan tertulis. Tambahkan catatan ini ke catatanmu dan jadilah yang pertama memberi ulasan.