program design using haggis 1 haggis is a standardised design notation used by the sqa in place of a...
TRANSCRIPT
Program Design Using Haggis
1
Haggis is a standardised design notation used by the SQA in place of a programming language for the purpose of asking coding questions in assessments or exams.
1. Keywords are always written in upper case letters.SETSENDRECEIVE
2. Each line begins with the word “Line” (Note the capital L) and a single space before the number.
Line 1Line 2
3. Variable names should be written in lower case letters to distinguish from keywords. Where the user wishes to use a longer variable name the second word should begin with a capital letter. e.g. firstName, secondNumber
4. Square brackets should be used in the SEND command.
5. The lines of coding inside a construct should be indented.Line 1 REPEATLine 2 SEND [“Please enter a number”] TO DISPLAYLine 3 RECEIVE number FROM KEYBOARDLine 4 UNTIL number = 100
2
Haggis formatting rules.
3
PRINT command
True Basic PRINT “Please enter your name”
Haggis SEND [“Please enter your name”] TO DISPLAY
LET commandTrue Basic LET area = length * breadth
Haggis SET area TO length* breadth
INPUT commandTrue Basic INPUT name$
Haggis RECEIVE name FROM KEYBOARD
4
PRINT “Please enter the height of the triangle”INPUT heightPRINT “Please enter the base of the triangle”INPUT baseLET area = (height*base)/ 2PRINT “The area of the triangle is “; areaEND
Line 1 SEND [“Please enter the height of the triangle”] TO DISPLAYLine 2 RECEIVE height FROM KEYBOARDLine 3 SEND [“Please enter the base of the triangle”] TO DISPLAYLine 4 RECEIVE base FROM KEYBOARDLine 5 SET area TO (height*base)/2Line 6 SEND [“The area of the triangle is ”, area] TO DISPLAY
True Basic
Haggis
5
True Basic IF user_answer$ = correct_answer$ THEN
PRINT “Well done! You are correct.”END IF
Haggis
IF userAnswer = correctAnswer THENSEND [“Well done! You are correct.”] TO DISPLAY
END IF
6
LET correct_answer$=”Edinburgh”PRINT “What is the capital of Scotland?” INPUT user_answer$IF user_answer$ = correct_answer$ THEN PRINT “Well done, you are correct.”END IFEND
Line 1 SET correctAnswer TO “Edinburgh”Line 2 SEND [“What is the capital of Scotland?”] TO DISPLAYLine 3 RECEIVE userAnswer FROM KEYBOARDLine 4 IF userAnswer = correctAnswer THENLine 5 SEND [“Well done, you are correct.”] TO DISPLAYLine 6 END IF
True Basic
Haggis
7
Now attempt questions 1, 2 and 3 from your Questions booklet.
8
True BasicFOR counter = 1 TO 10
PRINT firstname$NEXT counter
FOR ..... NEXT loop
Haggis There are 2 ways of writing a FOR loop
(Version 1)Line 1 REPEAT 10 TIMESLine 2 SEND [firstName] TO DISPLAYLine 3 END REPEAT
(Version 2)Line 1 FOR counter FROM 1 TO 10Line 2 SEND [firstName] TO DISPLAYLine 3 END FOR
9
True Basic
Haggis
PRINT “Please enter your sentence”INPUT sentence$FOR counter = 1 to 15
PRINT sentence$NEXT counter
Line 1 SEND [“Please enter your sentence”] TO DISPLAYLine 2 RECEIVE sentence FROM KEYBOARDLine 3 REPEAT 15 TIMESLine 4 SEND sentence TO DISPLAYLine 5 END REPEAT
10
Now attempt question 4 from your Questions booklet.
11
True Basic
DO PRINT “Please enter your mark” INPUT markLOOP UNTIL mark >= 50
DO ... LOOP UNTIL
Haggis
Line 1 REPEATLine 2 SEND [“Please enter your mark”] TO DISPLAYLine 3 RECEIVE mark FROM KEYBOARD Line 4 UNTIL mark >= 50
12
True Basic
Haggis
DO PRINT “Please enter password” INPUT password$LOOP UNTIL password$ = “apple”PRINT “You have clearance”
Line 1 REPEATLine 2 SEND [“Please enter password”] TO DISPLAYLine 3 RECEIVE password FROM KEYBOARD Line 4 UNTIL password=”apple”Line 5 SEND [“You have clearance”] TO DISPLAY
13
Now read Example 5 in your notes booklet and then attempt Questions 5, 6, 7 and 8 from your Questions booklet.