Back to 课程

Computer-science_A-level_Cie

0% Complete
0/0 Steps
  1. computers-and-components
    6 主题
  2. logic-gates-and-logic-circuits
    2 主题
  3. central-processing-unit-cpu-architecture
    6 主题
  4. assembly-language-
    4 主题
  5. bit-manipulation
    1 主题
  6. operating-systems
    3 主题
  7. language-translators
    2 主题
  8. data-security
    3 主题
  9. data-integrity
    1 主题
  10. ethics-and-ownership
    3 主题
  11. database-concepts
    3 主题
  12. database-management-systems-dbms-
    1 主题
  13. data-definition-language-ddl-and-data-manipulation-language-dml
    1 主题
  14. computational-thinking-skills
    1 主题
  15. algorithms
    14 主题
  16. data-types-and-records
    2 主题
  17. arrays
    2 主题
  18. files
    1 主题
  19. introduction-to-abstract-data-types-adt
    1 主题
  20. programming-basics
    1 主题
  21. constructs
    2 主题
  22. structured-programming
    1 主题
  23. program-development-life-cycle
    2 主题
  24. program-design-
    2 主题
  25. program-testing-and-maintenance
    3 主题
  26. user-defined-data-types
    1 主题
  27. file-organisation-and-access-
    3 主题
  28. floating-point-numbers-representation-and-manipulation
    3 主题
  29. protocols
    2 主题
  30. circuit-switching-packet-switching
    1 主题
  31. processors-parallel-processing-and-virtual-machines
    5 主题
  32. boolean-algebra-and-logic-circuits
    4 主题
  33. purposes-of-an-operating-system-os
    3 主题
  34. translation-software
    3 主题
  35. encryption-encryption-protocols-and-digital-certificates
    3 主题
  36. artificial-intelligence-ai
    4 主题
  37. recursion
    1 主题
  38. programming-paradigms
    4 主题
  39. object-oriented-programming
    7 主题
  40. file-processing-and-exception-handling
    2 主题
  41. data-representation
    5 主题
  42. multimedia
    3 主题
  43. compression
    2 主题
  44. networks-and-the-internet
    11 主题
课 Progress
0% Complete

Input, process, output

What is an input?

  • An input is data or information being entered/taken into a program before it is processed in the algorithm

  • An input can come from a variety of sources, such as:

    • User – keyboard, mouse, controller, microphone

    • Sensors – temperature, pressure, movement

  • Values are input using the INPUT command

INPUT <identifier>

What is a process?

  • A process is a doing action performed in the algorithm that transforms inputs into the desired output. The central processing unit (CPU) executes the instructions that define the process

  • An example would be:

    • Comparing two numbers

    • Calculating an average

What is an output?

  • An output is the result of the processing in an algorithm and usually the way a user can see if an algorithm works as intended

  • An output can take various forms, such as:

    • Numbers – result of calculations

    • Text

    • Images

    • Actions – triggering events

  • Values are output using the OUTPUT command

OUTPUT <value(s)>

More than one value can be output in the same command when separated by commas

OUTPUT "First name: ", Fname, "Surname: ", Sname

Example 1 – Area of a shape

  • A user wants to write a program to calculate the area of a shape

Input

Process

Output

  • Length

  • Width

  • Length X width

  • Area

// Calculate the area of a rectangle INPUT Length
INPUT Width Area ← Length * Width OUTPUT "The area is ", Area

Example 2 – Average test score

  • A teacher wants to calculate the average mark achieved on a test amongst students in a class

  • The teacher needs to enter how many students in the class and for each students a score out of 50

Input

Process

Output

  • Number of students

  • Score per student

  • TotalScore = TotalScore + score per student

  • Average = TotalScore / Number of students

  • Average mark

// Calculate the average test score for a class DECLARE TotalScore : INTEGER
DECLARE Score : INTEGER
DECLARE NumberOfStudents : INTEGER
DECLARE Average : REAL TotalScore ← 0 INPUT NumberOfStudents FOR StudentIndex ← 1 TO NumberOfStudents OUTPUT "Enter score for student ", StudentIndex INPUT Score TotalScore ← TotalScore + Score
NEXT StudentIndex Average ← TotalScore / NumberOfStudents OUTPUT "The average score is ", Average

Programming constructs

What is sequence?

  • Sequence refers to lines of code which are run one line at a time

  • The lines of code are run in the order that they written from the first line of code to the last line of code

  • Sequence is crucial to the flow of a program, any instructions out of sequence can lead to unexpected behaviour or errors

Example

  • A simple program to ask a user to input two numbers, number two is subtracted from number one and the result is outputted

Line

Pseudocode

01

INPUT NumberOne

02

INPUT NumberTwo

03

Result ← NumberOne - NumberTwo

04

OUTPUT "The result is ", Result

What is selection?

  • Selection is when the flow of a program is changed, depending on a set of conditions

  • The outcome of this condition will then determine which lines or block of code is run next

  • Selection is used for validation, calculation and making sense of a user’s choices

  • There are two ways to write selection statements:

    • if… then… else

    • case

Structure

IF…THEN…ELSE example

CASE statement example

Purpose

Used for binary decisions (true/false)

Used for multiple specific options

Scenario

Check if a user is old enough to vote

Perform an action based on the direction entered

Pseudocode example

INPUT Age
IF Age >= 18 THEN OUTPUT "You can vote"
ELSE OUTPUT "You cannot vote"
ENDIF
INPUT Direction
CASE OF Direction "N" : OUTPUT "North" "S" : OUTPUT "South" "E" : OUTPUT "East" "W" : OUTPUT "West" OTHERWISE : OUTPUT "Invalid direction"
ENDCASE

What is iteration?

  • Iteration means repeating a line or block of code using a loop

  • It allows a program to perform a task multiple times until a condition is met

Types of iteration

Type

Description

Pseudocode Format

Count-controlled

Repeats a fixed number of times

FOR ... TO ... NEXT

Post-condition

Repeats at least once, checks the condition after running the block

REPEAT ... UNTIL

Pre-condition

Checks the condition before running the block

WHILE ... ENDWHILE

// Count-controlled
FOR i ← 1 TO 5 OUTPUT i
NEXT i // Post-condition
REPEAT INPUT Password
UNTIL Password = "Secret123" // Pre-condition
WHILE Score < 100 Score ← Score + 10
ENDWHILE

Worked Example

A teacher uses a paper-based system to store marks for a class test. The teacher requires a program to assign grades based on these results.

The program will output the grades together with the average mark.

Write a detailed description of the algorithm that will be needed.[6]

Answer

Marks awarded for a description of each of the following steps of the algorithm:

  1. Reference variables for Count of students and Total marks [1 mark]

  2. Loop through all students (Count) [1 mark]

  3. Input individual mark (in loop) [1 mark]

  4. Compare mark with threshold / boundary values to determine grade (in loop) [1 mark]

  5. Output the grade for a student (in loop) [1 mark]

  6. Maintain a Total (and Count if required) (in loop) [1 mark]

  7. Calculate average by dividing Total by Count and Output (after loop) [1 mark]

Responses

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