QueryEd.com

AQA Homework – Algorithms & Loops

Q1. Variable & Constant Declaration

A teacher wants a program to store the maximum number of students allowed in a classroom.
- Write a declaration for a constant called MAX_STUDENTS with the value 30.
- Declare a variable called currentStudents.
- State why MAX_STUDENTS should be declared as a constant rather than a variable.

Answer:
Constant: CONST MAX_STUDENTS ← 30
Variable: currentStudents ← 0
Explanation: The maximum number of students will never change, so it should be fixed as a constant.

Q2. Data Types

For each of the following, state the most appropriate data type:

  1. The number of goals scored in a football match.
  2. The price of an item in a supermarket.
  3. A single letter grade (A–E).
  4. Whether the user has logged in successfully.
  5. A person’s full name.

Answer:
1) Integer
2) Real
3) Character
4) Boolean
5) String

Q3. Assignment & Iteration

total ← 0
FOR counter ← 1 TO 5
    total ← total + counter
NEXT counter

a) What is the final value of total after the loop finishes?
b) Explain how the assignment statement works in line 2.
c) What type of iteration is being used here?

Answer:
a) Final value = 15 (sum of 1+2+3+4+5)
b) The assignment updates total each time by adding the current counter value.
c) A FOR loop is being used (count-controlled iteration).

Q4. For Loop in Practice

Write pseudocode for a program that:

total ← 0
FOR i ← 1 TO 5
    INPUT score
    total ← total + score
NEXT i
average ← total / 5
OUTPUT average

Q5. Algorithm – Trace Table

number ← 3
FOR i ← 1 TO 4
    number ← number * 2
NEXT i
OUTPUT number

a) Complete a trace table for i and number.
b) What is the final output?
c) Explain why a FOR loop is appropriate here.

Answer:
Trace table:
i=1 → number=6
i=2 → number=12
i=3 → number=24
i=4 → number=48

Final output = 48
Explanation: The loop runs a fixed number of times, so a FOR loop is the most suitable.