.nr PS 11 .ps 11 .nr VS 13 .vs 13 .SH .ce EXAMPLE PROGRAM CIRCLE CALCULATION REPORT .NH Requirements .LP To produce a program that calculates the circumference and area of a circle given its radius. Assume "PI" is equivalent to 3.14 and that the radius is input by the user as a floating point number. Area of a circle = PI \(mu diameter = 2 \(mu PI \(mu radius and Volume = PI \(mu radius^2. .NH Design .LP A top down analysis is presented in Table 1. .PS a = b = c = d = e = .vs 4.5/3 0.5 0.5/2 0.5 d/2 12 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 .LP .ce .ps 15 \fBTable 1:\fI 6 b b b b ht b+d+b with .n at M.n "Circle""calculation" with .sw at M.sw +(0.5,0) "Input data" with .s at M.s "Calculate and""output""circumference" with .se at M.se -(0.5,0) "Calculate and""output area" 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 These operations are simple enough to be wrapped up into a single procedure: .IP 1) 3 \fCCIRCLE_CALC\fR (top level procedure): Input radius, and calculate and output circumference and area. Uses the following two data items. .TS box,center,tab($); c | c | c | c l | l | l | l. NAME$DESCRIPTION$TYPE$VALUE/RANGE = PI$Global constant$FLOAT$3.14 RADIUS$Global input variable$FLOAT$Default .TE .LP The detailed design for this procedure is given by the Nassi-Shneiderman chart presented in Table 2. .PS a = 3 b = 0.3 M:box invis wid 6 ht b*3 box wid a ht b with .n at M.n "Input RADIUS" box wid a ht b with .n at last box.s "Calculate and output circumference " box wid a ht b with .n at last box.s "Calculate and output area" .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. ----- CIRCLE CALCULATION 15 August 1997 Frans Coenen Dept Computer Science, University of Liverpool with CS_IO; use CS_IO; procedure CIRCLE_CALC is PI: constant FLOAT := 3.14; RADIUS: FLOAT; begin PUT_LINE("Input radius: "); GET(RADIUS); -- Calculate circumference using 2xPIxRadius PUT("The circumference is: "); put(2.0*PI*RADIUS,FORE => 3,AFT=>4,EXP =>0); NEW_LINE; -- Calculate area using PIxRadius^2 PUT("The area is: "); put(PI*RADIUS*RADIUS,FORE => 3,AFT=>4,EXP =>0); NEW_LINE; end CIRCLE_CALC; .TE .ce .ps 15 \fBTable 3:\fI Implementation\fR .NH Testing .LP \fBArithmetic testing|fR: Test using positive, negative and zero input values for \fCRadius\fR as shown in Table 4. .ft CW .TS center,box,tab($); c || c s l || l | l. TEST CASE$EXPECTED RESULT _ RADIUS$CIRCUMFERENCE$AREA = 10.0$62.8000$314.0000 0.0$0.0000$0.0000 -10.0$-62.8000$314.0000 .TE .ce .ps 15 \fBTable 4:\fI Test cases\fR .LP Note negative circumference? A screen dump illustrating the output produced as a result of running the above test cases is given in Table 5. .ft CW .ps 10 .vs 11 .TS center,box; l. kuban-349 $ circle_calc Input radius: 10.0 The circumference is: The area is: 314.0000 62.8000 kuban-350 $ circle_calc Input radius: 0.0 The circumference is: 0.0000 The area is: 0.0000 kuban-351 $ circle_calc Input radius: -10.0 The circumference is: -62.8000 The area is: 314.0000 .TE .ce .ps 15 \fBTable 5:\fI Arithmetic test output\fR .LP \fBData validation testing\fR: Test input with wrong type and too many inputs. Result shown in Table 6. .ft CW .ps 10 .vs 11 .TS center,box; l. kuban-289 $ circle_calc Input radius: x Ada-runtime: Exception FLOAT_INPUT_ERROR_DIGIT_NOT_READ propagated out of main. kuban-290 $ circle_calc Input radius: 5.0 10.0 The circumference is: 31.4000 The area is: 78.5000 kuban-291 $ 10.0 ksh: 10.0: not found .TE .ce .ps 15 \fBTable 6:\fI Data validation test output\fR