{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

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”

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

View Full Document
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:
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 <units>, □ area=0 <sq.units> 3. For each shape 4. If shape is a ∆ le 5. ∆ count++ 6. Else if (shape is a □ le && 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

{[ snackBarMessage ]}

### Page1 / 2

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

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

View Full Document
Ask a homework question - tutors are online