1. Sir Zahid Ali Bhatti
00971568047507
00923242415561
COMPUTER SCIENCE
PRE-RELEASE MATERIAL MAY / JUNE 2018
O LEVEL - COMPUTER SCIENCE 2210
IGCSE - COMPUTER SCIENCE 0478
2. Sir Zahid Ali Bhatti
00971568047507
00923242415561
PRE-RELEASE MATERIAL JUNE 2018
A farmer records the milk production of a herd of cows. Every cow has a unique 3-
digit identity code. Each cow can be milked twice a day, seven days a week. The
volume of milk from each cow is recorded in litres correct to one decimal place (yield)
every time the cow is milked. The size of the herd is fixed. At the end of the week the
total and the average yield for each cow for that week is calculated.
The farmer identifies the cow that has produced the most milk that week. The farmer
also identifies any cows that have produced less than 12 litres of milk on four or
more days that week.
3. Sir Zahid Ali Bhatti
00971568047507
00923242415561
PRE-RELEASE MATERIAL JUNE 2018
A program is required to record the yield for each cow every time it is milked.
Calculate the total weekly volume of milk for the herd and the average yield per cow
in a week. The program must also identify the cow with the best yield that week and
identify any cows with a yield of less than 12 litres of milk for four or more days that
week.
4. Sir Zahid Ali Bhatti
00971568047507
00923242415561
PRE-RELEASE MATERIAL JUNE 2018
Write and test a program or programs for the farmer.
• Your program or programs must include appropriate prompts for the entry of data.
• Error messages and other output need to be set out clearly and understandably.
• All variables, constants and other identifiers must have meaningful names.
You will need to complete these three tasks. Each task must be fully tested.
5. Sir Zahid Ali Bhatti
00971568047507
00923242415561
PRE-RELEASE MATERIAL JUNE 2018
TASK 1 - Record the yield.
Write a program for TASK 1 to record the milk yields for a week. The program records
and stores the identity code number and the yield every time a cow is milked.
6. Sir Zahid Ali Bhatti
00971568047507
00923242415561
PRE-RELEASE MATERIAL JUNE 2018
TASK 2 - Calculate the statistics.
Using your recorded data from TASK 1, calculate and display the total weekly volume
of milk for the herd to the nearest whole litre. Calculate and display the average yield
per cow in a week to the nearest whole litre.
7. Sir Zahid Ali Bhatti
00971568047507
00923242415561
PRE-RELEASE MATERIAL JUNE 2018
TASK 3 - Identify the most productive cow and cows that are producing a low volume
of milk.
Extend TASK 2 to identify and display the identity code number and weekly yield of
the cow that has produced the most milk. Also identify and display the identity code
numbers of any cows with a yield of less than 12 litres of milk for four days or more
in the week.
8. Sir Zahid Ali Bhatti
00971568047507
00923242415561
TASK 1 - SOLUTION
Task 1
Input “type the number of cows in your herd…: “, Cherd
Dim cowid (cherd)
Dim cowyield (cherd)
Dim lessmilk (cherd)
Dim tmilk, havg
Dim maxcid, mincid
Dim Min, Max
Finding the herd size and
Variable declaration
9. Sir Zahid Ali Bhatti
00971568047507
00923242415561
TASK 1 – SOLUTION CONTINUE
For a=1 to cherd
Input “ type the cow ID ..: “, cowid(a)
While cowid(a)<100 or cowid(a) >999
Input “Wrong cow id, please type the correct cow ID ... : “, cowid(a)
End while
for d=1 to a
While cowid(a)=cowid(d)
Input “Duplicate cow id, please type the correct cow ID ... : “, cowid(a)
End while
next d
cowyield (a) = 0 ; lessmilk (a)=0
Next c
Validating and recording
unique Cow ID, and
variables initialization.
10. Sir Zahid Ali Bhatti
00971568047507
00923242415561
TASK 1 – SOLUTION CONTINUE
For d=1 to 7
Print “ Milk Yield for the Day “, d
For a=1 to cherd
Print “Milk Yield Details of Cow ID ”, cowid(a)
Input “Type the milk yield (litres) for session 1..: “,
s1
Input “Type the milk yield (litres) for session 2..: “,
s2
cowyield (a) = round(cowyield (a) + s1 + s2,1)
if s1+s2<12 then
lessmilk(a)=lessmilk(a)+1
End if
Next a
Next d
This is the part work of task 3,
I did it here because, in this
task we are recording the milk
production of this herd of
cows
Recording the milk yield twice
a day, seven days a week,
correct to one decimal place.
11. Sir Zahid Ali Bhatti
00971568047507
00923242415561
TASK II - SOLUTION
Tmilk=0
For a=1 to cherd
tmilk=round(tmilk+cowyield(a),0)
next a
havg=round(tmilk/cherd,1)
print “Total weekly volume of milk: “, tmilk
print “Average weekly volume of milk: “, havg
for a=1 to cherd
print “Cow ID: “, cowed(a), “ Total Yield: “, cowyield(a), “ Average Yield per Week: “, round(cowyield(a)/7,
1)
next a
Calculating and displaying,
the average & total weekly
volume of milk, nearest to the
whole litre
Calculate and displaying the
average yield per cow in a week,
correct to one decimal place.
12. Sir Zahid Ali Bhatti
00971568047507
00923242415561
TASK III – SOLUTION
maxcid=0
mincid=0
min=9999
max=0
For a=1 to cherd
If cowyield(a) > max then
Max=cowyield(a) ; Maxcid=cowed(a)
End if
If cowyield(a)<min then
Min=cowyield(a) ; Mincid=cowed(a)
End if
Next a
Print “Cow ID: “, maxcid, “ has produced most milk “, max
Print “Cow ID: “, mincid, “ has produced least milk “, min
Identifying the
most productive
cow
Identifying the
least productive
cow
13. Sir Zahid Ali Bhatti
00971568047507
00923242415561
EXTENDED TASK II – SOLUTION CONTINUE
for a=1 to cherd
if leemilk(a)=> 4 then
print “Cow ID: “, cowid(a), “ has produced less than 12 litters of milk for “, lessmilk(a), “days in a week”
next a
identifying and displaying the cow
with a yield of less than 12 litres,
Part working of this task was
done with task 1