Back to 课程

Computer-Science-A-level-Ocr

0% Complete
0/0 Steps
  1. 3-3-networks
    8 主题
  2. 3-2-databases
    7 主题
  3. 3-1-compression-encryption-and-hashing
    4 主题
  4. 2-5-object-oriented-languages
    7 主题
  5. 2-4-types-of-programming-language
    4 主题
  6. 2-3-software-development
    5 主题
  7. 2-2-applications-generation
    6 主题
  8. 2-1-systems-software
    8 主题
  9. 1-3-input-output-and-storage
    2 主题
  10. 1-2-types-of-processor
    3 主题
  11. 1-1-structure-and-function-of-the-processor
    1 主题
  12. structuring-your-responses
    3 主题
  13. the-exam-papers
    2 主题
  14. 8-2-algorithms-for-the-main-data-structures
    4 主题
  15. 8-1-algorithms
    10 主题
  16. 7-2-computational-methods
    11 主题
  17. 7-1-programming-techniques
    14 主题
  18. 6-5-thinking-concurrently
    2 主题
  19. 6-4-thinking-logically
    2 主题
  20. 6-3-thinking-procedurally
    3 主题
  21. 6-2-thinking-ahead
    1 主题
  22. 6-1-thinking-abstractly
    3 主题
  23. 5-2-moral-and-ethical-issues
    9 主题
  24. 5-1-computing-related-legislation
    4 主题
  25. 4-3-boolean-algebra
    5 主题
  26. 4-2-data-structures
    10 主题
  27. 4-1-data-types
    9 主题
  28. 3-4-web-technologies
    16 主题
课 Progress
0% Complete

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

您的邮箱地址不会被公开。 必填项已用 * 标注