11 PROBLEM SOLVING AND ALGORITHM DEVELOPMENT (2)
Problem 3
Start A bus picks up passengers at several stops along its route Wnte
an algorithm to read the number of passengers picked up at each
stop, and add it to the total number of passengers. Calculate
the total number of passengers picked up in one day if the data
is teminated by the user entering a value of 999. Print the total
Set total number of
passengers to 0
number of passengerS.
Solution
Algorithm rough
Set the total number of passengers to 0
Enter number
of passengers Prompt and enter the number of passengers at the stop
at the stop
WHILE number of passengers at the stop is not equal to 999
DO
Total number of passengers = total number of passengers +
Enter nurTmber
of passengers number of passengers at the stop
at the stop
Prompt and enter the number of passengers at a stop
ENDWHLE
Total number of
Is ne No
nurnber of
passengers = total
Print "Total Number of Passengers"
number of passangers+|
passengers number of passengers
999 at the stop Algorithm refined
Yes
Total number of passengers =0
Prompt and enter the number of passengers
Print the total WHILE number of passengerS <> 999 DO
number of
passengers
Total number of passengers = total number of passengers
number of passengers
Prompt and enter the number of passengers
STOp ENDWHILE
Print "Total Number of Passengers"
Figure 11.8 Flowchart for Problem 3
Algorithm further refined
Total Passengers = 0
Prompt and Input number of passengers
WHILE number of passengers < 999 DO
gers
1otal passengers = total passengers+ nunber ot passeliye
Prompt and Input number of passengers
ENDWHILE
Print "Total Number of Passengers
192
WHILE-DO statemen=
Problem 4
Write an algorithm to enter the marks students obtained in English,
and count the number of students in a class. Calculate the average
English mark of the group of students if the data is terminated by
the value 999. Print the number of students in the class and the
average mark of the students.
Set the number of
students to 0
Solution
Algorithm rough
Set the number of students to 0
Set the total student Set the total students marks to 0
mark to O
Prompt and enter student mark
While the student mark is not equal to 999 DO
Add the student mark to total students mark
Enter student
mark
Add one to the total number of students
Prompt and enter next student mark
Enter student
ENDWHILE
mark
Find the average of the students mark by dividing the total
students mark by the total number of students
Print the number of students and the average mark of
Add 1 to total number
the students
of students
Algorithm refined
Total number of students = 0
Total students marks =0
VO
Add student mark to
student rnark
total students mark
Prompt and enter student mark
999
e5
While the student mark <> 999 do
Total students mark = total students mark + student mark
Calculate average
mark by dividing Total number of students = total number of students +1
total students mark
by total riumber of
students Prompt and enter student markk
ENDWHILE
Print total Average mark =total students mark/ total number of
nunber of
students
students,
average
Print number of students, average mark
Stop
igure 11.9 Flowchart for Problem 4