Skip to content

Course home

Representing algorithms

Representing algorithms

EasyMediumHard
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
Question 35

An algorithm is designed to validate inputs for a smart battery fast-charging system and calculate the total percentage of charge to be added.

Figure 1 shows the pseudocode for this algorithm.

Figure 1

1  validCharge ← False
2  REPEAT
3      addedPower ← -1
4      OUTPUT 'Enter start charge'
5      startCharge ← USERINPUT
6      OUTPUT 'Enter target charge'
7      targetCharge ← USERINPUT
8      IF startCharge ≥ targetCharge THEN
9          OUTPUT 'Start charge must be less than target charge'
10     ELSE
11         IF startCharge < 15 THEN
12             OUTPUT 'Fast charge requires at least 15% start charge'
13         ELSE
14             validCharge ← True
15         ENDIF
16     ENDIF
17 UNTIL validCharge = True
18 addedPower ← targetCharge - startCharge
19 OUTPUT addedPower

Table 1 shows three tests used to check the algorithm in Figure 1.

Complete the table to show what the values of the validCharge and addedPower variables would be at the end of the first iteration of each independent test execution.

Table 1

Test typeTest datavalidChargeaddedPower
NormalstartCharge20
targetCharge80
ErroneousstartCharge50
targetCharge40
BoundarystartCharge15
targetCharge50
[4]
Markscheme

Representing algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Representing algorithms

208 exam-style questions on AQA GCSE Computer Science Representing algorithms. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank