Answers To Chapter 7 Activities and Questions
Answers To Chapter 7 Activities and Questions
Answers To Chapter 7 Activities and Questions
7.3
Amount 100
TotalPrice 350
Discount 0.2
FinalPrice 280
Name "Nikki"
Message "Hello Nikki"
7.4
OUTPUT "Please enter a mark "
INPUT Mark
7.8
Telephone number – the number needs to be the one that is required as well as having the
necessary characteristics.
Pupil's name – the name needs to be the one that is associated with the pupil.
Part number – a part number could have the required format but not be for the part intended.
7.9
For example:
Normal test data: 7, 34, 55, 67, 74, 83, 21, 45, 72, 64; Expected result: 54.2
(Other values acceptable.)
7.10
For example:
Erroneous test data: −7, 1001; Expected result: both values rejected
(Other values acceptable.)
7.11
1 Boundary test data for 100 is: 100, 101; Expected result: 100 accepted, 101 rejected
2 Normal test data: 2, 14, 15, 6, 7, 13, 20, 4, 10, 9; Expected result: 10
Normal test data: 17, 13, 15, 15, 14, 16, 2, 8, 7, 6; Expected result: 11.3
Erroneous test data: −7, 23; Expected result: both values rejected
Boundary test data: −1, 0 and 20, 21
Expected results: −1 rejected, 0 accepted and 20 accepted, 21 rejected
7.12
Answer in chapter (page 285).
7.13
A B C X OUTPUT
1 4 4 4
2 8 8
3 19 19
4 17
5 3 3
6 11
7 6
8 1 1
9 13
10 9 19 1
7.14
Temperature
First Last Index Swap Temp
[1] [2] [3] [4] [5] [6] [7] [8]
1 8 1 FALSE 35 31 32 36 39 37 42 38
TRUE 35 31 35
2 TRUE 35 32 35
5 39 39 37 39
7 42 38 42
7 1 FALSE
6 TRUE 39 38 39
6 1 FALSE
7.15
Sample data: −1, −7, −11, −19, −3, −20, −9, −4, −6, −8
A B C X OUTPUT
0 0 100
1 -1
2 -7 -7
3 -11 -11
4 -19 -19
5 -3
6 -20 -20
7 -9
8 -4
9 -6
10 0 -3
0 -20
A B C X OUTPUT
1 12390 12390
2 0
3 77
4 359
5 -2
6 -89
7 5000
8 21
9 67
12390,-97
7.18
0, 26
Expected results rejected – erroneous data
1, 25
Expected results: Your tickets cost 20
Your tickets cost 400 – extreme data
9, 10
Expected results: Your tickets cost 180
Your tickets cost 180 – normal data
19, 20
Expected results: Your tickets cost 342
Your tickets cost 320 – normal data
Extra test data:
0, 1
Expected results: 0 rejected
1 Your tickets cost 20 – boundary data lower bound
26, 25
Expected results: 26 rejected
25 Your tickets cost 400 – boundary data upper bound
-30, 200
Expected results rejected – erroneous data
7.19
1 Change FOR Test ← 1 to 4 // outer loop for the tests
to FOR Test ← 1 to 2 // outer loop for the tests
remove 3 : SubjectName ← "English" and 4 : SubjectName ← "IT"
change FOR StudentNumber ← 1 TO 600
to FOR StudentNumber ← 1 TO 5
change SubjectAverage ← SubjectTotal / 600
to SubjectAverage ← SubjectTotal / 5
change OverallAverage ← OverallTotal / 2400
to OverallAverage ← OverallTotal / 10
The code should now look like this:
// initialisation of overall counters
OverallHighest ← 0
OverallLowest ← 100
OverallTotal ← 0
FOR Test ← 1 to 2 // outer loop for the tests
// initialisation of subject counters
SubjectHighest ← 0
SubjectLowest ← 100
SubjectTotal ← 0
CASE OF Test
1 : SubjectName ← "Maths"
2 : SubjectName ← "Science"
ENDCASE
FOR StudentNumber ← 1 TO 5 // inner loop for the students
REPEAT
OUTPUT "Enter Student", StudentNumber, "’s mark for ", SubjectName
INPUT Mark
UNTIL Mark < 101 AND Mark > -1
IF Mark < OverallLowest THEN OverallLowest ← Mark
IF Mark < SubjectLowest THEN SubjectLowest ← Mark
IF Mark > OverallHighest THEN OverallHighest ← Mark
IF Mark > SubjectHighest THEN SubjectHighest ← Mark
OverallTotal ← OverallTotal + Mark
SubjectTotal ← SubjectTotal + Mark
NEXT StudentNumber
SubjectAverage ← SubjectTotal / 5
OUTPUT SubjectName
OUTPUT "Average mark is ", SubjectAverage
OUTPUT "Highest Mark is ", SubjectHighest
OUTPUT "Lowest Mark is ", SubjectLowest
NEXT Test
OverallAverage ← OverallTotal / 10
OUTPUT "Overall Average is ", OverallAverage
OUTPUT "Overall Highest Mark is ", OverallHighest
OUTPUT "Overall Lowest Mark is ", OverallLowest
Test data (sample – yours might be different): 1, 99, −1, 101, 20, 80, 30, 70, 40, 60, 50, 50
2 Trace table:
1 1 1 1 1 1 1 1
Enter student 1’s
mark for Maths
2 99 99 100 99 100
Enter student 2’s
mark for Maths
3 -1
Enter student 3’s
mark for Maths
101
Enter student 3’s
mark for Maths
20 120 120
Enter student 3’s
mark for Maths
4 80 200 200
Enter student 4’s
mark for Maths
5 30 230 230
Enter student 5’s
mark for Maths
Maths
Average mark is 46
46
Highest mark is 99
Lowest mark is 1
2 0 100 0
1 70 70 70 70 300
Enter student 1’s
mark for English
2 40 40 110 340
Enter student 2’s
mark for English
3 60 60 170 400
Enter student 3’s
mark for English
4 50 50 220 450
Enter student 4’s
mark for English
5 50 50 270 500
Enter student 5’s
mark for English
English
Average mark is 54
54
Highest mark is 70
Lowest mark is 40
Overall average
mark is 50
50
Overall highest
mark is 99
Overall lowest
mark is 1
7.20
1 Total ← 0
FOR Counter ← 1 TO 10
REPEAT
OUTPUT "Enter positive number "
INPUT Number
UNTIL Number > 0
Total ← Total + Number
NEXT Counter
Average ← Total / 10
OUTPUT "Average is ", Average
OUTPUT "Total is ", Total
2 Total ← 0
Counter ← 0
REPEAT
REPEAT
OUTPUT "Enter positive number, -1 to finish "
INPUT Number
UNTIL Number > 0 OR Number = -1
IF Number <> -1
THEN
Total ← Total + Number
Counter ← Counter + 1
ENDIF
UNTIL Number = -1
Average ← Total / Counter
OUTPUT "Average is ", Average
OUTPUT "Total is ", Total
3 For 1, I chose a FOR … NEXT loop because it has a fixed number of iterations.
For 2, I chose a REPEAT … UNTIL loop because there must be at least one number in the list
but the number of iterations is unknown.
Answers to exam-style questions
Answers to questions 8 and 9 in this section are example answers for past paper questions. The details of
the relevant past paper can be found with the corresponding exam-style question in the Student’s Book.
1 • Inputs – the data used by the system that needs to be entered while the system is active
• Processes – the tasks that need to be performed using the input data and any other
previously stored data
• Outputs – information that needs to be displayed or printed for the users of the system
• Storage – data that needs to be stored in files on an appropriate media for use in the future
3 a Diners – range check 2 to 12 inclusive, presence check and type check of integer
Bill – range check 10 to 500 inclusive, presence check and type check of real
b Test data (sample – yours might be different):
• Normal data: 5 diners and a bill of $90.00
Expected result: $18.00
• Normal data: 8 diners and a bill of $69.00
Expected result: $8.63
c Test data (sample – yours might be different):
• Abnormal data: 15 diners and a bill of $5.00
Expected result: both values rejected
d • Boundary data for lower bounds 1 diner and 2 diners and bills of $9.99 and $10.00
Expected result: 1 and $9.99 both values rejected, 2 and $10.00 $5.00
• Boundary data for upper bounds 12 diners and 13 diners and bills of $500.00 and
$500.01
Expected result: 13 and $500.01 both values rejected, 12 and $500.00 $41.67
4 Validation – the automated checking by a program that data is reasonable before it is accepted
into a computer system
Verification – checking that data has been accurately copied from another source and input into
a computer or transferred from one part of a computer system to another
5 Name:
Validation checks:
• presence to ensure name is entered
• length check to ensure there are not too many letters
Verification check – yes to ensure that the name entered is the one intended and there are no
typing errors
Date of birth:
Validation checks:
• presence to ensure date of birth is entered
• format check to ensure that all the components of the data are in range
• range check to ensure that the value for the date is realistic
Verification check – yes to ensure that the date entered is the one intended and there are no
typing errors
Password:
Validation checks:
• presence to ensure password is entered
• length check to ensure there are the appropriate number of characters
• format check for any special rules, for example at least one digit
Verification check – yes to ensure that the password entered is the one intended and there are
no typing errors
Phone number:
Validation checks:
• presence to ensure phone number is entered
• length check to ensure there are the appropriate number of digits/characters
• format check for any special rules, for example must start with +44
Verification check – yes to ensure that the phone number entered is the one intended and there
are no typing errors
6 a Counter Accept Reject Length Breadth Size OUTPUT
0 0 0
1 1 15 10 150
2 2 20 17 340
3 1 32 10
4 2 30 35
5 3 30 15 450
6 3 30 28 840
7 4 25 25 625
8 4 20 15 300
9 5 40 20 800
10 5 12 10 120 5 5
d Test data: 1, 0, 67, 10, 22, −10, 3, 7, 2, 8, 1, 9 (sample – yours might be different).
1 extreme, 0 erroneous, 67 normal, 10 normal, 22 normal, −10 erroneous, 3 normal,
7 normal, 2 normal, 8 normal, 1 normal and 9 normal.
8 a Number1 Number2 Sign Answer OUTPUT
5 7 + 12 12
6 2 - 4 4
4 3 * 12 12
7 8 ? 0
0 0 / (0)
b CASE Sign OF
ꞌ+ꞌ : Answer ← Number1 + Number2
ꞌ-ꞌ : Answer ← Number1 - Number2
ꞌ*ꞌ : Answer ← Number1 * Number2
ꞌ/ꞌ :
Answer ← Number1 / Number2
OTHERWISE Answer ← 0
ENDCASE
9 a To ensure no changes are made on input, because the details do not have fixed values and
there is no clear set of rules that can be used for validation.
The programmer could ask the contributor to type in each detail twice and then check that
both values are equal. If they are not equal, then the input should be rejected.
b Email – check for @ to ensure that it is an email address. Password – length check to
ensure sufficient characters have been entered.