solution for wjec gcse computer science unit 3 (“developing … · 2016-11-28 · §1·2 the...
TRANSCRIPT
“Lucky Name Numbers”
Solution for WJEC GCSE Computer Science unit 3 (“Developing Computing
Solutions”) controlled assessment
For submission in May 2017
By Mark Bishop
<http://AModernPrometheus.WordPress.com/>
Contents
§1Design of Solution............................................................................................................. 1§2Implementation & Program Documentation................................................................... 13§3Testing............................................................................................................................19§4Evaluation.......................................................................................................................31
WJEC GCSE Computer Science unit 3 (“Developing Computing Solutions”) controlled assessment “Lucky Name Numbers”.................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Contents i of i
Design of Solution
§1·1 This author has been tasked with programming a solution for determining the “lucky number” – and the meaning of that “lucky number” – for a name, using a method, purportedly developed by Pythagoras, wherein every letter of the alphabet is associated with a digit in the
range
!
0,9( ] , and the digits associated with the letters of a name are repeatedly summed together
to arrive at a single-digit number, the “lucky number”.
The following table illustrates the associations between the letters of the alphabet and the digits.
ZYXWVUTS
RQPONMLKJ
IHGFEDCBA
987654321
The following list illustrates the associations between the lucky numbers and the meanings of the lucky numbers.
1. “Natural leaders”;2. “natural peacemakers”;3. “creative and optimistic”;4. “hard workers”;5. “value freedom”;6. “carers and providers”;7. “thinkers”;8. “have diplomatic skills”;9. “selfless and generous”.
The following example illustrates the determination of the lucky number – and the meaning of that lucky number – for the name “Eleanor Wiseman”.
1. The digits associated with the letters of the name are determined:
51451959651535
namesiWronaelE
2. The digits associated with the letters of the name are summed together:
!
5, 3,5,1, 5,6,9,5,9,1,5,4,1,5{ }" = 64
3. The digits of the number arrived at by summing together the digits associated with theletters of the name are repeatedly summed together to arrive at a single-digit number, thelucky number:
!
6, 4{ }" =10# 1,0{ }" =1
4. The meaning of the lucky number is looked up:1 = “natural leaders”.
The solution must make possible the entry of a name by the user, determine the lucky number – and the meaning of that lucky number – for the name entered by the user, and output the name entered by the user and the lucky number – and the meaning of that lucky number – for that name.
§1·2 The following diagram illustrates the screens of-, and the transitions between the screens of-, the proposed user interface.
WJEC GCSE Computer Science unit 3 (“Developing Computing Solutions”) controlled assessment “Lucky Name Numbers”.................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Design of Solution 1 of 33
Begin program execution
End program execution
1
---
- “Lucky Name Numbers”
- Solution for WJEC GCSE Computer Science
unit 3 (“Developing Computing Solutions”)
controlled assessment
- for submission in May 2017
- by Mark Bishop
- <http://AModernPrometheus.WordPress.com/>
---
2
Please enter a name and press the Return key –
this program will then determine the lucky
number for that name and the meaning of that
lucky number.
(Alternatively, enter nothing and press the
Return key to quit this program.)
Your input:
5
---
- This program will now
quit.---
4
Sorry, this program cannot
determine lucky numbers
for names which do notcontain at least one
letter, so this program
cannot determine the
lucky number for the name
“name”.
3
name’s lucky number is
lucky number; the meaning
of that lucky number is “meaning of lucky number”.
6
Please press the Return key to continue.
For submission in May 2017 By Mark Bishop.................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Design of Solution 2 of 33
§1·3 The program will place limits neither on the number of names a person may have nor on the length of any of the names a person may have.
Whilst the program will inform the user if it cannot determine the lucky number for a name if that name is comprised only of non-letter characters, the program will not reject a name if that name contains, in addition to letter characters, non-letter characters, as if the program were to do so it would preclude the user from being able to use the program to determine lucky numbers for names such as “Jack O’Neill” (due to the apostrophe in the family name “O’Neill”).
§1·4 The programming languages with which this author is familiar, and thus the programming languages in which this author may decide to program the solution, are C, C++, Java, METAL BASIC, Pascal, and Python.
This author has decided to program the solution in the Pascal programming language due to that programming language providing: support for modular programming (as whilst it is unlikely that any of the modules into which the program will be broken will be useful in other programs, breaking the program into modules will make it possible for those modules to be unit tested – viz., tested in isolation from the rest of the program – before the integration of those modules to produce the complete program); a built-in “string” type; and compile- and run-time range-checking for user-defined types.
Whilst the C and C++ programming languages provide support for modular programming, it is this author’s belief that programming the solution in the Pascal programming language will result in a shorter and easier-to-understand program; for example, a difference between those programming languages which can result in a shorter program if the program is written in the Pascal, rather than the C, programming language is that the Pascal programming language
provides a built-in “string” type whilst the C programming language does not; this difference
resulting in a difference in program length is illustrated by the following comparison of two (almost1) equivalent programs written in the Pascal and C programming languages.
The program written in the Pascal programming language:
1 program string_example( input, output );
2 var
3 name : string;
4 begin
5 writeln( 'Please enter a name and press the Return key – this program will then
.. write that name to the screen.' );
6 writeln;
7 write( 'Your input: ' );
8 readln( name );
9 writeln;
10 writeln( 'You entered the name "', name, '".' )
11 end.
1 This author acknowledges that the built-in “string” type provided by the Pascal programming language is more limited with regards to length than an array of characters in the C programming language; the built-in “string” type provided by the Pascal programming
language is limited to being at most
!
255 characters in length, whilst an array of characters in the C programming language is limited to
being at most the maximum value of size_t characters in length, with size_t having the maximum value
!
232"1 – a seven order
of magnitude difference – in Leonardo IDE 3.4.12, the interpreter for the C programming language this author used to develop the
program written in the C programming language used in the comparison.2 LeonardoA C Programming Environment for Reversible Execution and Software VisualizationDemetrescu, Camil and Finocchi, Irene
<http://www.dis.uniroma1.it/~demetres/Leonardo/>
Retrieved on the 7th of September, 2012
WJEC GCSE Computer Science unit 3 (“Developing Computing Solutions”) controlled assessment “Lucky Name Numbers”.................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Design of Solution 3 of 33
The program written in the C programming language:
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 char *readln( void )
5 {
6 char character, *string = ( char* )malloc( sizeof( char ));
7 size_t string_length = 1;
8 scanf( "%c", &character );
9 while( character != '\n' )
10 {
11 string = realloc( string, sizeof( char ) * ( string_length + 1 ));
12 string[ string_length - 1 ] = character;
13 string_length ++;
14 scanf( "%c", &character );
15 }
16 string[ string_length - 1 ] = '\0';
17 return string;
18 }
19
20 void main( void )
21 {
22 char *name;
23 printf( "Please enter a name and press the Return key – this program will then print
.. that name to the screen.\n" );
24 printf( "\n" );
25 printf( "Your input: " );
26 name = readln();
27 printf( "\n" );
28 printf( "You entered the name \"%s\".\n", name );
29 free( name );
30 }
Whilst the METAL BASIC programming language provides a built-in “string” type, that programming language provides no support for modular programming.
Whilst the Java and Python programming languages provide both support for modular programming and a built-in “string” type, it is this author’s belief that the compile- and run-time range-checking for user-defined types provided by the Pascal programming language will result in an easier-to-program and better self-documenting (and thus easier-to-understand) program if the solution is programmed in the Pascal programming language; the utility of the compile- and run-time range-checking for user-defined types provided by the Pascal programming language is illustrated by the following program written in that programming language.
1 program range_checking_example;
2 type
3 t_Digit = 0..9;
4 var
5 digit : t_Digit;
6 begin
7 {$R+} { This compiler directive enables range-checking. }
8 digit := 10 { With range-checking enabled, this assignment will result in a compile-
.. time error. }
9 end.
For submission in May 2017 By Mark Bishop.................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Design of Solution 4 of 33
!
!
!
!
!
!
!
!
!
!
Python
Pascal
METAL BASIC
Java
C++
C
Provides range-checking for user-defined types
Provides a built-in “string” type
Provides support for modular programming
Programming language
§1·5 The programming environment available to this author for programming in the Pascal programming language is Metrowerks CodeWarrior IDE 2.1 (Discover Programming Edition), running on an Apple Power Mac G4 (AGP Graphics) (450MHz processor, 1GB memory) running Apple Mac OS 9.2.2 (International English).
§1·6 The following diagram illustrates the proposed modularisation of the program.
Lucky Name Numbers
Digit summing.pasName- to- number conversion.pas
Lucky Name Numbers.pas
§1·7 The Pascal programming language provides multiple ways in which a digit associated with a letter may be stored and retrieved, including (but not limited to):
• using multiple “if”/“else” statements and “or” Boolean operators, for example:if ( character = ‘A’ ) or ( character = ‘J’ ) or ( character = ‘S’ ) then
digit := 1
else
...
• using multiple “if”/“else” statements and sets, for example:if character in [ ‘A’, ‘J’, ‘S’ ] then
digit := 1
else
WJEC GCSE Computer Science unit 3 (“Developing Computing Solutions”) controlled assessment “Lucky Name Numbers”.................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Design of Solution 5 of 33
...
• using an array with a character index, for example:digits : array [ ‘A’..‘Z’ ] of 1..9;
...
digits[ ‘A’ ] := 1;
digits[ ‘B’ ] := 2;
digits[ ‘C’ ] := 3;
...
digit := digits[ character ];
• and using a “case” statement, for example:case character of
‘A’, ‘J’, ‘S’:digit := 1;
...
This author has decided that a digit associated with a letter will be stored and retrieved using a “case” statement, as it is this author’s belief that, out of the ways in which a digit associated with a letter may be stored and retrieved in the Pascal programming language, a “case” statement most closely resembles the table illustrating the associations between the letters of the alphabet and the digits in §1·1.
For brevity, and to more closely resemble the table illustrating the associations between the letters of the alphabet and the digits in §1·1, only uppercase letters will be used in the “case” statement, with the character input to the “case” statement being converted into an uppercase letter (if necessary) using the built-in upcase( char ) : char function provided by the Pascal
programming language.
Any character which is not a letter will have associated with it the digit 0.
§1·8 The following flowchart illustrates the proposed method for converting a name into a number.
For submission in May 2017 By Mark Bishop.................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Design of Solution 6 of 33
WJEC GCSE Computer Science unit 3 (“Developing Computing Solutions”) controlled assessment “Lucky Name Numbers”.................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Design of Solution 7 of 33
Begin
Assign the value0 to the
variable number.
Assign the value1 to the
variable i.
Is the valueof thevariable igreater than
the length in charactersof the string heldby thevariable name?
Assign the ith character
of the string heldby thevariable name to the
variable character.
Is the character heldbythe variable character
an uppercaseletter?
Isthe character heldbythe variable character a
lowercaseletter?
Convert the characterheldby the variablecharacter into an
uppercaseletter usingthe built-in upcase(
char ) : char function
provided by the Pascalprogramminglanguage.
Add1 to the valueof the
variable i.
1
End
YesNo
Yes No
Yes No
2
1
Isthe character heldbythe variable character
in the set [ ‘A’, ‘J’,
‘S’ ]?
Add1 to the valueof the
variable number.
Is the character heldbythe variable character
in the set [ ‘B’, ‘K’,
‘T’ ]?
Add2 to the valueof the
variable number.
Is the character heldbythe variable character
in the set [ ‘C’, ‘L’,
‘U’ ]?
Add3 to the valueof the
variable number.
Is the character heldbythe variable character
in the set [ ‘D’, ‘M’,
‘V’ ]?
Add4 to the valueof the
variable number.
3
2
Yes
Yes
Yes
Yes
No
No
No
No
For submission in May 2017 By Mark Bishop.................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Design of Solution 8 of 33
3
Isthe character heldbythe variable character
in the set [ ‘E’, ‘N’,
‘W’ ]?
Add5 to the valueof the
variable number.
Yes
Isthe character heldbythe variable character
in the set [ ‘F’, ‘O’,
‘X’ ]?
Add6 to the valueof the
variable number.
Is the character heldbythe variable character
in the set [ ‘G’, ‘P’,
‘Y’ ]?
Add7 to the valueof the
variable number.
Is the character heldbythe variable character
in the set [ ‘H’, ‘Q’,
‘Z’ ]?
Add9 to the valueof the
variable number.
Add8 to the valueof the
variable number.
2
Yes
Yes
YesNo
No
No
No
§1·9 The procedure or function for converting a name into a number will be unit tested – viz., tested in isolation from the rest of the program – using black-box testing – viz., testing
WJEC GCSE Computer Science unit 3 (“Developing Computing Solutions”) controlled assessment “Lucky Name Numbers”.................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Design of Solution 9 of 33
concerned with the inputs to- and outputs from- that procedure or function, not with the method by which those inputs become those outputs.
The black-box unit testing of that procedure or function will be automated.
Test-cases will be selected which will test the functionality of that procedure or function when the input name is:
i. an empty string;ii. a single non-letter character;
iii. a single lowercase letter character;iv. a single uppercase letter character;v. comprised of multiple non-letter characters;
vi. comprised of multiple lowercase letter characters;vii. comprised of multiple uppercase letter characters;
viii. comprised of multiple lowercase and uppercase letter characters;ix. comprised of multiple non-letter and letter characters.
§1·10 The following flowchart illustrates the proposed method for summing together of the digits of a number (if that number is a multiple-digit number) to arrive at a single-digit number.
For submission in May 2017 By Mark Bishop.................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Design of Solution 10 of 33
Begin
Isthe valueof thevariable numbergreater
than- or equal to- 10?
Assign the value0 to the
variable new_number.
Yes
End
No
Isthe valueof thevariable numberequal to
0?
Assign the valueof thevariable new_number to
the variable number.
Yes
Assign the valueof thevariable number,
modulus10, to the
variable digit.
No
Addthe valueof thevariable digit to the
valueof the variablenew_number.
Dividethe valueof thevariable numberby 10,
discardinganyfractional part.
§1·11 The procedure or function for summing together the digits of a number (if that number is a multiple-digit number) to arrive at a single-digit number will be unit tested – viz., tested in isolation from the rest of the program – using black-box testing – viz., testing concerned with the inputs to- and outputs from- that procedure or function, not with the method by which those inputs become those outputs.
The black-box unit testing of that procedure or function will be automated.
Test-cases will be selected which will test the functionality of that procedure or function when the input number is:
i. zero;ii. a single-digit positive number;
iii. a multiple-digit positive number, the digits of which sum to a number less than 10;
WJEC GCSE Computer Science unit 3 (“Developing Computing Solutions”) controlled assessment “Lucky Name Numbers”.................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Design of Solution 11 of 33
iv. a multiple-digit positive number, the digits of which sum to a number greater than- or equal to- 10.
The minimum number which may be output from the procedure or function for converting a name into a number will be – if the name input to that procedure or function is comprised only of non-letter characters – zero; as the number input to the procedure or function for summing together the digits of a number (if that number is a multiple-digit number) to arrive at a single-digit number will be the number output from the procedure or function for converting a name into a number, it will thus not be necessary to test the functionality of that former procedure or function when the number input to that procedure or function is negative.
§1·12 Following the automated black-box unit testing of the procedures or functions for converting a name into a number and for summing together the digits of a number (if that number is a multiple-digit number) to arrive at a single-digit number, those procedures or functions will be integrated to produce the complete program, and the complete program will be manually tested to test the correctness of the outputs computed for the user inputs to the complete program and the correctness of the user interface of the complete program – viz., that the outputs computed are correctly formatted and that the screens of the user interface are correctly transitioned between.
Test-cases will be selected which will test the correctness of the outputs computed by the complete program and the user interface of the complete program when the user enters:
i. nothing and presses the Return key to quit the program on screen 2;ii. a name comprised of a single non-letter character on screen 2;
iii. a name comprised of a single lowercase letter character on screen 2;iv. a name comprised of a single uppercase letter character on screen 2;v. a name comprised of multiple non-letter characters on screen 2;
vi. a name comprised of multiple lowercase letter characters on screen 2;vii. a name comprised of multiple uppercase letter characters on screen 2;
viii. a name comprised of multiple lowercase and uppercase letter characters on screen 2;ix. a name comprised of multiple non-letter and letter characters on screen 2;x. nothing and presses the Return key to transition to screen 2 on screen 6;
xi. anything and presses the Return key to transition to screen 2 on screen 6.
For submission in May 2017 By Mark Bishop.................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Design of Solution 12 of 33
Implementation & Program Documentation
§2·1 The following diagram illustrates the actual modularisation of the program – cf. the diagram illustrating the proposed modularisation of the program in §1·6.
lib_Types.pas
Lucky Name Numbers
Lucky Name Numbers.pas
lib_DigitSumming.paslib_NameToNumberConversion.pas
§2·2 The following describes the differences between the default settings for a MacOS
!
" Pascal
!
" ANS Console 68k project in Metrowerks CodeWarrior IDE 2.1 (Discover Programming Edition) and the settings for this project.
“!” indicates a setting which is by default inactive, and which has been activated.
Conversely, “"” indicates a setting which is by default active, and which has been deactivated.• Target
• Target Settings• Target Name: ANS Console 68k
!
" Lucky Name Numbers• 68K Target
• File Name: Hello World 68k
!
" Lucky Name Numbers• Language Settings
• Pascal Language
• Debugging Aids: ! Activate Range Checking
WJEC GCSE Computer Science unit 3 (“Developing Computing Solutions”) controlled assessment “Lucky Name Numbers” .................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Implementation & Program Documentation 13 of 33
• IO Model: ! ANS Pascal
" Turbo Pascal
• ! ANS Conformance
• " Case Sensitive Identifiers• Pascal Warnings
• " Modified For-Loop Indexes
• " Function Returns
• " Unused Variables
• " Unused Arguments
• " Undefined Routines
§2·3 The following listing is of the source code file lib_Types.pas.
1 unit lib_Types;
2 {
3 - Part of a solution to "Lucky Name Numbers"
4 - WJEC GCSE Computer Science unit 3 ("Developing Computing Solutions") controlled
.. assessment for submission in May 2017
5 - by Mark Bishop
6 - <http://AModernPrometheus.WordPress.com/>
7 }
8
9 interface
10
11 type
12 t_Digit = 0..9;
13 t_WholeNumber = 0..maxint; { As defined by the College Algebra (MA008)
.. (<http://Udacity.com/course/ma008>) course offered by Udacity. }
14
15 end.
§2·4 The following listing is of the source code file lib_NameToNumberConversion.pas.
1 unit lib_NameToNumberConversion;
2 {
3 - Part of a solution to "Lucky Name Numbers"
4 - WJEC GCSE Computer Science unit 3 ("Developing Computing Solutions") controlled
.. assessment for submission in May 2017
5 - by Mark Bishop
6 - <http://AModernPrometheus.WordPress.com/>
7 }
8
9 interface
10
11 uses
12 lib_Types;
13
14 function f_ConvertNameToNumber( name : string ) : t_WholeNumber;
15 {
16 - The above function sums together the digits associated with the letter characters of
.. a name to arrive at a number, which it returns.
17 }
18
19 implementation
20
21 function f_ConvertNameToNumber( name : string ) : t_WholeNumber;
22 var
For submission in May 2017 By Mark Bishop.................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Implementation & Program Documentation 14 of 33
23 number : t_WholeNumber;
24 i : 1..maxint;
25 character : char;
26 digit : t_Digit;
27 begin
28 number := 0;
29 if length( name ) >= 1 then
30 for i := 1 to length( name ) do begin
31 character := name[ i ];
32 if character in [ 'a'..'z' ] then
33 character := upcase( character );
34 digit := 0;
35 case character of
36 'A', 'J', 'S':digit := 1;
37 'B', 'K', 'T':digit := 2;
38 'C', 'L', 'U':digit := 3;
39 'D', 'M', 'V':digit := 4;
40 'E', 'N', 'W':digit := 5;
41 'F', 'O', 'X':digit := 6;
42 'G', 'P', 'Y':digit := 7;
43 'H', 'Q', 'Z':digit := 8;
44 'I', 'R':digit := 9
45 end;
46 number := number + digit
47 end;
48 f_ConvertNameToNumber := number
49 end;
50
51 end.
§2·5 The following listing is of the source code file lib_DigitSumming.pas.
1 unit lib_DigitSumming;
2 {
3 - Part of a solution to "Lucky Name Numbers"
4 - WJEC GCSE Computer Science unit 3 ("Developing Computing Solutions") controlled
.. assessment for submission in May 2017
5 - by Mark Bishop
6 - <http://AModernPrometheus.WordPress.com/>
7 }
8
9 interface
10
11 uses
12 lib_Types;
13
14 function f_SumDigits( number : t_WholeNumber ) : t_Digit;
15 {
16 - The above function sums together the digits of a number (if that number is a
.. multiple-digit number) to arrive at a single-digit number, which it returns.
17 }
18
19 implementation
20
21 function f_SumDigits( number : t_WholeNumber ) : t_Digit;
22 var
23 new_number : t_WholeNumber;
24 digit : t_Digit;
25 begin
WJEC GCSE Computer Science unit 3 (“Developing Computing Solutions”) controlled assessment “Lucky Name Numbers” .................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Implementation & Program Documentation 15 of 33
26 while number >= 10 do begin
27 new_number := 0;
28 while number <> 0 do begin
29 digit := number mod 10;
30 new_number := new_number + digit;
31 number := number div 10
32 end;
33 number := new_number
34 end;
35 f_SumDigits := number
36 end;
37
38 end.
§2·6 The following listing is of the source code file Lucky Name Numbers.pas.
1 program Lucky_Name_Numbers( input, output );
2 uses
3 lib_Types, lib_NameToNumberConversion, lib_DigitSumming;
4 var
5 name : string;
6 number : t_WholeNumber;
7 lucky_number : t_Digit;
8 begin
9 writeln( '---' );
10 writeln( '- "Lucky Name Numbers"' );
11 writeln( '- Solution for WJEC GCSE Computer Science unit 3 ("Developing Computing
.. Solutions") controlled assessment' );
12 writeln( '- for submission in May 2017' );
13 writeln( '- by Mark Bishop' );
14 writeln( '- <http://AModernPrometheus.WordPress.com/>' );
15 writeln( '---' );
16 writeln;
17 repeat
18 writeln( 'Please enter a name and press the Return key – this program will then
.. determine the lucky number for that name and the meaning of that lucky number.'
.. );
19 writeln;
20 writeln( '(Alternatively, enter nothing and press the Return key to quit this
.. program.)' );
21 writeln;
22 write( 'Your input: ' );
23 readln( name );
24 if length( name ) > 0 then begin
25 writeln;
26 number := f_ConvertNameToNumber( name );
27 if number <> 0 then begin
28 lucky_number := f_SumDigits( number );
29 write( '"', name, '"''' );
30 if not ( upcase( name[ length( name ) ] ) in [ 'S', 'X' ] ) then
31 write( 's' );
32 write( ' lucky number is ', lucky_number, '; the meaning of that lucky
.. number is "' );
33 case lucky_number of
34 1:write( 'natural leaders' );
35 2:write( 'natural peacemakers' );
36 3:write( 'creative and optimistic' );
37 4:write( 'hard workers' );
38 5:write( 'value freedom' );
For submission in May 2017 By Mark Bishop.................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Implementation & Program Documentation 16 of 33
39 6:write( 'carers and providers' );
40 7:write( 'thinkers' );
41 8:write( 'have diplomatic skills' );
42 9:write( 'selfless and generous' )
43 end;
44 writeln( '".' )
45 end
46 else
47 writeln( 'Sorry, this program cannot determine lucky numbers for names which
.. do not contain at least one letter, so this program cannot determine the
.. lucky number for the name "', name, '".' );
48 writeln;
49 write( 'Please press the Return key to continue.' );
50 readln
51 end;
52 writeln
53 until length( name ) = 0;
54 writeln( '---' );
55 writeln( '- This program will now quit.' );
56 writeln( '---' )
57 end.
WJEC GCSE Computer Science unit 3 (“Developing Computing Solutions”) controlled assessment “Lucky Name Numbers” .................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Implementation & Program Documentation 17 of 33
Testing
§3·1 The following is the black-box unit testing of the function for converting a name into a number, f_ConvertNameToNumber, as outlined in §1·9 – viz., the input to-, expected output from-,
and actual output from- that function.
Expected
Expected
!
!
2
1
‘B’
‘A’
iv.
iv.
31
30
!Expected8‘z’iii.29
!
!
Expected
Expected
28
27
iii.
iii.
7
6
‘y’
‘x’
Expected
Expected
Expected
Expected
!
!
!
!
!
!
!
26
25
24
23
22
21
20
Expected
Expected
Expected
iii.
iii.
iii.
iii.
iii.
iii.
iii.
5
4
3
2
1
9
8
‘w’
‘v’
‘u’
‘t’
‘s’
‘r’
‘q’
!
!
!
!
!
!
!
!
Expected
Expected
Expected
Expected
Expected
Expected
Expected
Expected
7
6
5
4
3
2
1
9
iii.
iii.
iii.
iii.
iii.
iii.
iii.
iii.
‘p’
‘o’
‘n’
‘m’
‘l’
‘k’
‘j’
‘i’
19
18
17
16
15
14
13
12
!
!
!
!
!
!
!
!
Expected
Expected
Expected
Expected
Expected
Expected
Expected
Expected
8
7
6
5
4
3
2
1
‘h’
‘g’
‘f’
‘e’
‘d’
‘c’
‘b’
‘a’
iii.
iii.
iii.
iii.
iii.
iii.
iii.
iii.
11
10
9
8
7
6
5
4
!
!
Expected
Expected
0
0
‘-’
‘!’
ii.
ii.
3
2
!Expected0i.1 ‘’
Actual number output
Expected number output
Name input Test passed
Test type(refer to §1·9 for the
meaning of these values)
Test number
WJEC GCSE Computer Science unit 3 (“Developing Computing Solutions”) controlled assessment “Lucky Name Numbers”.................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Testing 19 of 33
!
!Expected
Expected14
38
‘Teal’’c’
‘Jack O’’Neill’
ix.
ix.
65
64
!
!Expected
Expected46
35‘SamCarter’
‘DanielJackson’
viii.
viii.
63
62
Expected
Expected
29
19
‘CARTER’
‘JACKSON’ !
!vii.
vii.
61
60
Expected
Expected6
27
‘sam’
‘daniel’
!
!
59
58
vi.
vi.
Expected
Expected
!
!
57
56
0
0
‘+-’
‘?!’
v.
v.
Expected
Expected
Expected
Expected
Expected
Expected
8
7
6
5
4
3
!
!
!
!
!
!
55
54
53
52
51
50
iv.
iv.
iv.
iv.
iv.
iv.
‘Z’
‘Y’
‘X’
‘W’
‘V’
‘U’
Expected
Expected
Expected
Expected
Expected
Expected
Expected
Expected
Expected
!
!
!
!
!
!
!
!
!
2
1
9
8
7
6
5
4
3
49
48
47
46
45
44
43
42
41
iv.
iv.
iv.
iv.
iv.
iv.
iv.
iv.
iv.
‘T’
‘S’
‘R’
‘Q’
‘P’
‘O’
‘N’
‘M’
‘L’
Expected
Expected
Expected
Expected
Expected
Expected
Expected
Expected
!
!
!
!
!
!
!
!
iv.
iv.
iv.
iv.
iv.
iv.
iv.
iv.
40
39
38
37
36
35
2
1
9
8
7
6
5
4
‘K’
‘J’
‘I’
‘H’
‘G’
‘F’
‘E’
‘D’
34
33
!Expected3‘C’iv.32
Test type(refer to §1·9 for the
meaning of these values)
Name input Expected number output
Actual number output
Test passed
Test number
§3·2 The following listing is of the source code of the framework for performing the automatic
For submission in May 2017 By Mark Bishop.................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Testing 20 of 33
black-box unit testing of the function for converting a name into a number, f_ConvertNameToNumber.
1 program Test_name_to_number_conversion( output );
2 {
3 - Part of a solution to "Lucky Name Numbers"
4 - WJEC GCSE Computer Science unit 3 ("Developing Computing Solutions") controlled
... assessment for submission in May 2017
5 - by Mark Bishop
6 - <http://AModernPrometheus.WordPress.com/>
7 }
8
9 uses
10 lib_NameToNumberConversion, lib_Types;
11
12 var
13 test_number : 1..maxint;
14
15 procedure p_Test( p_input : string; p_expectedOutput : t_WholeNumber );
16 var
17 output : t_WholeNumber;
18 begin
19 write( test_number:2, ' - ' );
20 test_number := test_number + 1;
21 output := f_ConvertNameToNumber( p_input );
22 if output <> p_expectedOutput then
23 write( 'Failed: output (', output, ') <> expected output (', p_expectedOutput,
... ')' )
24 else
25 write( 'Passed' );
26 writeln( '.' )
27 end;
28
29 begin
30 writeln( '- This program performs the automated black-box unit testing of the
... function f_ConvertNameToNumber.' );
31 writeln( '---' );
32 writeln;
33 test_number := 1;
34
35 p_Test( '', 0 ); { Type i. tests. }
36
37 p_Test( '!', 0 ); { Type ii. tests. }
38 p_Test( '-', 0 );
39
40 p_Test( 'a', 1 ); { Type iii. tests. }
41 p_Test( 'b', 2 );
42 p_Test( 'c', 3 );
43 p_Test( 'd', 4 );
44 p_Test( 'e', 5 );
45 p_Test( 'f', 6 );
46 p_Test( 'g', 7 );
47 p_Test( 'h', 8 );
48 p_Test( 'i', 9 );
49 p_Test( 'j', 1 );
50 p_Test( 'k', 2 );
51 p_Test( 'l', 3 );
52 p_Test( 'm', 4 );
53 p_Test( 'n', 5 );
WJEC GCSE Computer Science unit 3 (“Developing Computing Solutions”) controlled assessment “Lucky Name Numbers”.................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Testing 21 of 33
54 p_Test( 'o', 6 );
55 p_Test( 'p', 7 );
56 p_Test( 'q', 8 );
57 p_Test( 'r', 9 );
58 p_Test( 's', 1 );
59 p_Test( 't', 2 );
60 p_Test( 'u', 3 );
61 p_Test( 'v', 4 );
62 p_Test( 'w', 5 );
63 p_Test( 'x', 6 );
64 p_Test( 'y', 7 );
65 p_Test( 'z', 8 );
66
67 p_Test( 'A', 1 ); { Type iv. tests. }
68 p_Test( 'B', 2 );
69 p_Test( 'C', 3 );
70 p_Test( 'D', 4 );
71 p_Test( 'E', 5 );
72 p_Test( 'F', 6 );
73 p_Test( 'G', 7 );
74 p_Test( 'H', 8 );
75 p_Test( 'I', 9 );
76 p_Test( 'J', 1 );
77 p_Test( 'K', 2 );
78 p_Test( 'L', 3 );
79 p_Test( 'M', 4 );
80 p_Test( 'N', 5 );
81 p_Test( 'O', 6 );
82 p_Test( 'P', 7 );
83 p_Test( 'Q', 8 );
84 p_Test( 'R', 9 );
85 p_Test( 'S', 1 );
86 p_Test( 'T', 2 );
87 p_Test( 'U', 3 );
88 p_Test( 'V', 4 );
89 p_Test( 'W', 5 );
90 p_Test( 'X', 6 );
91 p_Test( 'Y', 7 );
92 p_Test( 'Z', 8 );
93
94 p_Test( '?!', 0 ); { Type v. tests. }
95 p_Test( '+-', 0 );
96
97 p_Test( 'daniel', 27 ); { Type vi. tests. }
98 p_Test( 'sam', 6 );
99
100 p_Test( 'JACKSON', 19 ); { Type vii. tests. }
101 p_Test( 'CARTER', 29 );
102
103 p_Test( 'DanielJackson', 46 ); { Type viii. tests. }
104 p_Test( 'SamCarter', 35 );
105
106 p_Test( 'Jack O''Neill', 38 ); { Type ix. tests. }
107 p_Test( 'Teal''c', 14 );
108
109 writeln;
110 writeln( '---' );
111 writeln( '- This program will now quit.' )
112 end.
For submission in May 2017 By Mark Bishop.................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Testing 22 of 33
§3·3 The following is the black-box unit testing of the function for summing together the digits of a number (if that number is a multiple-digit number) to arrive at a single-digit number, f_SumDigits, as outlined in §1·11 – viz., the input to-, expected output from-, and actual output
from- that function.
1983
19
16
21
7
3
0
3
1
7
3
7
3
0
!
!
!
!
!
!
!
Expected
Expected
Expected
Expected
Expected
Expected
Expected
iv.
iv.
iii.
iii.
ii.
ii.
i.
7
6
5
4
3
2
1
Test type(refer to §1·11 for
the meaning of these values)
Test passed
Actual number output
Expected number output
Number inputTest number
§3·4 The following listing is of the source code of the framework for performing the automatic black-box unit testing of the function for summing together the digits of a number (if that number is a multiple-digit number) to arrive at a single-digit number, f_SumDigits.
1 program Test_digit_summing( output );
2 {
3 - Part of a solution to "Lucky Name Numbers"
4 - WJEC GCSE Computer Science unit 3 ("Developing Computing Solutions") controlled
... assessment for submission in May 2017
5 - by Mark Bishop
6 - <http://AModernPrometheus.WordPress.com/>
7 }
8
9 uses
10 lib_Types, lib_DigitSumming;
11
12 var
13 test_number : 1..maxint;
14
15 procedure p_Test( p_input : t_WholeNumber; p_expectedOutput : t_Digit );
16 var
17 output : t_Digit;
18 begin
19 write( test_number, ' - ' );
20 test_number := test_number + 1;
21 output := f_SumDigits( p_input );
22 if output <> p_expectedOutput then
23 write( 'Failed: output (', output, ') <> expected output (', p_expectedOutput,
... ')' )
24 else
25 write( 'Passed' );
26 writeln( '.' )
27 end;
28
29 begin
30 writeln( '- This program performs the automated black-box unit testing of the
... function f_SumDigits.' );
WJEC GCSE Computer Science unit 3 (“Developing Computing Solutions”) controlled assessment “Lucky Name Numbers”.................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Testing 23 of 33
31
writeln( '---' );
32
writeln;
33
test_number := 1;
34
p_Test( 0, 0 ); { Type i. tests. }
35
p_Test( 3, 3 ); { Type ii. tests. }
36
p_Test( 7, 7 );
37
p_Test( 21, 3 ); { Type iii. tests. }
38
p_Test( 16, 7 );
39
p_Test( 19, 1 ); { Type iv. tests. }
40
p_Test( 1983, 3 );
41
writeln;
42
writeln( '---' );
43
writeln( '- This program will now quit.' )
44
end.
§3
·5 T
he
foll
ow
ing
is
the
test
ing
of
the
com
ple
te p
rog
ram
, as
ou
tlin
ed i
n §
1·1
2.
Expected
hard workers
Expected
4Expected
dExpected
3d
!ii
i.6
2
Expected
Expected
creative and
optimistic
natural
peacemakers
Expected
Expected
32
Expected
Expected
cb
!!
cb
Expected
Expected
33
22
iii.
iii.
54
Expected
natural
leaders
Expected
1Expected
aExpected
3a
!2
iii.
3
N/a
N/a
Expected
!Expected
4!
!2
ii.
2
N/a
N/a
N/a
Expected
5®
!i.
21
Actu
al
luck
y
nu
mb
er
mea
nin
g
ou
tpu
t
Ex
pecte
d
luck
y
nu
mb
er
mea
nin
g
ou
tpu
t
Actu
al
luck
y
nu
mb
er
ou
tpu
t
Ex
pecte
d
luck
y
nu
mb
er
ou
tpu
t
Actu
al
na
me
ou
tpu
t
Ex
pecte
d
na
me
ou
tpu
t
Use
r
inp
ut
Test
p
ass
ed
Actu
al
screen
tr
an
sit-
ion
ed
to
Ex
pecte
d
screen
tr
an
sit-
ion
ed
to
Sc
re
en
Test
ty
pe
(ref
er t
o
§1
·12
fo
r th
e m
ean
ing
o
f th
ese
val
ues
)
Test
n
um
be
r
For
subm
issi
on i
n M
ay 2
017
By M
ark B
ishop
............................................................................................................................................................................................................................................................................................................................................................
............................................................................................................................................................................................................................................................................................................................................................
Tes
ting
24
of
33
19
18
Expected
Expected
have
diplomatic
skills
thinkers
Expected
Expected
87
Expected
Expected
qp
Expected
Expected
33
qp
!!
iii.
iii.
22
17
16
15
14
13
Expected
Expected
Expected
Expected
Expected
carers and
providers
value
freedom
hard workers
creative and
optimistic
natural
peacemakers
Expected
Expected
Expected
Expected
Expected
65432
Expected
Expected
Expected
Expected
Expected
onmlk
Expected
Expected
Expected
Expected
Expected
Expected
Expected
Expected
Expected
Expected
Expected
33333
onmlk
!!!!!
iii.
iii.
iii.
iii.
iii.
22222
Expected
Expected
Expected
Expected
Expected
Expected
natural
leaders
selfless and
generous
have
diplomatic
skills
thinkers
carers and
providers
value
freedom
Expected
Expected
Expected
Expected
Expected
Expected
198765
Expected
Expected
Expected
Expected
Expected
Expected
jihgfe
333333
jihgfe
!!!!!!
222222
iii.
iii.
iii.
iii.
iii.
iii.
12
11
10987
Actu
al
luck
y
nu
mb
er
mea
nin
g
ou
tpu
t
Ex
pecte
d
luck
y
nu
mb
er
mea
nin
g
ou
tpu
t
Actu
al
luck
y
nu
mb
er
ou
tpu
t
Ex
pecte
d
luck
y
nu
mb
er
ou
tpu
t
Actu
al
na
me
ou
tpu
t
Ex
pecte
d
na
me
ou
tpu
t
Use
r
inp
ut
Test
p
ass
ed
Actu
al
screen
tr
an
sit-
ion
ed
to
Ex
pecte
d
screen
tr
an
sit-
ion
ed
to
Sc
re
en
Test
ty
pe
(ref
er t
o
§1
·12
fo
r th
e m
ean
ing
o
f th
ese
val
ues
)
Test
n
um
be
r
WJE
C G
CS
E C
om
pu
ter
Sci
ence
un
it 3
(“D
evel
op
ing
Co
mp
uti
ng
So
luti
on
s”)
con
tro
lled
ass
essm
ent
“Lu
cky
Nam
e N
um
ber
s”............................................................................................................................................................................................................................................................................................................................................................
............................................................................................................................................................................................................................................................................................................................................................
Tes
ting
25
of
33
33
Expected
value
freedom
Expected
5Expected
EExpected
3E
!iv
.2
!Expected
hard workers
Expected
4Expected
DD
Expected
32
iv.
32
31
30
29
Expected
Expected
Expected
creative and
optimistic
natural
peacemakers
natural
leaders
Expected
Expected
Expected
321
Expected
Expected
Expected
CBA
Expected
Expected
Expected
333
CBA
!!!
iv.
iv.
iv.
222
28
27
26
25
24
23
22
21
20
Expected
Expected
Expected
Expected
Expected
Expected
Expected
Expected
Expected
have
diplomatic
skills
thinkers
carers and
providers
value
freedom
hard workers
creative and
optimistic
natural
peacemakers
natural
leaders
selfless and
generous
Expected
Expected
Expected
Expected
Expected
Expected
Expected
Expected
Expected
876543219
Expected
Expected
Expected
Expected
Expected
Expected
Expected
Expected
Expected
zyxwvutsr
Expected
Expected
Expected
Expected
Expected
Expected
Expected
Expected
Expected
333333333
zyxwvutsr! ! ! ! ! ! ! ! !
iii.
iii.
iii.
iii.
iii.
iii.
iii.
iii.
iii.
222222222
Actu
al
luck
y
nu
mb
er
mea
nin
g
ou
tpu
t
Ex
pecte
d
luck
y
nu
mb
er
mea
nin
g
ou
tpu
t
Actu
al
luck
y
nu
mb
er
ou
tpu
t
Ex
pecte
d
luck
y
nu
mb
er
ou
tpu
t
Actu
al
na
me
ou
tpu
t
Ex
pecte
d
na
me
ou
tpu
t
Use
r
inp
ut
Test
p
ass
ed
Actu
al
screen
tr
an
sit-
ion
ed
to
Ex
pecte
d
screen
tr
an
sit-
ion
ed
to
Sc
re
en
Test
ty
pe
(ref
er t
o §
1·
12
fo
r th
e m
ean
ing
of
thes
e v
alu
es)
Test
n
um
be
r
For
subm
issi
on i
n M
ay 2
017
By M
ark B
ishop
............................................................................................................................................................................................................................................................................................................................................................
............................................................................................................................................................................................................................................................................................................................................................
Tes
ting
26
of
33
46
45
44
Expected
Expected
Expected
selfless and
generous
have
diplomatic
skills
thinkers
Expected
Expected
Expected
987
Expected
Expected
Expected
RQP
Expected
Expected
Expected
333
RQP
!!!
iv.
iv.
iv.
222
43
42
41
40
39
Expected
Expected
Expected
Expected
Expected
carers and
providers
value
freedom
hard workers
creative and
optimistic
natural
peacemakers
Expected
Expected
Expected
Expected
Expected
65432
Expected
Expected
Expected
Expected
Expected
ONMLK
Expected
Expected
Expected
Expected
Expected
33333
ONMLK
!!!!!
iv.
iv.
iv.
iv.
iv.
22222
38
37
36
35
34
Expected
Expected
Expected
Expected
Expected
natural
leaders
selfless and
generous
have
diplomatic
skills
thinkers
carers and
providers
Expected
Expected
Expected
Expected
Expected
19876
Expected
Expected
Expected
Expected
Expected
JIHGF
Expected
Expected
Expected
Expected
Expected
33333
JIHGF
!!!!!
iv.
iv.
iv.
iv.
iv.
22222
Actu
al
luck
y
nu
mb
er
mea
nin
g
ou
tpu
t
Ex
pecte
d
luck
y
nu
mb
er
mea
nin
g
ou
tpu
t
Actu
al
luck
y
nu
mb
er
ou
tpu
t
Ex
pecte
d
luck
y
nu
mb
er
ou
tpu
t
Actu
al
na
me
ou
tpu
t
Ex
pecte
d
na
me
ou
tpu
t
Use
r
inp
ut
Test
p
ass
ed
Actu
al
screen
tr
an
sit-
ion
ed
to
Ex
pecte
d
screen
tr
an
sit-
ion
ed
to
Sc
re
en
Test
ty
pe
(ref
er t
o
§1
·12
fo
r th
e m
ean
ing
o
f th
ese
val
ues
)
Test
n
um
be
r
WJE
C G
CS
E C
om
pu
ter
Sci
ence
un
it 3
(“D
evel
op
ing
Co
mp
uti
ng
So
luti
on
s”)
con
tro
lled
ass
essm
ent
“Lu
cky
Nam
e N
um
ber
s”............................................................................................................................................................................................................................................................................................................................................................
............................................................................................................................................................................................................................................................................................................................................................
Tes
ting
27
of
33
60
Expected
natural
leaders
Expected
1Expected
DanielJackson
Expected
3DanielJackson
!v
iii.
2
59
58
Expected
Expected
natural
peacemakers
natural
leaders
Expected
Expected
21
Expected
Expected
CARTER
JACKSON
Expected
Expected
33
CARTER
JACKSON
!!
vii
.
vii
.
22
57
56
Expected
Expected
carers and
providers
selfless and
generous
Expected
Expected
69
Expected
Expected
sam
daniel
Expected
Expected
33
sam
daniel
!!
vi.
vi.
22
55
N/a
N/a
Expected
?!
Expected
4?!
!v
.2
54
53
52
Expected
Expected
Expected
have
diplomatic
skills
thinkers
carers and
providers
Expected
Expected
Expected
876
Expected
Expected
Expected
ZYX
Expected
Expected
Expected
333
ZYX
!!!
iv.
iv.
iv.
222
51
50
49
48
47
Expected
Expected
Expected
Expected
Expected
value
freedom
hard workers
creative and
optimistic
natural
peacemakers
natural
leaders
Expected
Expected
Expected
Expected
Expected
54321
Expected
Expected
Expected
Expected
Expected
WVUTS
Expected
Expected
Expected
Expected
Expected
33333
WVUTS
!!!!!
iv.
iv.
iv.
iv.
iv.
22222
Actu
al
luck
y
nu
mb
er
mea
nin
g
ou
tpu
t
Ex
pecte
d
luck
y
nu
mb
er
mea
nin
g
ou
tpu
t
Actu
al
luck
y
nu
mb
er
ou
tpu
t
Ex
pecte
d
luck
y
nu
mb
er
ou
tpu
t
Actu
al
na
me
ou
tpu
t
Ex
pecte
d
na
me
ou
tpu
t
Use
r
inp
ut
Test
p
ass
ed
Actu
al
screen
tr
an
sit-
ion
ed
to
Ex
pecte
d
screen
tr
an
sit-
ion
ed
to
Sc
re
en
Test
ty
pe
(ref
er t
o §
1·
12
fo
r th
e m
ean
ing
of
thes
e v
alu
es)
Test
n
um
be
r
For
subm
issi
on i
n M
ay 2
017
By M
ark B
ishop
............................................................................................................................................................................................................................................................................................................................................................
............................................................................................................................................................................................................................................................................................................................................................
Tes
ting
28
of
33
65
N/a
N/a
N/a
Expected
2!®
!x
i.6
64
N/a
N/a
N/a
Expected
2®
!x
.6
63
62
Expected
Expected
value
freedom
natural
peacemakers
Expected
Expected
52
Expected
Expected
Teal’c
Jack O’Neill
Expected
Expected
33
Teal’c
Jack O’Neill
!!
ix.
ix.
22
61
Expected
have
diplomatic
skills
Expected
8Expected
SamCarter
Expected
3SamCarter
!v
iii.
2
Actu
al
luck
y
nu
mb
er
mea
nin
g
ou
tpu
t
Ex
pecte
d
luck
y
nu
mb
er
mea
nin
g
ou
tpu
t
Actu
al
luck
y
nu
mb
er
ou
tpu
t
Ex
pecte
d
luck
y
nu
mb
er
ou
tpu
t
Actu
al
na
me
ou
tpu
t
Ex
pecte
d
na
me
ou
tpu
t
Use
r
inp
ut
Test
p
ass
ed
Actu
al
screen
tr
an
sit-
ion
ed
to
Ex
pecte
d
screen
tr
an
sit-
ion
ed
to
Sc
re
en
Test
ty
pe
(ref
er t
o
§1
·12
fo
r th
e m
ean
ing
o
f th
ese
val
ues
)
Test
n
um
be
r
WJE
C G
CS
E C
om
pu
ter
Sci
ence
un
it 3
(“D
evel
op
ing
Co
mp
uti
ng
So
luti
on
s”)
con
tro
lled
ass
essm
ent
“Lu
cky
Nam
e N
um
ber
s”............................................................................................................................................................................................................................................................................................................................................................
............................................................................................................................................................................................................................................................................................................................................................
Tes
ting
29
of
33
Evaluation
§4·1 The solution programmed by this author achieves all of the objectives of that solution, making possible the entry of a name by the user, and determining the lucky number – and the meaning of that lucky number – for the name entered by the user, with the functions for converting a name into a number (f_ConvertNameToNumber) and for summing together the digits of
a number (if that number is a multiple-digit number) to arrive at a single-digit number (f_SumDigits) passing all of the automated black-box unit tests (refer to §3·1 and §3·3,
respectively), and the complete program passing all of the manual tests (refer to §3·5).
However, in spite of the solution achieving all of the objectives of that solution, the solution could still be improved.
§4·2 Whilst the built-in “string” type provided by the Pascal programming language is limited to being at most
!
255 characters in length, on reflection the name entered by the user need not share that limitation – the Pascal programming language provides multiple ways in which the solution programmed by this author could be improved to support the user entering names more than
!
255 characters in length, including (but not limited to) using a linked list dynamic data structure wherein the name entered by the user is stored in one or more nodes, with each node
storing
!
1,255[ ] characters, as is illustrated by the following program.
1 program long_string_example( input, output );
2
3 const
4 k_MAXIMUM_NUMBER_OF_CHARACTERS_PER_STRING_LIST_NODE = 5; { Must be [ 1, 255 ]. }
5
6 type
7 t_StringListNodePointer = ^t_StringListNode;
8 t_StringListNode = record
9 m_pointerToNextNode : t_StringListNodePointer;
10 m_string : string
11 end;
12 t_StringList = record
13 m_pointerToFirstNode, m_pointerToLastNode : t_StringListNodePointer
14 end;
15
16 procedure p_CreateStringList( var list : t_StringList );
17 begin
18 list.m_pointerToFirstNode := nil
19 end;
20
21 procedure p_DestroyStringList( var list : t_StringList );
22
23 procedure p_DestroyStringList__private( var node : t_StringListNodePointer );
24 begin
25 if node^.m_pointerToNextNode <> nil then
26 p_DestroyStringList__private( node^.m_pointerToNextNode );
27 dispose( node )
28 end;
29
30 begin
31 if list.m_pointerToFirstNode <> nil then begin
32 p_DestroyStringList__private( list.m_pointerToFirstNode );
33 list.m_pointerToFirstNode := nil
34 end
35 end;
36
WJEC GCSE Computer Science unit 3 (“Developing Computing Solutions”) controlled assessment “Lucky Name Numbers”.................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Evaluation 31 of 33
37 procedure p_ReadLineIntoStringList( var list : t_StringList );
38 var
39 short_string : string;
40
41 procedure p_AddNodeToStringList__private;
42 var
43 node : t_StringListNodePointer;
44 begin
45 new( node );
46 node^.m_pointerToNextNode := nil;
47 node^.m_string := short_string;
48 if list.m_pointerToFirstNode = nil then
49 list.m_pointerToFirstNode := node
50 else
51 list.m_pointerToLastNode^.m_pointerToNextNode := node;
52 list.m_pointerToLastNode := node
53 end;
54
55 var
56 character : char;
57 begin
58 p_DestroyStringList( list );
59 short_string := '';
60 while not eoln do begin
61 read( character );
62 short_string := short_string + character;
63 if length( short_string ) = k_MAXIMUM_NUMBER_OF_CHARACTERS_PER_STRING_LIST_NODE
.. then begin
64 p_AddNodeToStringList__private;
65 short_string := ''
66 end
67 end;
68 if length( short_string ) >= 1 then
69 p_AddNodeToStringList__private;
70 readln
71 end;
72
73 procedure p_WriteStringList( list : t_StringList );
74 var
75 node : t_StringListNodePointer;
76 begin
77 node := list.m_pointerToFirstNode;
78 while node <> nil do begin
79 write( node^.m_string );
80 node := node^.m_pointerToNextNode
81 end
82 end;
83
84 var
85 name : t_StringList;
86 begin
87 writeln( 'Please enter a name and press the Return key – this program will then
.. write that name to the screen.' );
88 writeln;
89 write( 'Your input: ' );
90 p_CreateStringList( name );
91 p_ReadLineIntoStringList( name );
92 writeln;
93 write( 'You entered the name "' );
For submission in May 2017 By Mark Bishop.................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Evaluation 32 of 33
94 p_WriteStringList( name );
95 p_DestroyStringList( name );
96 writeln( '".' )
97 end.
§4·3 Whilst the user interface of the solution programmed by this author is usable, making possible the entry of a name by the user and outputting the lucky number – and the meaning of that lucky number – for the name entered by the user, the user interface may become cluttered after the solution has been used to determine the lucky number – and the meaning of the lucky number – for multiple names, as is illustrated by the following screenshot.
The solution could therefore be improved by replacing the existing textual user interface, which can become cluttered. with a graphical user interface, which cannot become cluttered, as is illustrated by the following mock-up.
WJEC GCSE Computer Science unit 3 (“Developing Computing Solutions”) controlled assessment “Lucky Name Numbers”.................................................................................................................................................................................................................................
.................................................................................................................................................................................................................................Evaluation 33 of 33