With task 2 now complete, we can begin to tackle the final problem...task 3!
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
Task Break Down
Which cow has produced the most milk - To get this information we now need to work out individual cow totals - Array needed to store individual cow totals - Name - IndCowTotals
How much milk did the best cow yield all week - We will search the individual cow totals to determine the best cow - Variable will be required to store the best cow as we search the IndCowTotals array - Name - BestCow
Which cows produced less than 12 litres on more than 4 days in the week. - We will search the original TotalCowYield array to find this - A new array - Name - LowYieldCount will keep count for each cow, the number of times that it produces less than 12 litres
Example - We have three cows. The number of times that each cow produces less than 12 litres are:
Cow 1 - 5 times Cow2 - 2 times Cow 3 - 1 time
In this case the LowYieldCount would hold this data LowYieldCount = [5,2,1]
- Next we will need a new array to store the ID numbers of each cow who has a LowYieldCount of more than 4 - Name - BadCows
The following program flow steps give a brief outline of the key steps involved in task 2.
Step 1 Create new data structures to store required information First we will need a new variable to store the ID number of the best Cow - Name = BestCow Next we need to declare a new Array that will store each cows weekly total - Name = CowTotals  Now we need an Array to serve as a counting space for each time, each cow produces less than 12 litres of milk - Name = LowYieldCount  Finally we need to declare an Array to store the ID numbers of all cows that produce less than 12 liters of milk m than 4 times
Step 2 We need to calculate each cows individual total and store their totals in the CowsTotal  Array To do this we will need to use the now familiar For loop that loops for 7 days within the week and nested within this loop we need another for loop that loops through every cow in the herd. Upon looping through each cow in the herd, we will add the current value in the TotalCowYield array into the CowsTotal  array.
Step 3 Work out which is the best cow and which are the worst Cows To finish this program we need to, again set up the same for loop within a for loop - One for loop for the 7 days of the week, the inner for loop for the number of cows. Within each repetition of the inner loop, we will look at the totalCowYield and check to see if it is less than 4. If it is less than 4 then we will add 1 to the LowCowYield Array. Next, within the same loop, we check to see if the cows total is greater than that stored in the current BestCow variable. Finally - We Output all of the information to the user.