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 Pi: Instead of hardcoding the value of π (3.142) directly in the program, it would be beneficial to define it as a constant at the beginning. This way, if the value needs to change in the future, it will only need to be updated in one place. For example, setting PI = 3.142 at the start would enhance maintainability.
Encapsulate Input Validation: The input validation logic could be improved by creating a separate function to handle the validation of the radius. This function could be called within the main logic. For instance, the code for checking the radius could look like:
This would not only make the code cleaner but also allow for easier updates to the validation rules.
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
area
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
3.142
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 π (3.142) is a fixed mathematical constant and should not change during the program's execution, making it suitable for constant definition.
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: ✔
Selection: ✔
Iteration: ✖
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 helps in easily identifying keywords, variables, and errors in the code.
Debugging tools enable step-by-step execution of the program to identify and fix errors.