Topic_4-_Home_Assignment-_FA2
Topic_4-_Home_Assignment-_FA2
K=5
A=1
B=0
while K >= 0
if DATA[K] mod 2 < 1
then
A = A * DATA[K]
else
B=B+1
end if
K=K-1
end while
output(A)
output(B)
[2]
2. There are 1000 rooms where students can live on a college campus. The rooms are numbered
from 1 to 1000. The bill for each room must be paid each month.
The room numbers of the students who have paid their bills for the month of May so far are
stored in the ROOMNUMS array (see Figure 1).
For example, the bill for room number 93 has been paid. This can be seen in ROOMNUMS[6].
[5]
[6]
2, 4, 1, −2, −4, 1, 0
COUNTER = 0
SUM = 0
DATA.resetNext()
loop for X from 0 to 6
if DATA.getNext() > 0
ARRAY[X] = DATA.getNext()
COUNTER = COUNTER + 1
SUM = SUM + ARRAY[X]
end if
end loop
output SUM/COUNTER
[4]
A transport authority is investigating how many people use a certain direct train route, which is
used every day of the week.
At the end of each day, the total number of passengers who travelled on this route is stored in a
collection, PASSENGERS.
The first item was written to the collection on Monday 1st January 2018.
The next items, collected on Tuesday and Wednesday, were added like this:
(b) Assuming that the first item read from the collection is from Monday 1st January 2018,
construct pseudocode that will read PASSENGERS into an array, P_ARRAY.
[4]
(c) Using P_ARRAY, construct pseudocode to output the day of the week with the highest
average number of passengers. Use the sub procedure convert() which converts the
numbers 0 to 6 into days of the week, for example convert(1) will return “Tuesday”.
Note: you should not assume that data for an exact number of weeks is stored.
[7]