Control Structures
12 Grade 10 Computer Studies questions on Control Structures, with worked marking schemes. 12 questions are available on this topic in full.
Question 1
1 markA clerk at a dairy cooperative in Nyeri types in the litres of milk brought by each farmer and types 0 after the last farmer has been served. The number of farmers is different every day. Which control structure best suits this task?
A. A WHILE loop that keeps reading litres until 0 is entered
B. A FOR loop that counts from 1 to 100
C. A single IF...ELSE statement that tests the litres entered
D. A nested IF placed inside another IF
(1 mark)
Marking scheme for this question
Create a free account to see itQuestion 2
6 marksAt a tea buying centre in Kericho a delivery is graded as follows: below 10 kg is graded 'Small', from 10 kg up to but not including 30 kg is graded 'Medium', and 30 kg or more is graded 'Large'. Outline, in words, the steps a program using nested selection would follow to read a delivery weight and display the correct grade.
(6 marks)
Marking scheme
1 mark each, maximum 6: - Set aside a variable to hold the weight and one to hold the grade. - Read (input) the weight of the delivery into the weight variable. - Test whether the weight is less than 10; if true, set the grade to 'Small'. - Otherwise, test whether the weight is less than 30; if true, set the grade to 'Medium'. - Otherwise, set the grade to 'Large', which covers 30 kg and above. - End (close) the nested IF statements and display the grade, so that exactly one grade is shown for any weight entered. (Accept a correct equivalent that works downwards from 30 kg, and accept displaying the grade inside each branch, provided the boundary values 10 and 30 fall in the correct bands.)
Question 3
4 marksExplain two reasons why a programmer would choose a FOR loop rather than a WHILE loop when the number of repetitions is known before the loop starts.
(4 marks)
Marking scheme
2 marks for each reason (1 mark for the point, 1 mark for the explanation), maximum 4. Any two of: - Setting the counter, increasing it and testing it are all written in one statement, so the loop needs fewer lines and there is less chance of a typing error. - The counter is increased automatically, so the programmer cannot forget to update it and the loop cannot become endless for that reason. - The number of passes is stated openly in the loop heading, so another person reading the program can see at once how many times the body runs. - The step size can be set once in the heading, so counting in twos, fives or backwards needs no extra instructions in the body.
Question 4
3 marksState the three basic control structures used in program design and give the purpose of each.
(3 marks)
Marking scheme for this question
Create a free account to see itQuestion 5
1 markA program counts bags of potatoes using a counted loop whose counter starts at 5, increases by 5 at the end of each pass, and which stops once the counter goes past 25. How many times is the body of the loop carried out?
A. 4
B. 25
C. 20
D. 5
(1 mark)
Marking scheme for this question
Create a free account to see itQuestion 6
1 markIn a grading program, a mark that is 50 or more but below 60 earns a grade of C. Which condition correctly tests for this band of marks?
A. IF mark is greater than or equal to 60 AND mark is less than 50
B. IF mark is greater than 50 AND mark is less than or equal to 60
C. IF mark is greater than or equal to 50 AND mark is less than 60
D. IF mark is greater than or equal to 50 OR mark is less than 60
(1 mark)
Marking scheme for this question
Create a free account to see itQuestion 7
1 markA program prints a report for each of 4 streams in a school, and for every stream it prints the mean mark of 3 subjects. The instruction that prints a subject mean sits inside a FOR loop that makes 3 passes, which is itself inside a FOR loop that makes 4 passes. How many subject means are printed altogether?
A. 12
B. 4
C. 3
D. 7
(1 mark)
Marking scheme for this question
Create a free account to see itQuestion 8
1 markA booking program stores a route code typed by a matatu conductor: 1 for Nairobi-Nakuru, 2 for Nairobi-Kisii, 3 for Nairobi-Malindi and 4 for Nairobi-Garissa. Different instructions must be carried out for each code. Which control structure handles this most neatly?
A. A CASE (SELECT) statement that tests the route code
B. A REPEAT...UNTIL loop that repeats four times
C. A FOR loop that makes four passes over the code
D. A single IF statement written without an ELSE part
(1 mark)
Marking scheme for this question
Create a free account to see itQuestion 9
1 markA learner writes a loop that keeps repeating while a counter is less than 30. The counter is set to 1 just before the loop, but nothing inside the loop changes it. What will happen when the program is run?
A. The body will be carried out once and the loop will stop
B. The loop will be skipped because the counter is less than 30
C. The loop will repeat endlessly because the condition never becomes false
D. The body will be carried out 30 times and the loop will stop
(1 mark)
Marking scheme for this question
Create a free account to see itQuestion 10
3 marksA learner writes a loop to add up the daily sales of a shop in Machakos, but when the program is run the loop never stops. Suggest three errors in the loop that could cause this.
(3 marks)
Marking scheme
1 mark each, maximum 3. Any three of: - The counter or variable that controls the loop is never changed inside the body of the loop. - The condition is written so that it can never become false, for example repeating while a positive counter is greater than zero. - The sentinel (stopping) value is never entered, or the loop tests for a sentinel value that the user can never type. - The counter is changed in the wrong direction, for example increased when the condition needs it to fall. - The instruction that updates the counter is placed outside the loop, so it runs only once.
Question 11
4 marksA greenhouse in Naivasha has a temperature sensor connected to a computer. Using pseudocode described in words, describe the steps the program would follow to switch the fan on when the temperature rises above 30 degrees Celsius and to switch it off otherwise.
(4 marks)
Marking scheme for this question
Create a free account to see itQuestion 12
2 marksDistinguish between a WHILE loop and a REPEAT...UNTIL loop.
(2 marks)
Marking scheme for this question
Create a free account to see it9 more marking schemes are on this page. A free account opens all of them, and lets you build your own paper on the topics you have actually taught, laid out in KNEC format with its full marking scheme.
Create a free account