You are on page 1of 6

1. All variables and other identifiers should have meaningful names.

(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

DECLARE COW_YIELD=[ ] AS REAL

DECLARE LOWYIELDLIST=[ ] AS INTEGER

DECLARE COW_NUMBER AS INTEGER

DECLARE PERDAYMILK =[ ] AS REAL

DECLARE MILK YIELD AS REAL

Validation check
FOR I=1 TO 50
OUTPUT “ENTER YOUR COWSCODE STATRTING WITH 100,101,102 ETC”

INPUT COW_NUMBER

WHILE COW_NUMBER<100 OR COW_NUMBER>999

OUTPUT “COW_NUMBER IS OUT OF RANGE SPECIFIED, PLEASE ENTER COW_NUMBER AGAIN”

INPUT COW_NUMBER

ENDWHILE

COWIDS[I] = COW_NUMBER

NEXT I

LOOP FOR FULL WEEK

PERDAYMILK=0: NO OF YIELD=0

FOR COUNTER = 1 TO 7

OUTPUT (“ENTER DATA FOR DAY “;COUNTER)

LOOP FOR MILKING TWICE THE COWS

FOR K = 1 TO 2

FOR I = 1 TO 50

OUTPUT (“ENTER DATA FOR” K ;“MILKING”)

ENTER EACH COW YIELD

OUTPUT“ENTER THE YIELD OF THE COW” ; COWIDS[I]

INPUT MILKYIELD, NO OF YIELD

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.

Normal / Valid 103


Erroneous / Abnormal / Invalid 13.5 / Twelve / 9
Boundary (accepted)/ Boundary 100 or 999/
(rejected) 99 or 1000
Extreme 100 or 999

(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

Validation check 2 - type check for MILKYIELD


Reason for choice - must be a numeric value
Set of test data- 6.5 liters, 8 liters etc

4. (i) When you performed the task1, you used variables.

Write suitable declarations for two of these.


State what you used each one for.

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 .

(ii) When you performed the task1, you used constants.

Write suitable declarations for two of these.


State what you used each one for.

Many correct answers, they must be meaningful. These are examples only.

Constant 1 – Days of week


Value – 7
Constant 2 name – MILKYIELD per day
Value - 2

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

IF TOTAL[I]<LEASTYIELD (TOTAL IN TASK 2)

THEN

LEASTYIELD=TOTAL[I]

LEASTYIELDCOW_NUMBER=COW_NUMBER[I]

ENDIF

NEXT I

OUTPUT “COW”;MAXYIELDCOW_NUMBER; “HAS THE MAXIMUM YIELD OF”:

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

OUTPUT”COWID”; COWIDS[I];”YIELDED LOW MILK FOR”;LOWYIELDLIST[I];”DAYS”

ENDIF

NEXT I

END

– variable used to hold will have to initialised to a high value / variable


used to hold will be given first record value
– store array value in variable if less than current value in variable
– store array value of COW_NUMBER with the same index in a variable
– Output COWIDS with LEASTYIELD LITRES of milk
- Check the PERDAYMILK of each cow is less than 12 liters and
LOWYIELDLIST is greater than or equal to 3
- output COWIDS of the cow with the days of lowyieldlist.

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

DECLARE COW_NUMBER AS INTEGER

Validation check
FOR I=1 TO 50

OUTPUT “ENTER YOUR COWSCODE STATRTING WITH 100,101,102 ETC”

INPUT COW_NUMBER

WHILE COW_NUMBER<100 OR COW_NUMBER>999

OUTPUT “COW_NUMBER IS OUT OF RANGE SPECIFIED, PLEASE ENTER COW_NUMBER AGAIN”

INPUT COW_NUMBER

ENDWHILE

COWIDS[I] = COW_NUMBER

NEXT I

You might also like