Learning Intention I will learn about the standard
Learning Intention • I will learn about the standard algorithm for input validation.
1. 2. 3. 4. 5. 6. Analysis Design Implementation Testing Documentation Evaluation
Standard Algorithms • An algorithm is a step-by-step procedure for solving a problem in a finite number of steps. • Any bit of written code that carries out a specific task could be said to be an algorithm.
A program to add two test marks together is to be created. Both tests are marked out of 20. Normal Test Data: 1 -> 19 Extreme Test Data: 0, 20 Exceptional Test Data: -1, 21
A program to add two test marks together is to be created. Both tests are marked out of 20.
Standard Algorithm - Input Validation • Input validation is used to check that input to the program is acceptable. • Validating input is a specific task that is used in lots of programs so it is called a standard algorithm.
Input Validation Example A program to enter a users age: SEND “Enter an age (range 0 - 130)” TO DISPLAY RECEIVE age FROM (INTEGER) KEYBOARD SEND “You are “ & age & “ years old” TO DISPLAY
Input Validation – Example 1 SEND “Enter an age (range 0 - 130)” TO DISPLAY RECEIVE age FROM (INTEGER) KEYBOARD WHILE age ˂ 0 OR age ˃ 130 DO SEND “Invalid. Try again” TO DISPLAY RECEIVE age FROM (INTEGER) KEYBOARD END WHILE SEND “You are “ & age & “ years old” TO DISPLAY
Input Validation – Example 2 REPEAT SEND “Enter an age (range 0 - 130)” TO DISPLAY RECEIVE age FROM (INTEGER) KEYBOARD IF age < 0 OR age > 130 THEN SEND “Invalid. Try again” TO DISPLAY END IF UNTIL age >= 0 AND age <= 130 SEND “You are “ & age & “ years old” TO DISPLAY
Standard Algorithm - Input Validation • Input validation can be added to any program that is accepting input, even inside another loop (fixed or conditional).
What did this program do? SET total TO 0 REPEAT RECEIVE number FROM KEYBOARD SET total TO total + number SEND total TO DISPLAY UNTIL total > 100
Over 100 (with each number <= 20) SET total TO 0 REPEAT RECEIVE number FROM KEYBOARD IF number > 20 THEN SEND “number too big” TO DISPLAY END IF UNTIL number <= 20 SET total TO total + number SEND total TO DISPLAY UNTIL total > 100
Programming Tasks • Complete the programming tasks on pages 73 -75 • Extension Sets 6 & 6 b
Success Criteria • I can create an input validation algorithm using a conditional loop.
- Slides: 14