Computer-science_A-level_Cie
-
computers-and-components6 主题
-
logic-gates-and-logic-circuits2 主题
-
central-processing-unit-cpu-architecture6 主题
-
assembly-language-4 主题
-
bit-manipulation1 主题
-
operating-systems3 主题
-
language-translators2 主题
-
data-security3 主题
-
data-integrity1 主题
-
ethics-and-ownership3 主题
-
database-concepts3 主题
-
database-management-systems-dbms-1 主题
-
data-definition-language-ddl-and-data-manipulation-language-dml1 主题
-
computational-thinking-skills1 主题
-
algorithms14 主题
-
data-types-and-records2 主题
-
arrays2 主题
-
files1 主题
-
introduction-to-abstract-data-types-adt1 主题
-
programming-basics1 主题
-
constructs2 主题
-
structured-programming1 主题
-
program-development-life-cycle2 主题
-
program-design-2 主题
-
program-testing-and-maintenance3 主题
-
user-defined-data-types1 主题
-
file-organisation-and-access-3 主题
-
floating-point-numbers-representation-and-manipulation3 主题
-
protocols2 主题
-
circuit-switching-packet-switching1 主题
-
processors-parallel-processing-and-virtual-machines5 主题
-
boolean-algebra-and-logic-circuits4 主题
-
purposes-of-an-operating-system-os3 主题
-
translation-software3 主题
-
encryption-encryption-protocols-and-digital-certificates3 主题
-
artificial-intelligence-ai4 主题
-
recursion1 主题
-
programming-paradigms4 主题
-
object-oriented-programming7 主题
-
file-processing-and-exception-handling2 主题
-
data-representation5 主题
-
multimedia3 主题
-
compression2 主题
-
networks-and-the-internet11 主题
faults-and-errors
Error types
What are the common types of error?
-
Designing algorithms is a skill that must be developed and when designing algorithms, mistakes and issues will occur
-
Trace tables can also help to find any kind of error in a program or algorithm
-
There are three main categories of errors that when designing algorithms a programmer must be able to identify & fix, they are:
-
Syntax errors
-
Logic errors
-
Runtime errors
-
Syntax errors
What is a syntax error?
-
A syntax error is an error that breaks the grammatical rules of a programming language and stops it from running
-
Examples of syntax errors are:
-
Typos and spelling errors
-
Missing or extra brackets or quotes
-
Misplaced or missing semicolons
-
Invalid variable or function names
-
Incorrect use of operators
-
Incorrectly nested loops & blocks of code
-
|
Pseudocode – with syntax errors |
|---|
|
|
Pseudocode – without syntax errors |
|
|
Syntax errors |
|
Logic errors
What is a logic error?
-
A logic error is where incorrect code is used that causes the program to run, but produces an incorrect output or result
-
Logic errors can be difficult to identify by the person who wrote the program, so one method of finding them is to use ‘Trace Tables‘
-
Examples of logic errors are:
-
Incorrect use of operators (< and >)
-
Logical operator confusion (AND for OR)
-
Looping one extra time
-
Indexing arrays incorrectly (arrays indexing starts from 0)
-
Using variables before they are assigned
-
Infinite loops
-
|
Pseudocode |
|---|
|
Logic errors
|
Line |
Error |
Correction |
|---|---|---|
|
|
The check allows one value to be negative, which is not valid |
Should be |
|
|
Incorrect calculation – subtracts instead of multiplying to find the area |
Should be |
Runtime errors
What is a runtime error?
-
A runtime error is where an error causes a program to crash
-
Examples of runtime errors are:
-
Dividing a number by 0
-
Index out of the range of an array
-
Unable to read or write a drive
-
|
Pseudocode |
|---|
|
Runtime error
|
Line |
Error |
Correction |
|---|---|---|
|
|
Only one parameter is passed instead of two – will crash at runtime |
Should be |
Worked Example
Each pseudocode statement in the following table may contain an error due to the incorrect use of the function or operator.
Describe the error in each case, or write ‘NO ERROR’ if the statement contains no error.
You can assume that none of the variables referenced are of an incorrect type.[5]
|
Statement |
Error |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Answer
|
Statement |
Error |
|---|---|
|
|
Should be arithmetic operator (not &) OR 2 and 4 should be CHAR / STRING |
|
|
NO ERROR |
|
|
Not Boolean values / incorrect operator OR Condition incorrect |
|
|
to a Boolean value / incorrect operator |
|
|
Can’t add string to number / “Done” is not a number |
Responses