Computer-Science-A-level-Ocr
-
3-3-networks8 主题
-
3-2-databases7 主题
-
3-1-compression-encryption-and-hashing4 主题
-
2-5-object-oriented-languages7 主题
-
2-4-types-of-programming-language4 主题
-
2-3-software-development5 主题
-
2-2-applications-generation6 主题
-
2-1-systems-software8 主题
-
1-3-input-output-and-storage2 主题
-
1-2-types-of-processor3 主题
-
1-1-structure-and-function-of-the-processor1 主题
-
structuring-your-responses3 主题
-
the-exam-papers2 主题
-
8-2-algorithms-for-the-main-data-structures4 主题
-
8-1-algorithms10 主题
-
7-2-computational-methods11 主题
-
7-1-programming-techniques14 主题
-
capturing-selecting-managing-and-exchanging-data
-
entity-relationship-diagrams
-
data-normalisation
-
relational-databases
-
hashing
-
symmetric-vs-asymmetric-encryption
-
run-length-encoding-and-dictionary-coding
-
lossy-and-lossless-compression
-
polymorphism-oop
-
encapsulation-oop
-
inheritance-oop
-
attributes-oop
-
methods-oop
-
objects-oop
-
capturing-selecting-managing-and-exchanging-data
-
6-5-thinking-concurrently2 主题
-
6-4-thinking-logically2 主题
-
6-3-thinking-procedurally3 主题
-
6-2-thinking-ahead1 主题
-
6-1-thinking-abstractly3 主题
-
5-2-moral-and-ethical-issues9 主题
-
5-1-computing-related-legislation4 主题
-
4-3-boolean-algebra5 主题
-
4-2-data-structures10 主题
-
4-1-data-types9 主题
-
3-4-web-technologies16 主题
-
environmental-effects
-
automated-decision-making
-
computers-in-the-workforce
-
layout-colour-paradigms-and-character-sets
-
piracy-and-offensive-communications
-
analysing-personal-information
-
monitoring-behaviour
-
censorship-and-the-internet
-
artificial-intelligence
-
the-regulation-of-investigatory-powers-act-2000
-
the-copyright-design-and-patents-act-1988
-
the-computer-misuse-act-1990
-
the-data-protection-act-1998
-
adder-circuits
-
flip-flop-circuits
-
simplifying-boolean-algebra
-
environmental-effects
procedural-programming
Procedural Programming
What is procedural programming?
-
Procedural programming is a method of writing software where tasks are broken down into a sequence of step-by-step instructions
-
Modular design:
-
It focuses on grouping code into functions and procedures to promote reuse and improve clarity
-
-
State and control:
-
Variables are used to hold the program’s state, while control structures (like selection and iteration) determine the flow of execution throughout the program
-
-
Core programming concepts
|
Explanation |
Example |
Output |
|
|---|---|---|---|
|
Variables |
Storing data values that can change |
|
|
|
Constants |
Storing values that remain unchanged |
|
|
|
Selection |
Decision-making constructs |
|
|
|
Iteration |
Using loops to repeat actions |
|
|
|
Sequence |
Executing statements sequentially |
|
|
|
Subroutines |
Organising code into reusable parts |
|
|
|
String Handling |
Operations on character strings |
|
|
|
File Handling |
Reading from and writing to files |
|
|
|
Boolean Operators |
Logical operations |
|
|
|
Arithmetic Operators |
Basic mathematical operations |
|
|
Full example
-
This script greets the user, asks for two numbers, and multiplies them if they are both greater than 10
-
It gives the user three attempts to provide suitable numbers and asks if they want to continue after each attempt
-
Finally, it writes the greeting and the last multiplication result to a file
# Constants
MAX_ATTEMPTS = 3
FILENAME = 'output.txt' # Subroutine to greet a user
def greet(name): return "Hello, " + name # Subroutine to multiply two numbers
def multiply(x, y): return x * y # Main program
def main(): name = input("Please enter your name: ") print(greet(name)) # Iteration to allow multiple attempts for attempt in range(MAX_ATTEMPTS): x = int(input("Enter the first number: ")) y = int(input("Enter the second number: ")) # Selection if x > 10 and y > 10: result = multiply(x, y) print(f"The product of {x} and {y} is {result}") else: print("Both numbers should be greater than 10.") # Asking user if they want to continue continue_choice = input("Do you want to continue? (y/n): ") if continue_choice.lower() != 'y': break # File Handling with open(FILENAME, 'w') as file: file.write(greet(name) + "n") file.write(f"Last multiplication result: {result}") print(f"Results have been saved to {FILENAME}") # Sequence: Calling the main program
if __name__ == "__main__": main()
Worked Example
You are working for a library and need to develop a program that calculates the total late fees for overdue books. Provide pseudocode that includes a function to calculate the fee for each book.
How to answer this question:
-
Notice that the same operation needs to take place against multiple items. This suggests iteration could be used
-
A function is required to calculate the fee for each book. Simple names for functions make them clear to understand
-
Think of some data structures to hold the bits of data for this scenario
-
Many numbers representing each book’s days overdue could be stored in an array
-
The total late fee could be stored in a variable
-
-
Use indentation to show which code is inside a code block e.g.
function,ifstatement,forstatement -
Only include code comments where you think it’s necessary to explain
-
The example below contains comments for your understanding
Answer:
Answer that gets full marks:
const DAILY_CHARGE = 1 // Many functions can use this const if they need it function calculateFee(days_overdue) IF days_overdue > 0 THEN RETURN days_overdue * DAILY_CHARGE // £1 per day ELSE RETURN 0 ENDIF
END function function calculateTotalFee(books) var total_fee = 0 FOR each days_overdue IN books // days_overdue is an identifier that represents each item in books total_fee = total_fee + calculateFee(days_overdue) // adding the result of the function to the total_fee variable ENDFOR RETURN total_fee // returning the variable back to caller
END function var books = [7, 3, 0, 10] // Array of numbers representing each book's overdue days
var total_fee = calculateTotalFee(books) PRINT "Total Late Fee:", total_fee
-
This solution contains a function that accepts an array of books and a function that will calculate the fee for a single book
-
This is well-designed because two smaller functions are better than 1 larger function
Responses