Computer Science GCES OCR
-
Cpu Architecture Performance And Embedded Systems Ocr5 主题
-
Primary And Secondary Storage Ocr6 主题
-
Data Storage And Compression Ocr12 主题
-
Units Of Data Storage Ocr
-
Processing Binary Data Ocr
-
Data Capacity And Calculating Capacity Requirements Ocr
-
Converting Between Denary And Binary Ocr
-
Binary Addition Ocr
-
Converting Between Denary And Hexadecimal Ocr
-
Converting Between Binary And Hexadecimal Ocr
-
Binary Shifts Ocr
-
Representing Characters Ocr
-
Representing Images Ocr
-
Representing Sound Ocr
-
Compression Ocr
-
Units Of Data Storage Ocr
-
Networks And Topologies Ocr6 主题
-
Wired And Wireless Networks Protocols And Layers Ocr6 主题
-
Identifying And Preventing Threats To Computer Systems And Networks Ocr2 主题
-
Operating Systems And Utility Software Ocr2 主题
-
Ethical Legal Cultural And Environmental Impact Ocr2 主题
-
Computational Thinking Searching And Sorting Algorithms Ocr3 主题
-
Designing Creating And Refining Algorithms Ocr5 主题
-
Programming Fundamentals And Data Types Ocr5 主题
-
Additional Programming Techniques Ocr7 主题
-
Defensive Design And Testing Ocr6 主题
-
Boolean Logic Diagrams Ocr2 主题
-
Programming Languages And Integrated Development Environments Ides Ocr3 主题
-
The Exam Papers Ocr2 主题
-
Structuring Your Responses Ocr3 主题
Identify Errors In Algorithms Ocr
Exam code:J277
-
Designing algorithms is a skill that must be developed and when designing algorithms, mistakes will be made
-
There are two main types of errors that when designing algorithms a programmer must be able to identify & fix, they are:
-
Syntax errors
-
Logic 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
-
Examples
|
Syntax Errors |
Corrected |
|---|---|
|
|
|
|
|
|
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
-
Example
-
An algorithm is written to take as input the number of miles travelled. The algorithm works out how much this will cost, with each mile costing £0.30 in petrol. If this is greater than £10.00 then it is reduced by 10%.
|
Logic errors |
Corrected |
|---|---|
|
|
|
|
Commentary |
|
|
|
Worked Example
Nine players take part in a competition, their scores are stored in an array. The array is named scores and the index represents the player
Array scores
|
Index |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
|
Score |
7 |
9 |
2 |
11 |
8 |
4 |
13 |
10 |
5 |
The following program counts the total score of all the players
for x = 1 to 8
total = 0
total = total + scores[x]
next x
print(total)
When tested, the program is found to contain two logic errors.
Describe how the program can be refined to remove these logic errors [2]
How to answer this question
-
A common logic error if an algorithm contains a loop is checking it loops the correct amount of times, how many times should this algorithm loop?
Answer
-
For loop changed to include 0
-
total = 0 moved to before loop starts
Guidance
-
Moving total outside the loop is not enough, it could be moved after the loop which would still be a logic error)
-
Corrected code accepted
total = 0
for x = 0 to 8
total = total + scores[x]
next x
print(total)
Responses