Professional Documents
Culture Documents
Questions For Pre-Release Material
Questions For Pre-Release Material
(i) Declare the array used to store the COWIDS and COW_YIELD for the herd of cows .
COWIDS[ ]
COW_YIELD[ ]
(ii) Change this declaration so the array can only hold records for a sample of 50 COWS.
COWIDS[1:50]
COW_YIELD[1:50]
(iii) Explain why an array is an effective data structure for storing the records.
– can store COWIDS under a single identifier
– reduces the number variables
– arrays have an index which identifies each stored element
– can use iteration to loop through an array
– allows for more efficient programming
– programs are easier to debug
2. Write an algorithm to complete Task 1 for the 50 COWS, using either pseudocode,
programming statements or a flowchart.
DECLARE COWIDS=[ ] AS INTEGER
Validation check
FOR I=1 TO 50
OUTPUT “ENTER YOUR COWSCODE STATRTING WITH 100,101,102 ETC”
INPUT COW_NUMBER
INPUT COW_NUMBER
ENDWHILE
COWIDS[I] = COW_NUMBER
NEXT I
PERDAYMILK=0: NO OF YIELD=0
FOR COUNTER = 1 TO 7
FOR K = 1 TO 2
FOR I = 1 TO 50
NO OF YIELD= NO OF YIELD +1
COW_YIELD[I] = COW_YIELD[I]+MILKYIELD
PERDAYMILK[I] = PERDAYMILK[I]+MILKYIELD
NEXT I
NEXT K
NEXT COUNTER
3. (a) Identify three different types of test data you used to test the validation checks on the
cowids input in Task 1. For each type, give an example of appropriate data.
(b) Give two different validation checks you could have used for data entry in Task 1. For
each check explain why it could be used and provide a set of data for testing.
The only inputs for task 1 can be COW_NUMBER,MILKYIELD,NO OF YIELD
There are many possible correct answers these are examples only.
Validation check 1 - range check for cow identity code (COW_NUMBER)
Reason for choice - Each cow has a unique 3-digit identity code
Set of test data – 102 , 450 etc
Many correct answers, they must be meaningful. These are examples only.
Variable 1 – COUNTER
Data Type - integer
Use – to use as a loop counter for milking seven days a week.
Variable 2 – COW_YIELD
Data Type - real
Use – to store the milk yield of each cow .
Many correct answers, they must be meaningful. These are examples only.
5. Explain how you would change your solution of Task 3 to identify and display the
identity code number and weekly yield of the cow that has produced the least milk for 50
cows. Also identify and display the identity code numbers of any cows with a yield of less
than 12 litres of milk for three days or more in the week.
LEAST YIELD=999
LEASTYIELDCOW_NUMBER=” “
FOR I= 1 TO 50
THEN
LEASTYIELD=TOTAL[I]
LEASTYIELDCOW_NUMBER=COW_NUMBER[I]
ENDIF
NEXT I
MAXYIELD;”LITRES”
Display the identity code numbers of any cows with a yield of less than 12 liters of milk for
three days or more in the week.
FOR COUNTER = 1 TO 7
FOR I = 1 TO 50
IF PERDAYMILK[I]< 12 THEN
LOWYIELDLIST[I]=LOWYIELDLIST[I]+1
ENDIF
NEXT I
NEXT COUNTER
FOR I =1 TO 50
IF LOWYIELDLIST[I]>=3 THEN
ENDIF
NEXT I
END
6. Write an algorithm to complete THE VALIDATION FOR Task 1 for the 50 COWS, using
either pseudocode, programming statements or a flowchart.
DECLARE COWIDS=[ ] AS INTEGER
Validation check
FOR I=1 TO 50
INPUT COW_NUMBER
INPUT COW_NUMBER
ENDWHILE
COWIDS[I] = COW_NUMBER
NEXT I