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 type | Test data | validCharge | addedPower | |
|---|---|---|---|---|
| Normal | startCharge | 20 | ||
| targetCharge | 80 | |||
| Erroneous | startCharge | 50 | ||
| targetCharge | 40 | |||
| Boundary | startCharge | 15 | ||
| targetCharge | 50 |
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.