ExamBank Scot · N5 Computing Science question bank · All N5 Computing Science questions

N5 Computing Science 2017 Question 17

10 marks · Input validation

Show, using pseudocode or a programming language of your choice, how input validation could be used to ensure an acceptable number of bags is entered. The data in the table below will be used to test the program. Complete the table. Test Data Type of Test Data Expected Results Extreme Proceed to next section of code Exceptional Three Program cannot run! Invalid data type 4 Proceed to next section of code When testing the program using the data from the table, “Three” is entered. As expected, an error message appears. Program cannot run! Invalid data type Name this type of error. Explain why this error occurred when testing the program. A syntax error can occur when writing code. Explain what is meant by a syntax error. Explain how the editing features in software development environments can help identify syntax errors. An online pet supply retailer is offering a special deal to customers buying at least two, but not more than six, bags of pet food. If customers try to buy any other quantity, a message is displayed. For example: Input Special Deal Please enter the number of bags of pet food you would like to buy: 8 Output Quantity not valid. Please try again.

Marking scheme

(Conditional) loop (1 mark) Correct loop condition (1 mark) Input inside loop (1 mark) Display error message (1 mark) Example answers: While (1) bags < 2 or bags >6 (1) Display error message (1) Input bags from user (1) End While Repeat/Do Input bags from user (1) If bags <2 or bags >6 Display error message (1) End If Until (1) bags >=2 and bags <=6 (1) Also accept alternative conditions Until bags >1 and bags <7 While bags <=1 or bags >=7 2 and/or 6 (1 mark) Normal (1 mark) Execution (Runtime) Data type expected is number (integer); data entered is string Entered the word three instead of the number 3. Do not accept invalid data type can’t just restate the question When a mistake is made in the program code. OR When the rules of the programming language are broken. Any one from the following: • Syntax highlighting • Colour coded variable names • Automatic indentation • Bookmarking/flags errors • Comments on errors Accept “Spell Check” only if the answer clearly shows how the spellchecker would identify the error to the user.

Previous question: N5 Computing Science 2017 Question 16

Next question: N5 Computing Science 2017 Question 18