Computer Science – 11.3 Structured Programming | e-Consult
11.3 Structured Programming (1 questions)
Login to see all questions.
Click on a question to view the answer
(a)
function IsGradePassing(grade)
{
// Check if the grade is 70 or above
if grade >= 70
{
// If the grade is 70 or above, return True
return True;
}
else
{
// Otherwise, return False
return False;
}
}
(b) Using a function to determine if a student's grade is passing improves the design and maintainability of the program in the following ways:
- Modularity: The grade-checking logic is encapsulated in a separate function, making the main program code cleaner and easier to understand.
- Reusability: The function can be called multiple times with different student grades without rewriting the grade-checking logic. This avoids code duplication.
- Testability: The function can be tested independently to ensure it correctly determines if a grade is passing.
- Readability: Using a descriptive function name (e.g., IsGradePassing) improves the readability of the code, making it easier for others (and the original author) to understand.
- Maintainability: If the passing grade criteria change (e.g., to 60), only the function needs to be updated, rather than searching for and modifying the logic in multiple places.