Year10 CS – Answers Pseudocode Practice questions.
CW: Class work
PW: Practice work
Ask the following questions for any pseudocode question
Do you need a loop
o If yes then decide the count value
What are the input required?
What are the calculations needed?
o How is calculations to be done
What are the outputs?
CW
1. count=500
largest=0
smallest=999
totalpop=0
While count<>0 do
Input population, landarea
count=count-1
populationdensity=population/landarea
if populationdensity>largest then largest=populationdensity
if populationdensity<smallest then smallest=populationdensity
totalpop=totalpop+population
endwhile
print largest, smallest
average=totalpop/500
print average
2. count=500
largest=0
smallest=999
totalFS=0
While count<>0 do
Input time
count=count-1
finalspeed=200/time
if finalspeed>largest then largest=finalspeed
if finalspeed<smallest then smallest=finalspeed
totalFS=totalFS+finalspeed
print finalspeed
endwhile
print largest, smallest
average=totalFS/500
print average
3. count=1000
totalhts=0
totalwts=0
while count<>0 do
input ht, wt
if ht>2 and ht<0 then print “error in height”
else if wt>130 and wt<0 then print “error in weight”
else
count=count-1
totalhts=totalhts+ht
totalwts=totalwts+wt
endif
endif
endwhile
avght=totalhts/1000
avgwt=totalwts/1000
print avght, avgwt
4. Total=0
largest=0
Input number
Count=0
While number<>-1 do
Total=Total+number
If number>largest then largest=number
Input number
Count=Count+1
Endwhile
Average=Total/Count
Print average, largest
5. Count=3650
Total=0
best=0
worst=999
Occasions=0
While count<>0 do
Input exchangerate
Count=Count-1
Total=Total+exchangerate
If exchangerate>best then best=exchangerate
If exchangerate<worst then worst=exchangerate
If exchangerate>2 then Occasions=Occasions+1
Endwhile
Average=Total/3650
Print Average, best, worst, Occasions
CW
6. lessTh=0
moreTh=0
Input number
While number<>-1 do
If number<1000 then lessTh=lessTh+1
If number>1000 then moreTh=moreTh+1
Input number
Endwhile
Print lessTh, moreTh
7. Count=365
Cloudy=0
Raining=0
Sunny=0
Foggy=0
Highest=0
Lowest=999
While count<>0 do
Input weathertype, temp
Count=Count-1
If weathertype=”Cloudy” then Cloudy=Cloudy+1
Else If weathertype=”Raining” then Raining=Raining+1
Else If weathertype=”Sunny” then Sunny=Sunny+1
Else If weathertype=”Foggy” then Foggy=Foggy+1
If temp>Highest then Highest=temp
If temp<Lowest then Lowest=temp
Endwhile
Print Cloudy, Raining, Sunny, Foggy, Highest, Lowest
8. Count=1000
Whole=0
While Count<>0 Do
Input number
Count=Count-1
Y=INT(number)
If number=Y then Whole=Whole+1
Endwhile
Print Whole
9. Input number
Count=0
Divnum=number
While Divnum<>0 Do
Divnum=Divnum/10
Count=count+1
Endwhile
Print Count, number
10. Count=50
Palcnt=0
While Count<>0 Do
Input D1, D2, D3, D4
Count=Count-1
If D1=D4 AND D2=D3 then Palcnt=Palcnt+1
Endwhile
PercentagePal=Palcnt*2
Print PercentagePal
11. x = 0: tbun = 0: tcoffee = 0: tcake = 0: tsand = 0: tdessert =0
input item
while item<>”end” Do
if item = “bun” then tbun = tbun + 0.5
else if item = “coffee” then tcoffee = tcoffee + 1.20
else if item = “cake” then tcake = tcake + 1.50
else if item = “sandwich” then tsand = tsand + 2.10
else if item = “dessert” then tdessert = tdessert + 4.00
else print “error”
input item
endwhile
if tbun > x then x = tbun
if tcoffee > x then x = tcoffee
if tcake > x then x = tcake
if tsand > x then x = tsand
if tdessert > x then x = tdessert
total = tbun + tcoffee + tcake + tsand + tdessert
print total, x