In preparation
for the examination candidates should attempt the following
practical tasks by writing and testing a program or programs.
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.
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.
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.
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.
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.
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.
Practice Questions
1 When you performed the tasks, you used variables.
Write suitable declarations for two of these.
State what you used each one for.
Variable 1:
CowHerd
Datatype:
Integer
Use: To input no. of cows in the herd
Variable 2:
MostYield
Datatype:
Integer
Use: To store the weekly yield
of the cow that has produced the most
milk
2 When you performed the tasks,
you may have used arrays. Write suitable
declarations
for
any two of these.
State what you used each one for.
Declaration of Array1:
Dim IdentityCode(CowHerd) As Integer
Use: To store the Identity Code of
each cow
in the herd Declaration of Array2:
Dim TotalCowYield(7) As Integer Use: To store the total milk yield of each cow
per
week
3 Write an algorithm
to complete
Task 1, using either
pseudocode,
programming statements
or a flowchart.
Dim CowHerd As Integer
Input "Enter
No. of Cows in the Herd", CowHerd
Dim IdentityCode(CowHerd) As Integer
Dim Yield1(7), Yield2(7) As Single
For c = 1 To CowHerd
Do
Input "Enter Three Digit Cow
Code:", IdentityCode (c)
If IdentityCode (c) < 100 Or
IdentityCode (c) > 999 Then
Print("Invalid Code!
Re-Enter")
End If
Loop Until IdentityCode (c) >= 100 And IdentityCode (c) <= 999
For d = 1 To 7
Input "Enter Milk Yield for
Session 1:", Yield1(d)
Yield1(d) = Math.Round(Yield1(d),
1)
Input "Enter Milk Yield for
Session 2:", Yield2(d)
Yield2(d) = Math.Round(Yield2(d),
1)
Next
Next
4 Write an
algorithm to complete
Task 2, using either pseudocode, programming statements or a
flowchart.
Dim CowHerd As Integer
Dim TotalWeeklyVolume As Single
TotalWeeklyVolume = 0
Input "Enter
No. of Cows in the Herd", CowHerd
Dim IdentityCode (CowHerd) As Integer
Dim Yield1(7), Yield2(7) As Single
Dim TotalCowYield(CowHerd), Average(CowHerd), Yield(7) As Single
For c = 1 To CowHerd
Total(c) = 0
Do
Input "Enter Three Digit Cow Code:", IdentityCode (c)
If IdentityCode (c) < 100 Or IdentityCode (c) > 999 Then
Print "Invalid Code! Re-Enter")
End If
Loop Until IdentityCode (c) >= 100 And IdentityCode (c) <= 999
For d = 1 To 7
Input "Enter Milk Yield for Session 1:",
Yield1(d)
Input "Enter
Milk Yield for Session 2:", Yield2(d)
TotalCowYield (c) = TotalCowYield(c) + Yield1(d) + Yield2(d) TotaLWeeklyVolume = TotaLWeeklyVolume + TotalCowYield(c)
Next
Average(c) = TotalCowYield(c) / 14
Print "Total Milk Yield for Cow per week is : ", Math.Round(TotalCowYield(c))
Print "Average Milk Yield for Cow per week is: ", Math.Round(Average(c))
Next
Print
"Total weekly volume per week is: "
, Math.Round(TotalWeeklyVolume)
5 Write an algorithm
to complete
Task 3, using either pseudocode, programming statements or a flowchart. You should assume that Task 1 & Task 2 has been already
completed.
Dim MostID, Count As Integer
Dim MostYield As Single
Dim Yield(7) As Single
MostYield = 0
Count = 0
For c = 1 To CowHerd
For d = 1 To 7
Yield(d) = Yield1(d) + Yield2(d) If Yield(d) < 12 Then
Count = Count + 1
End If
Next
If Count >= 4 Then
Print "Cow with less than 12 litres of milk for four or more days ", IdentityCode(c)
End If
If MostYield <= TotalCowYield(c) Then
MostID = IdentityCode(c)
MostYield = TotalCowYield(c)
Print("Cow
that produced most milk in the week ", MostID ,
" the yield is ", MostYield
End If
Next
6 Explain how you performed validation of identity code input in Task 1. You
can
include pseudocode or programming statements
as part of your explanations.
Identity
code in Task 1 is validated using Do - Loop Until. The Identity
code
will be re- input if it is not in the range that is from 100 to 999. To print the error message IF-Then- Else-End If is used. Error message will be displayed if number is less than 100 or greater
than 999. Following program code describes the working of validation:
Do
Input "Enter Three Digit Cow Code:", IdentityCode(c)
If IdentityCode (c) < 100 Or IdentityCode (c) > 999 Then
Console.WriteLine("Invalid Code! Re-Enter")
End If
Loop Until IdentityCode (c) >= 100 And IdentityCode (c) <= 999
7 Explain how your program calculates the total yield
of the herd. You can include
pseudocode or programming statements as part
of your explanation.
Two arrays named as Yield1 and Yield2 are
used to store the milk yield twice a day. Another array named as TotalCowYield will keep the sum of milk yield produced per day. Initialize
the TotalCowYield array with
zero.
TotalCowYield(c) = TotalCowYield(c) + Yield1(d) + Yield2(d) is used to sum milk yield
per day. Then this TotalCowYield value
is summed up to the TotalWeeklyVolume using the statement i.e.
TotalWeeklyVolume = TotalWeeklyVolume + TotalCowYield(c).
8 Explain
how
your program
calculate average
yield
to
the
nearest whole
number. You can include
pseudocode, programming statements
as part of your explanation.
Total yield produced by each cow in whole week is summed up
in an array named as
TotalCowYield(c). Divide
each index of TotalCowYield(c) array with the number 14 to calculate the
average yield
per cow i.e. Average(c) = Math.Round(TotalCowYield(c)
/ 14) To display the average yield to the nearest whole number Math.Round function is used i.e.
Print "Average Yield for Cow per week is: ", Math.Round(Average(c))
9 Comment on the efficiency
of your design for Task 2.
Arrays are
used to store the milk yield for each cow and two loops are used to take milk yield of
each cow. External loop is used for
each cow and internal loop is used for milk yield of seven days.
10 Comment on the efficiency of
your design for Task 3.
The cow that has produced the most milk and less than 12 liters of milk for four
days or more
in the week are saved
in a variable instead of an
array.
This will save the memory consumption and
results will be displayed on
the spot.
11 Give a set of “Identity Code” data that could be used to check your rules in Task
1. Explain why
you
chose this data set.
Set 1 200
Reason To test
normal data
Set 2 1283
Reason To test
extreme
data
Set 3 One
Reason To test
abnormal data