Presentation on theme: "Program Design Using Haggis"— Presentation transcript:
1Program 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.
2Haggis formatting rules. 1. Keywords are always written in upper case letters.SETSENDRECEIVE2. Each line begins with the word “Line” (Note the capital L) and a single space before the number.Line 1Line 23. 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, secondNumber4. Square brackets should be used in the SEND command.5. The lines of coding inside a construct should be indented.Line 1 REPEATLine SEND [“Please enter a number”] TO DISPLAYLine RECEIVE number FROM KEYBOARDLine 4 UNTIL number = 100
3PRINT, INPUT and LET commands PRINT commandTrue Basic PRINT “Please enter your name”Haggis SEND [“Please enter your name”] TO DISPLAYINPUT commandTrue Basic INPUT name$Haggis RECEIVE name FROM KEYBOARDLET commandTrue Basic LET area = length * breadthHaggis SET area TO length* breadth3
4Example 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 heightPRINT “Please enter the base of the triangle”INPUT baseLET area = (height*base)/ 2PRINT “The area of the triangle is “; areaENDTrue BasicLine 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 DISPLAYHaggis
5IF ... THEN construct True Basic IF user_answer$ = correct_answer$ THENPRINT “Well done! You are correct.”END IFHaggisIF userAnswer = correctAnswer THENSEND [“Well done! You are correct.”] TO DISPLAYEND IF5
6Example 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$ THENPRINT “Well done, you are correct.”END IFENDTrue BasicLine 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 IFHaggis
7QuestionsNow attempt questions 1, 2 and 3 from your Questions booklet.
8Fixed Loops True Basic FOR counter = 1 TO 10 PRINT firstname$ NEXT counterFOR NEXT loopHaggis There are 2 ways of writing a FOR loop(Version 1)Line 1 REPEAT 10 TIMESLine SEND [firstName] TO DISPLAYLine 3 END REPEAT(Version 2)Line 1 FOR counter FROM 1 TO 10Line SEND [firstName] TO DISPLAYLine 3 END FOR8
9Example 3(FOR ..NEXT)This example asks the user for a sentence then prints that sentence 15 times.True BasicPRINT “Please enter your sentence”INPUT sentence$FOR counter = 1 to 15PRINT sentence$NEXT counterHaggisLine 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
10QuestionsNow attempt question 4 from your Questions booklet.
11Conditional Loops DO ... LOOP UNTIL Haggis Line 1 REPEAT True BasicDOPRINT “Please enter your mark”INPUT markLOOP UNTIL mark >= 50HaggisLine 1 REPEATLine 2 SEND [“Please enter your mark”] TO DISPLAYLine 3 RECEIVE mark FROM KEYBOARDLine 4 UNTIL mark >= 5011
12Example 4 (DO .. LOOP UNTIL) This program asks the user for a password and keeps asking until the user enters “apple”.True BasicDOPRINT “Please enter password”INPUT password$LOOP UNTIL password$ = “apple”PRINT “You have clearance”HaggisLine 1 REPEATLine 2 SEND [“Please enter password”] TO DISPLAYLine 3 RECEIVE password FROM KEYBOARDLine 4 UNTIL password=”apple”Line 5 SEND [“You have clearance”] TO DISPLAY
13QuestionsNow read Example 5 in your notes booklet and then attempt Questions 5, 6, 7 and 8 from your Questions booklet.