.nr PS 11 .ps 11 .nr VS 13 .vs 13 .SH .ce EXAMPLE PROGRAM LOWER TO UPPER CASE CONVERSION REPORT .NH Requirements .LP To produce a program that converts lower case alphabetic characters to upper case alphabetic characters. Note that lower case letters a..z have ASCII codes 97..122, and upper case letters A..Z have ASCII codes 65..90. Therefore to convert from lower case to upper case we must subtract -32 from the ASCII code of the input character. The ASCII character code of 96 is equivalent to the symbol '`', and a code 123 to the symbol `{'. .NH Design .LP A top down analysis is presented in Table 1. .PS a = b = c = d = e = 4.5/3 0.5 0.5/2 0.5 d/2 M:box invis wid B1:box wid a ht B2:box wid a ht B3:box wid a ht B4:box wid a ht line from B1.s line from B3.n line from B1.s .PE .ce .ps 15 \fBTable 1:\fI 5 b b b b ht b+d+b with .n at M.n "Lower case to""upper case""conversion" with .sw at M.sw "Input a""character" with .s at M.s "Convert to""upper case" with .se at M.se "Output upper""case character" to B1.s -(0,e) to B2.n +(0,e) to B2.n to B3.n +(0,e) -(0,e) to B4.n +(0,e) to B4.n Top down analysis\fR .LP A single procedure: .IP 1) 3 \fCLOWER_2_UPPER\fR (top level procedure) input lower case character, convert, output upper case character. .TS center,box,tab($); l | l | l | l. NAME$DESCRIPTION$TYPE$VALUE/RANGE = LOW_CASE_LETTER$Input variable$LOWER_CASE$'a'..'z' ASCII_CODE$Global variable$INTEGER$Default .TE where \fCLOWER_CASE\fR is a subtype of the type \fCCHARACTER\fR. .LP An appropriate Nassi-Shneiderman design is presented in Table 2. .PS a = b = c = d = 0.5 0.3 2 1.8 M:box invis wid 6 ht (b*3) box wid c ht b with .n at M.n "Input lower case character" box wid c ht b with .n at last box.s "conversion" box wid c ht b with .n at last box.s "Output upper case character" .PE .ce .ps 15 \fBTable 2:\fI Nassi-Shneiderman Chart\fR .NH Implementation .LP Implementation is as shown in Table 3: .ft CW .ps 10 .vs 11 .TS center,box; l. ----- LOWER TO UPPER CASE CONVERSION 6 August 1997 Frans Coenen Dept Computer Science, University of Liverpool with TEXT_IO; use TEXT_IO; procedure LOWER_2_UPPER is subtype LOWER_CASE is CHARACTER range 'a'..'z'; LOW_CASE_LETTER: LOWER_CASE; ASCII_CODE: INTEGER; begin -- Input lower case character PUT_LINE("Input lower case character: "); GET(LOW_CASE_LETTER); -- Conversion ASCII_CODE := CHARACTER'POS(LOW_CASE_LETTER)-32; -- Output upper case value PUT("The equivalent in upper case is: "); PUT(CHARACTER'VAL(ASCII_CODE)); NEW_LINE; end LOWER_2_UPPER; .TE .ce .ps 15 \fBTable 3:\fI Implementation\fR .NH Testing .LP A set of BVA and limit test cases is given in Table 4 (results presented in Table 5). These test cases will also serve to test the arithmetic operation of the code with the inclusion of a sample input value near the middle of the prescribed range (e.g. \fC'm'\fR). We should also carry out some random data validation testing (Table 6). .ft CW .TS center,box,tab($); c || c l || l. TEST CASE$EXPECTED RESULT _ LOW_CASE_LETTER$Output = '`'$CONSTRAINT_ERROR 'a'$'A' 'b'$'B' 'm'$'M' 'y'$'Y' 'z'$'Z' '{'$CONSTRAINT_ERROR .TE .ce .ps 15 \fBTable 4:\fI BVA, limit and arithmetic test cases\fR .ft CW .ps 10 .vs 11 .TS center,box; l. kuban-331 $ lower_2_upper Input lower case character: ' Ada-runtime: Exception CONSTRAINT_ERROR raised in /tmp_mnt/home/staff2/ ra/frans/public_html/2CS21/week4/lower_2_upper.ada on line 12. Rangecheck error: 96 not in range 97..122. kuban-332 $ lower_2_upper Input lower case character: a The equivalent in upper case is: A kuban-333 $ lower_2_upper Input lower case character: b The equivalent in upper case is: B kuban-334 $ lower_2_upper Input lower case character: y The equivalent in upper case is: Y kuban-335 $ lower_2_upper Input lower case character: z The equivalent in upper case is: Z kuban-336 $ lower_2_upper Input lower case character: { Ada-runtime: Exception CONSTRAINT_ERROR raised in /tmp_mnt/home/staff2/ ra/frans/public_html/2CS21/week4/lower_2_upper.ada on line 12. Rangecheck error: 123 not in range 97..122. .TE .ce .ps 15 \fBTable 5:\fI BVA, limit and arithmetic test output\fR .ft CW .ps 10 .vs 11 .TS center,box; l. kuban-214 $ lower_2_upper Input lower case character: frans The equivalent in upper case is: F kuban-215 $ rans ksh: rans: not found .TE .ce .ps 15 \fBTable 6:\fI Data validation tests\fR