0% found this document useful (0 votes)
78 views7 pages

Answers To End of Chapter 7 Activities and Questions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views7 pages

Answers To End of Chapter 7 Activities and Questions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

NPS International School

lTask 2 - Topic: Algorithm design and problem solving


Name: _______ Subject:

Date: ________ Grade: 10 IGCSE

Practice question – 1:

a. The following pseudocode algorithm should:


• input up to 20 numbers
• stop if the sum of the input numbers exceeds 50
• output the final sum
10 count = 0
20 REPEAT
30 INPUT n
40 n + sum = sum
50 IF sum = 50 THEN count = 20
60 count = count + 1
70 UNTIL count = 20
80 OUTPUT n
There are five errors in this algorithm.
Locate these errors and suggest a correction.
NPS International School

b.The following section of a pseudocode algorithm should:


• input 500 numbers
• generate a ratio called k
• output each value of k
• output how many numbers were larger than 10
10 total = 1
20 FOR x = 1 TO 500
30 IF number < 10 THEN total = total + 1
40 k = x / number
50 x = x + 1
60 OUTPUT k
70 NEXT x
80 OUTPUT x

Practice question – 2:

a. A School has 3000 students sitting final examinations.


Each student sits eight examinations.
Write an algorithm, using pseudocode or a flowchart,
which:
 Input the marks for all 8 examinations for each student
 Outputs for each student the average mark for their 8
examinations
 Outputs the highest mark overall.
NPS International School

highest = 0

for student = 1 to 3000

total = 0

for exam = 1 to 8

input mark

total = total + mark

if mark > highest then

highest = mark

next exam

average = total/8

output average

next student

output highest

b. A group of students were monitoring the temperature


every day over a one-year period.
Readings were taken ten times every day (you may
assume a year contains 365 days).

Write an algorithm, using pseudocode or flowchart, which


 inputs all the temperatures (ten per day)
 outputs the highest temperature taken over the year
 outputs the lowest temperature taken over the year
 outputs the average temperature per day
 outputs the average temperature for the whole year

highest = -100
lowest = 100
total_year = 0
for c = 1 to 365
total_day = 0
NPS International School

for d = 1 to 10
input temp
total_day = total_day + temp
total_year = total_year + temp
if temp > highest then
highest = temp
if temp < lowest then
lowest = temp
next d
average_day = total_day/10
print average_day
next c
average_year = total_year/3650
print highest, lowest, average_year

c. A customer wants to compare prices of 1000 items sold in


two supermarkets (price1 and price 2).

Write an algorithm, using pseudocode or a flowchart,


which:

 inputs the two prices for all 1000 items


 outputs how many items were more expensive in
supermarket 1
 outputs how many items were more expensive in
supermarket 2
 outputs the largest price difference

smarket1 = 0: smarket2 = 0

for item = 1 to 1000

input price1, price2

if price1 > price2 then

smarket1 = smarket1 + 1

if price2 > price1 then


NPS International School

smarket2 = smarket2 + 1

difference = price1 – price2

if difference < 0 then

difference = - difference

if difference > largest then

largest = difference

next item

output smarket1, smarket2, largest

Practice question – 3:

a. There is a program that stores the following data:


 StudentID, a student ID which must be two letters followed
by 4 numbers, e.g. NP4578
 Gender, the Student Gender which can be M or F only
 Graduated, whether the student is graduated or not
 Examination result (%),which can be any number from 0 to
100
Complete the following table to identify:

 The most appropriate data type for each variable


 An appropriate validation check for each variable. You
must use a different validation check for each variable.
NPS International School

Practice question – 4:

Write an algorithm, using pseudocode or a program flowchart


only, which: • inputs the population and land area for 500
countries,

• calculates the population density (i.e. population/land area)


for every country,

• outputs the largest and smallest population density,

• outputs the average population for all 500 countries.


smallest = 10000: largest = 0: total = 0

for country = 1 to 500

input population, area

density = population/area

if density > largest then largest = density

if density < smallest then smallest = density

total = total + population

next country

average = total/500 print largest, smallest, average

Repeat..Until& WHILE

correct loop ( repeat .... until n = 500, while n <> 500 do ....)
NPS International School

You might also like