Presentation is loading. Please wait.

Presentation is loading. Please wait.

Program Design Using Haggis

Similar presentations


Presentation on theme: "Program Design Using Haggis"— Presentation transcript:

1 Program Design Using Haggis
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.

2 Haggis formatting rules.
1. Keywords are always written in upper case letters. SET SEND RECEIVE 2. Each line begins with the word “Line” (Note the capital L) and a single space before the number. Line 1 Line 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 REPEAT Line SEND [“Please enter a number”] TO DISPLAY Line RECEIVE number FROM KEYBOARD Line 4 UNTIL number = 100

3 PRINT, INPUT and LET commands
PRINT command True Basic PRINT “Please enter your name” Haggis SEND [“Please enter your name”] TO DISPLAY INPUT command True Basic INPUT name$ Haggis RECEIVE name FROM KEYBOARD LET command True Basic LET area = length * breadth Haggis SET area TO length* breadth 3

4 Example 1 (PRINT, INPUT and LET commands)
This program asks the user for the height and base of a triangle and works out the area. PRINT “Please enter the height of the triangle” INPUT height PRINT “Please enter the base of the triangle” INPUT base LET area = (height*base)/ 2 PRINT “The area of the triangle is “; area END True Basic Line 1 SEND [“Please enter the height of the triangle”] TO DISPLAY Line 2 RECEIVE height FROM KEYBOARD Line 3 SEND [“Please enter the base of the triangle”] TO DISPLAY Line 4 RECEIVE base FROM KEYBOARD Line 5 SET area TO (height*base)/2 Line 6 SEND [“The area of the triangle is ”, area] TO DISPLAY Haggis

5 IF ... THEN construct True Basic
IF user_answer$ = correct_answer$ THEN PRINT “Well done! You are correct.” END IF Haggis IF userAnswer = correctAnswer THEN SEND [“Well done! You are correct.”] TO DISPLAY END IF 5

6 Example 2 (IF ... THEN ... ENDIF)
This program will ask the user the question “What is the capital of Scotland?” It will then check if the user’s answer is correct and if it is then it will display a “Well done” message. 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 IF END True Basic Line 1 SET correctAnswer TO “Edinburgh” Line 2 SEND [“What is the capital of Scotland?”] TO DISPLAY Line 3 RECEIVE userAnswer FROM KEYBOARD Line 4 IF userAnswer = correctAnswer THEN Line 5 SEND [“Well done, you are correct.”] TO DISPLAY Line 6 END IF Haggis

7 Questions Now attempt questions 1, 2 and 3 from your Questions booklet.

8 Fixed Loops True Basic FOR 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 TIMES Line SEND [firstName] TO DISPLAY Line 3 END REPEAT (Version 2) Line 1 FOR counter FROM 1 TO 10 Line SEND [firstName] TO DISPLAY Line 3 END FOR 8

9 Example 3 (FOR ..NEXT) This example asks the user for a sentence then prints that sentence 15 times. True Basic PRINT “Please enter your sentence” INPUT sentence$ FOR counter = 1 to 15 PRINT sentence$ NEXT counter Haggis Line 1 SEND [“Please enter your sentence”] TO DISPLAY Line 2 RECEIVE sentence FROM KEYBOARD Line 3 REPEAT 15 TIMES Line 4 SEND sentence TO DISPLAY Line 5 END REPEAT

10 Questions Now attempt question 4 from your Questions booklet.

11 Conditional Loops DO ... LOOP UNTIL Haggis Line 1 REPEAT
True Basic DO PRINT “Please enter your mark” INPUT mark LOOP UNTIL mark >= 50 Haggis Line 1 REPEAT Line 2 SEND [“Please enter your mark”] TO DISPLAY Line 3 RECEIVE mark FROM KEYBOARD Line 4 UNTIL mark >= 50 11

12 Example 4 (DO .. LOOP UNTIL)
This program asks the user for a password and keeps asking until the user enters “apple”. True Basic DO PRINT “Please enter password” INPUT password$ LOOP UNTIL password$ = “apple” PRINT “You have clearance” Haggis Line 1 REPEAT Line 2 SEND [“Please enter password”] TO DISPLAY Line 3 RECEIVE password FROM KEYBOARD Line 4 UNTIL password=”apple” Line 5 SEND [“You have clearance”] TO DISPLAY

13 Questions Now read Example 5 in your notes booklet and then attempt Questions 5, 6, 7 and 8 from your Questions booklet.


Download ppt "Program Design Using Haggis"

Similar presentations


Ads by Google