11.2 Constructs (3)
Resources |
Revision Questions |
Computer Science
Login to see all questions
Click on a question to view the answer
1.
Write pseudo-code for a 'CASE' structure that determines a student's letter grade based on their percentage score. The grading criteria are as follows:
- 90% or above: A
- 80% - 89%: B
- 70% - 79%: C
- 60% - 69%: D
- Below 60%: F
Pseudo-code:
START
INPUT student_percentage
IF student_percentage >= 90 THEN
DISPLAY "Grade: A"
ELSE IF student_percentage >= 80 THEN
DISPLAY "Grade: B"
ELSE IF student_percentage >= 70 THEN
DISPLAY "Grade: C"
ELSE IF student_percentage >= 60 THEN
DISPLAY "Grade: D"
ELSE
DISPLAY "Grade: F"
ENDIF
END
2.
Write pseudo-code for a 'pre-condition' loop that repeatedly prompts the user for positive integer input until a number greater than 10 is entered. The loop should include input validation to ensure the user enters a valid integer.
Pseudo-code:
- Start
- Display a message prompting the user to enter a positive integer (greater than 10).
- Get input from the user and store it in a variable number.
- While number is not a positive integer greater than 10:
- Display an error message indicating the input is invalid (e.g., "Please enter a number greater than 10").
- Prompt the user to enter a positive integer again.
- End While
- Display a message confirming the valid number entered (e.g., "You entered the number: number").
- End
3.
Consider a scenario where you need to process a list of numbers. Write pseudo-code for a 'pre-condition' loop that iterates through the list, adding each number to a running total, but only if the number is positive. Assume the list is stored in an array called numbers and the running total is stored in a variable called total, initialized to 0.
Pseudo-code:
- Start
- For each number in numbers:
- If number is positive:
- total = total + number
- End If
- End For
- Display the value of total.
- End