Program Design Using Haggis

Slides:



Advertisements
Similar presentations
Combining Like Terms. Only combine terms that are exactly the same!! Whats the same mean? –If numbers have a variable, then you can combine only ones.
Advertisements

© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 5: Repetition and Loop Statements Problem Solving & Program.
Introduction to Programming
LOOPS Loops are lines of code that can be run more than one time. Each time is called an iteration and in for loops there is also an index that is changing.
CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Programming Methodology (1). public class Hello { public static void main(String[] args) { System.out.println("Hello world"); } } Hello world.
5.9 + = 10 a)3.6 b)4.1 c)5.3 Question 1: Good Answer!! Well Done!! = 10 Question 1:
Summer 2012 Instructor: Hassan Khosravi
1 Chapter 4 The while loop and boolean operators Samuel Marateck ©2010.
Decisions If statements in C.
Computing Science Software Design and Development SOFTWARE DESIGN AND DEVELOPMENT USING PYTHON.
Test B, 100 Subtraction Facts
Follow the man….. Read the phrases on the shimmering neon lights and write down the correct economic term to match that phrase.
Computer Programming Mr. José A. Ortiz Morris. Computer Language  Languages that the computer understands.  They are low level languages. (BINARY 1.
Standard Algorithms Find the highest number. ! Your name and today’s date ! Find the maximum Dim numbers(20) As Integer.
ABNIAC The following slide presentation is to acquaint the student with ABNIAC. The version used for presentation is the Java version, which can be found.
PSEUDOCODE & FLOW CHART
ITEC113 Algorithms and Programming Techniques
Computer Science 1620 Loops.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
True BASIC Ch. 6 Practice Questions. What is the output? PRINT X LET X = -1 PRINT X FOR X = 4 TO 5 STEP 2 PRINT X NEXT X PRINT X END.
1 9/28/07CS150 Introduction to Computer Science 1 Loops section 5.2, 5.4, 5.7.
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
Do Loops A Do..Loop terminates based on a condition that is specified Execution of a Do..Loop continues while a condition is True or until a condition.
CS1061: C Programming Lecture 23: Review; Examination Details A. O’Riordan, 2005.
Chapter 3 Planning Your Solution
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
Noadswood Science,  To know the basics of Python coding and decoding Monday, September 07, 2015.
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
Programming.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
Chapter 2 - Algorithms and Design
Logic Structure - focus on looping Please use speaker notes for additional information!
Linux+ Guide to Linux Certification, Third Edition
Python Repetition. We use repetition to prevent typing the same code out many times and to make our code more efficient. FOR is used when you know how.
ORDER OF CONTENT AND INSTRUCTIONS A program in its simplest form usually contains three kinds of activity:  INPUT : The program asks the user for some.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 1 Simple Python Programs Using Print, Variables, Input.
Repetition Structures Repetition Structures allow you to write programs that will repeat program steps multiple times. –Also called Loops –Counter controlled.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
CMP-MX21: Lecture 5 Repetitions Steve Hordley. Overview 1. Repetition using the do-while construct 2. Repetition using the while construct 3. Repetition.
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
ITI 1120 Lab #5 Contributors: S. Boyd, R. Plesa, A. Felty, D. Inkpen, A. Williams, D. Amyot.
Designing While Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Validation final steps Stopping gaps being entered in an input.
© The McGraw-Hill Companies, 2006 Chapter 3 Iteration.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
Algorithms and Pseudocode
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
1 Project 7: Looping. Project 7 For this project you will produce two Java programs. The requirements for each program will be described separately on.
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Nested For Loops. First, the rules to these loops do not change. We are sticking one loop inside another. while(condition) { // loop body } do { // loop.
While loops. Iteration We’ve seen many places where repetition is necessary in a problem. We’ve been using the for loop for that purpose For loops are.
Microsoft® Small Basic Conditions and Loops Estimated time to complete this lesson: 2 hours.
Fundamentals of Algorithms MCS - 2 Lecture # 3. Representation of Algorithms.
Repetition In today’s lesson we will look at: why you would want to repeat things in a program different ways of repeating things creating loops in Just.
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
Lesson 4 - Challenges.
7 - Programming 7P, Q, R - Testing.
Lesson 3 - Repetition.
Iterations Programming Condition Controlled Loops (WHILE Loop)
Standard Algorithms Input validation Finding the minimum
Introduction to pseudocode
Topic 1: Problem Solving
We’re moving on to more recap from other programming languages
Introduction to TouchDevelop
Learning Intention I will learn about evaluating a program.
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
The monitor shows information.
Learning Intention I will learn about the standard algorithm for input validation.
Python SAT 1 Feedback.
Presentation transcript:

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.

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 2 SEND [“Please enter a number”] TO DISPLAY Line 3 RECEIVE number FROM KEYBOARD Line 4 UNTIL number = 100

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

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

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

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

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

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

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

Questions Now attempt question 4 from your Questions booklet.

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

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

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