q1_sol - (i) the number of triangles, and (ii) the sum of...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Programming Fundamentals for CIS Majors II Quiz 1 : (Problem Solving – Algorithms and Pseudocode) 17th May 2010 SOLUTIONS (21-May-2010) A. Write an algorithm to solve each of the following problems: 1. To print the 8 times table from 1 x 8 to 15 x 8. 8TIMES-TABLE: Algorithm to print the 8 times table from 1 to 15. INPUT: None OUTPUT: The 8times table from 1x8 to 15x8. 1 for i 1 to 15 2 print “ i x 8= ” ( i * 8) 3 return done” 2. To input a number, square it and output the result if (the output is) less than 50. SQUARED-BELOW50: Algorithm to input a number, square it and output the result if less than 50. INPUT: Number n from user. OUTPUT: Squared value of n if less than 50. 1 n_square = n * n 2 if n_square < 50 3 print “ n 2 = “ n_square 4 else print “no value”
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
B. Problem-solving: Write pseudocode to solve the following problems: 1. Given a set of n red, blue and green shapes (triangles and rectangles only), count:
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: (i) the number of triangles, and (ii) the sum of the areas of all red rectangles. SOLUTION: // Pseudocode to perform calculations on geometric shapes 1. Input n red, blue, green shapes ( triangle and rectangle) 2. Initialize count=0 &lt;units&gt;, area=0 &lt;sq.units&gt; 3. For each shape 4. If shape is a le 5. count++ 6. Else if (shape is a le &amp;&amp; color = red) 7. area = ( l*b ) + area 8. return Number of triangles = count units. 9. return Total area of red rectangles = area sq. units. 2. Clear an oil spill (decide on your own input/ output parameters, strategies, etc.) [There are multiple ways to try to solve this problem. Ask BP! Your approach to the problem, strategies to break it into manageable steps, and the logical correctness of your pseudocode will be evaluated.]...
View Full Document

Page1 / 2

q1_sol - (i) the number of triangles, and (ii) the sum of...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online