Wednesday, 16 March 2016

Wednesday 17th mar 2016


(2) As part of an experiment, a school measured the heights (in metres) of all its 500 students.
Write an algorithm, using a flowchart, which inputs the heights of all 500 students and outputs the height of the tallest person and the shortest person in the school.

(3) A geography class decide to measure daily temperatures and hours of sunshine per day over a 12 month period (365 days)
Write an algorithm, using a flowchart, which inputs the temperatures and hours of sunshine for all 365 days, and finally outputs the average (mean) temperature for the year and the average (mean) number of hours per day over the year.

(4) A small shop sells 280 different items. Each item is identified by a 3 – digit code. All items that start with a zero (0) are cards, all items that start with a one (1) are sweets, all items that start with a two (2) are stationery and all items that start with a three (3) are toys.
Write an algorithm, using a flowchart, which inputs the 3 – digit code for

Pseudocode exercise questions

Add caption

Tuesday, 8 March 2016

Pseudocode Lecture (Wed 9th Mar'16)

QUESTION 1: 
A geography class decide to measure daily temperatures and hours of sunshine per day over a 12 month period (365 days)
Write an algorithm, using pseudocode, which inputs the temperatures and hours of sunshine for all 365 days, and finally outputs the average (mean) temperature for the year and the average (mean) number of hours per day over the year.

SOLUTION
1 sum_temp = 0: sum_hours = 0

2 for count = 1 to 365 do
3 input temp, hours
4 sum_temp = sum_temp + temp
5 sum_hours = sum_hours + hours
6 next

7 mean_temp = sum_temp/365
8 mean_hours = sum_hours/365
9 print mean_temp, mean_hours

QUESTION 2: 
As part of an experiment, a school measured the heights (in metres) of all its 500 students.
Write an algorithm, using pseudocode, which inputs the heights of all 500 students and outputs the height of the tallest person and the shortest person in the school.

SOLUTION
1 tallest = 0
2 shortest = 500

3 for count = 1 to 500 do
4 input height
5 if height > tallest then tallest = height
6 if height < smallest then smallest = height
7 next

8 print tallest, shortest