The area of a circle is calculated using the formula π × r² where π is equal to 3.142 and r is the radius - OCR - GCSE Computer Science - Question 7 - 2023 - Paper 1
Question 7
The area of a circle is calculated using the formula π × r² where π is equal to 3.142 and r is the radius.
A program is written to allow a user to enter the radius ... show full transcript
Worked Solution & Example Answer:The area of a circle is calculated using the formula π × r² where π is equal to 3.142 and r is the radius - OCR - GCSE Computer Science - Question 7 - 2023 - Paper 1
Step 1
Explain, using examples from the program, two ways to improve the maintainability of the program.
96%
114 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Use Constants for Fixed Values: Instead of hardcoding the value of π as 3.142 directly in the area calculation (line 8), it is better to define a constant at the beginning of the program. For example:
PI = 3.142
area = PI * (radius ^ 2)
This improves maintainability because if the value of π needs to change, it only has to be updated in one location.
Input Validation: Lines 04-05 contain the logic for checking the validity of the radius. To enhance maintainability, this logic can be encapsulated in a separate function. For example:
This makes the main program clearer and allows for easier adjustments to the validation logic in the future.
Step 2
Identify two variables used in the program.
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
radius: This variable stores the user input for the radius of the circle.
area: This variable holds the computed area of the circle.
Step 3
Identify one item in the program that could have been written as a constant.
96%
101 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The value of π (3.142) used in the area calculation could be defined as a constant.
Step 4
Give one reason why you have identified this item as a constant.
98%
120 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The value of π is a fixed mathematical constant, and defining it once enhances clarity and allows for easy updates if necessary.
Step 5
Tick (✓) one box in each row to identify whether each programming construct has or has not been used in the program.
97%
117 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Sequence: Has been used
Selection: Has been used
Iteration: Has not been used
Step 6
Identify two features of an IDE that might be used when writing the program.
97%
121 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Syntax Highlighting: This feature helps in distinguishing different elements of the code through color coding, making it easier to read and debug.
Code Autocompletion: This feature helps programmers by suggesting completions for variable names and functions, reducing typos and improving efficiency.