Computer Science AS OCR
-
1-1-structure-and-function-of-the-processor as5 主题
-
1-2-types-of-processor as3 主题
-
1-3-input-output-and-storage as2 主题
-
2-1-systems-software as8 主题
-
2-3-software-development as5 主题
-
2-4-types-of-programming-language as4 主题
-
3-1-compression-encryption-and-hashing as3 主题
-
3-2-databases as3 主题
-
3-3-networks as8 主题
-
3-4-web-technologies as13 主题
-
html as
-
css as
-
css-styling as
-
javascript as
-
variables-and-constants-in-javascript as
-
outputs-in-javascript as
-
selection-in-javascript- as
-
for-loops-in-javascript- as
-
while-loops-in-javascript- as
-
strings-in-javascript- as
-
operators-in-javascript- as
-
nested-statements-in-javascript as
-
functions-and-procedures-in-javascript as
-
html as
-
4-1-data-types as8 主题
-
4-2-data-structures as4 主题
-
4-3-boolean-algebra as1 主题
-
5-1-computing-related-legislation as4 主题
-
5-2-moral-and-ethical-issues as9 主题
-
6-1-thinking-abstractly as3 主题
-
6-2-thinking-ahead as1 主题
-
6-3-thinking-procedurally as3 主题
-
6-4-thinking-logically as2 主题
-
6-5-thinking-concurrently as2 主题
-
7-1-programming-techniques as9 主题
-
8-1-standard-algorithms-and-big-o-notation as8 主题
decisions-in-computational-thinking as
Exam code:H046
Identify the Points in a Solution where a Decision has to be Taken
-
Most languages use structured programming techniques including:
-
Sequence: one statement after another
-
Selection: Decision making, if/then/else, switch/case
-
Iteration: Loops, for/while/do while/do until
-
-
The purpose of these techniques is to aid the readability, understanding and maintainability of code
-
Python is an example of a block-structured language, which uses only these three constructs to control the flow of execution and data in a program. Each block of code should have a single entry and exit point and ideally minimise breaking out of iterative blocks. This is to prevent unintended consequences relating to the flow of control of a program such as entering or leaving a subroutine early or branching unintentionally
-
When designing algorithms, it is always best to plan the algorithm using flowcharts, pseudocode or structured english before coding in a language
-
Languages have specific syntax, constructs and idiosyncrasies that differ between other languages. This makes it challenging to create a solution that can immediately be implemented in another language
-
When determining the points in a solution where decisions are made, flowcharts are useful as they visually show the flow of control in a program. Decisions are clear and easy to follow, however flowcharts are time consuming to create
-
Pseudocode more accurately mimics the constructs of programming languages without the problem of syntax. As pseudocode has no syntax, any way of expressing an algorithm is acceptable as long as the pseudocode meaning is clear
-
Structured English can be an alternative to pseudocode but is usually more verbose and imprecise
How do you Identify the Points in a Solution where a Decision has to be Taken?
-
Most errors in a program occur when evaluating a Boolean condition, whether in a sequence as part of a statement, iteration or selection. It is therefore important to be careful when creating Boolean conditions, especially long, complex conditions involving multiple clauses
-
Decisions in programs usually occur in two situations, an if statement/select case or a loop, usually a while loop
-
Selection, also known as branching, involves directing the flow of control of a program, dependent on a Boolean condition or set of conditions
-
Iteration involves repeating a sequence of instructions based on a stopping Boolean condition
Determine how Decisions Affect Flow through a Program
-
Decisions affect the flow of control of a program
-
Decisions are Boolean conditions encountered in selection structures such as if/then/else statements and iteration structures such as while loops
-
If statements and switch/case statements can consist of many decision points as illustrated below. Each decision point directs the program through different statements
if/then/else example
if today == “Monday” then print(“Eugh! Monday again!”) elseif today == “Tuesday” then print(“Tuesday, one day closer the weekend!”) elseif today == “Wednesday” then print(“Half way there!”) elseif today == “Thursday” then print(“One more day to go!”) elseif today == “Friday” then print(“I can’t believe its Friday!”) elseif today == “Saturday” then print(“Woo! Its Saturday!”) elseif today == “Sunday” then print(“Aww, its Monday tomorrow!”) else print(“That’s not a day!”) endif
switch/case statement example
switch entry: case “Monday”: print(“Eugh! Monday again!”) case “Tuesday” print(“Tuesday, one day closer the weekend!”) case “Wednesday”: print(“Half way there!”) case “Thursday”: print(“One more day to go!”) case “Friday”: print(“I can’t believe its Friday!”) case “Saturday”: print(“Woo! Its Saturday!”) case “Sunday”: print(“Aww, its Monday tomorrow!”) default: print(“That’s not a day!”) endswitch
-
Iteration and selection statements can be nested, leading to a structure as shown below
Count ← 0 REPEAT INPUT Score[Count] IF Score[Count] >= 70 THEN Grade[Count] ← "A" ELSE IF Score[Count] >= 60 THEN Grade[Count] ← "B" ELSE IF Score[Count] >= 50 THEN Grade[Count] ← "C" ELSE IF Score[Count] >= 40 THEN Grade[Count] ← "D" ELSE IF Score[Count] >= 30 THEN Grade[Count] ← "E" ELSE Grade[Count] ← "F" ENDIF ENDIF ENDIF ENDIF ENDIF Count ← Count + 1 UNTIL Count = 30
-
Each if statement contains another if statement which affects the flow of the program. This is however functionally identical to the days of the week program shown above
Responses