O-level Computer science (2210), Pre-release Material M/J '18 with Solution

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.

Python Solution

Task 1

Cow = [] Yield = [] days=2 code=0 Cows = int(input("How many cows are in the herd? ")) for x in range(days): for x in range(Cows): Code = input("Enter code : ") c=len(Code) while c!=3: print("invaid code") Code = input("Enter code again: ") c=len(Code) Cow.append(Code) print(Cow) Yield1 = float(input("Enter volume of milk in litres: ")) Yield2 = float(input("Enter volume of milk in litres: ")) Yield.append(Yield1) Yield.append(Yield2) print(Yield)

Task 2

Total = 0 for i in range(len(Yield)): Total=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")
Task 3
Total = [] LessMilk = "" YieldOnDay = 0 Milking = 0 for j in range(Cows): T = 0 Days = 0 Cow_t = Cow[j] #A cow chosen for i in range(len(Cow)): if Cow[i] == Cow_t: T =T + Yield[i] #Incrementing the total for each cow YieldOnDay += Yield[i] Milking =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)

Visual Basic :

Task1: 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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 &lt; 100 Or cowid &gt; 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 : " &amp; cowids(cows))
        For days = 1 To 7
            MsgBox(" For day : " &amp; 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

Task 2:
1
2
3
4
5
6
7
8
9
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 " &amp; cowids(cows) &amp; " is : " &amp;
    Math.Round(avg_yield))
    total_yield = total_yield + milkstore(cows)
Next
MsgBox(" The total weekly volume of milk for the herd : " &amp;
Math.Round(total_yield))

Task 3:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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

Comments

Popular Posts

IFRS 'RED BOOK' 2017 NOW AVAILABLE--FREE PDF.

HOW TO INCREASE IPHONE/IPAD STORAGE

DIFFERENCE B/W 32 BIT(X86) AND 64 BIT(X64) VERSIONS

TOP 10 WEBSITES THAT PAY FOR LINK SHORTENING!!!

Windows 10 Activator | KMSPico