Pls 3 Solutions
Pls 3 Solutions
Note that there are multiple possible solutions to these activities. Those described here are
meant only to serve as a guide.
a)
PROGRAM OVERTIME
END
b)
c)
PROGRAM OVERTIME
d)
e)
PROGRAM TILES
1. GET width ;
2. GET length ;
3. SET area = width x length ;
4. IF area > 20
5. DISPLAY “Tile does not fit in box” ;
6. ELSE
7. DISPLAY “Tile fits in box” ;
8. ENDIF
END
a)
b)
PROGRAM NEEDLES
1. GET thickness ;
2. IF thickness > 5mm
3. Use 2mm needle ;
4. ELSEIF thickness > 3mm
5. Use 1.5mm needle ;
6. ELSE
7. Use 1mm needle ;
8. ENDIF
END
c)
d)
PROGRAM INSURANCE
END
3. Iteration Structures
a)
b)
This works
END
The logic:
1 + 2 + 3 + 4 + 5 = 15
The total at the start is zero. Because we have not yet added any numbers:
SET total = 0 ;
SET total = 0 ;
SET number = 1 ;
WHILE
ENDWHILE
Add the condition for the loop. We want the loop to iterate 5 times.
SET total = 0 ;
SET number = 1 ;
WHILE number < = 5
ENDWHILE
Each time the loop iterates we will add the next number to the total.
SET total = 0 ;
SET number = 1 ;
WHILE number < = 5
SET total = total + number ;
ENDWHILE
SET total = 0 ;
SET number = 1 ;
WHILE number < = 5
SET total = total + number ;
SET number = number + 1 ;
ENDWHILE
Finally, when all numbers have been added, we display the total.
SET total = 0 ;
SET number = 1 ;
WHILE number < = 5
SET total = total + number ;
SET number = number + 1 ;
ENDWHILE
DISPLAY total ;
The logic: