<p> Question Sheet 1 – A Solution</p><p>Q1. {Algorithm to count #a and #e in text input} READ character</p><p> number_a 0 number_e 0</p><p>WHILE ( character != ‘z’ )</p><p>IF ( character = ‘a’ ) THEN number_a number_a + 1 ENDIF</p><p>IF ( character = ‘e’ ) THEN number_e number_e + 1 ENDIF</p><p>READ character</p><p>ENDWHILE</p><p>PRINT “Number of a = “, number_a PRINT “Number of e = “, number_e Q2. {Algorithm to write out numbers in expanded form} PRINT “Input a number” READ number</p><p>WHILE ( number != 0 )</p><p>FOR ( duplicate FROM 1 TO number ) PRINT number ENDFOR</p><p>PRINT “Input another number” READ number</p><p>ENDWHILE</p><p>Q3.</p><p> number total value PRINT - - - READ 5 - - 5 1 - FOR 5 1 1 5 1 1 FOR 5 1 2 5 2 2 FOR 5 2 3 5 6 3 FOR 5 6 4 5 24 4 FOR 5 24 5 5 120 5 PRINT 5 120 6 1. Factorial 2. Result would always be 0 otherwise 3. Set iteration counter to 2 and not 1. Multiply by 1 is redundant.</p><p>Q4.</p><p>(a) Module Name: calculate_volume_hemisphere Inputs: radius Outputs: hemisphere_volume Process:</p><p>{Calculate volume of a hemisphere using the radius}</p><p> hemisphere_volume ( 2 * PI * radius3 ) / 3 RETURN hemisphere_volume</p><p>(b) Module Name: calculate_volume_cone Inputs: radius, height Outputs: cone_volume Process:</p><p>{Calculate volume of a cone using the radius and height} cone_volume ( PI * radius2 * height ) / 3 RETURN cone_volume</p><p>Q3. (c)</p><p>{ Algorithm to calculate ice-cream cone volumes }</p><p>PRINT “Enter radius and height” READ radius, height</p><p>WHILE ( radius != 0 OR height != 0 ) total_volume calculate_volume_hemisphere(radius) + calculate_volume_cone(radius,height) PRINT “Total Volume of Ice Cream is “, total_volume</p><p>PRINT “Enter another radius and height” READ radius, height </p><p>ENDWHILE</p>
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages4 Page
-
File Size-