Pre release Material 2018
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 the milk from each cow is recorded in liters 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 the 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 liters 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 cow with a yield of less than 12 liters of milk for four or more days that week.
Write and test a program or programs for the farmer.Your program of programs must include the 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 theidentify 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 nearest while liter. Calculate and display the average yield per cow in a week to the nearest whole liter.
TASK 3 – Identify the most productive 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 liters of milk for four days or more in the week.
Visual Basic (Forms base) Solution
Dim nofcows, cowid As Integer Dim morning, evening, weektotalcow As Single nofcows = InputBox("How many cows in a herd ? ") Dim cowids(0 To nofcows) As Integer Dim milkstore(0 To nofcows) As Single For cows = 1 To nofcows cowid = InputBox(" Enter cow ID ") While cowid < 100 Or cowid > 999 MsgBox(" You have entred the wrong ID. Enter 3 number code. ") cowid = InputBox(" Enter cow ID ") End While cowids(cows) = cowid Next For cows = 1 To nofcows MsgBox(" Enter Milk Yield for cow ID no : " & cowids(cows)) For days = 1 To 7 MsgBox(" For day : " & days) morning = InputBox(" Morning Yield in liters for cow ") evening = InputBox(" Evening Yield in liters for cow ") weektotalcow = weektotalcow + morning + evening Next milkstore(cows) = weektotalcow Next
Dim total_yield, avg_yield As Single For cows = 1 To nofcows avg_yield = milkstore(cows) / nofcows MsgBox(" The average Yield of cow ID no " & cowids(cows) & " is : " & Math.Round(avg_yield)) total_yield = total_yield + milkstore(cows) Next MsgBox(" The total weekly volume of milk for the herd : " & Math.Round(total_yield))
Dim highest_yeild As Single Dim highest_ID As Integer highest_yeild = 0 For cows = 1 To nofcows If milkstore(cows) > highest_yeild Then highest_yeild = milkstore(cows) highest_ID = cowids(cows) End IfPre Release Material CS 2210 O Levels Summers 2018 A Project Of csmeasy.com Next MsgBox(" The Cow ID no : " & highest_ID & " has produced the highest yeild " & highest_yeild) For cows = 1 To nofcows If milkstore(cows) < 12.0 Then MsgBox(" The cow ID no " & cowids(cows) & " has produced less then 12 Liters In a week") End If Next End Sub End Class
Credits to : Engr. Bandeshah for the Visual Basic Solution
#Recording the yield Cow =  Yield =  Cows = int(input("How many cows are in the herd? ")) Day = 0 #to configure the milking for i in range(14): if i%2 == 1: Milking = "Second" else: Milking = "First" Day += 1 print("Day ", Day, "; ", Milking, " milking") for i in range(Cows): while True: Code = int(input("Enter code: ")) if Code > 999 or Code < 100: print("Enter a 3-digit code please") else: Cow.append(Code) break Y = float(input("Enter volume of milk in litres: ")) #A range check for yield can be added Yield.append(Y)
#Finding the Total and Average Total = 0 for i in range(len(Yield)): Total += Yield[i] Average = Total/Cows round(Total, 0) round(Average, 0) print("Total weekly volume of milk: ", int(Total), " litres") print("Average yield per cow: ", int(Average), " litres")
#Identifying most productive and low producing cows Total =  LessMilk = "" YieldOnDay = 0 Milking = 0 for j in range(Cows): T = 0 Days = 0 Cow = Cow[j] #A cow chosen for i in range(len(Cow)): if Cow[i] == Cow: T += Yield[i] #Incrementing the total for each cow YieldOnDay += Yield[i] Milking += 1 if Milking == 2: # 2 since checking for days, not milkings if YieldOnDay < 12: #Checking if yield is less than 12 Days += 1 Milking = 0 YieldOnDay = 0 if Days > 3: #Low yield for 4 or more days LessMilk = LessMilk + str(Cow[j]) + ", " Total.append(T) print(Total) for i in range(Cows): if Total[i] == max(Total): print("Cow ", Cow[i], " has the highest yield of ", Total[i], " litres") print("Cows which produced less than 12 litres of milk: " , LessMilk)