ExamBank Scot · N5 Computing Science question bank · All N5 Computing Science questions
10 marks · Input validation
A brick length must be greater than 15 and less than 50. Using pseudocode or a programming language of your choice, show how input validation could be used to ensure a valid brick length is entered by the user. Pseudocode OR Programming Language Using the information obtained in Lines 1 to 6. Use pseudocode or a programming language of your choice to show how Line 7 would be implemented. Pseudocode OR Programming Language The program is tested and gives the following output. The number of bricks needed is: 345.32 The number of bricks needing to be ordered is 346. Describe how a pre-defined function could be used to ensure that the correct number of bricks is ordered. Mortar is required to hold the bricks in place. The following calculation will be used to calculate the amount of mortar required. Mortar = (2 * sand) + cement + water State the number of variables required. A program is required to calculate the quantity of bricks required to build a wall. The program will ask the user to enter the dimensions of the wall and a single brick. 1 cm will be added onto the dimensions of the brick to allow for mortar between the bricks. Area of a rectangle is calculated by multiplying the length by height. Length of Wall Height of Wall Height of Brick + 1 cm Length of Brick + 1 cm A design for the program is shown below. Line 1 RECEIVE lengthOfWall FROM (REAL) KEYBOARD Line 2 RECEIVE heightOfWall FROM (REAL) KEYBOARD Line 3 RECEIVE lengthOfBrick FROM (REAL) KEYBOARD Line 4 RECEIVE heightOfBrick FROM (REAL) KEYBOARD Line 5 SET lengthOfBrick TO lengthOfBrick + 1 Line 6 SET heightOfBrick TO heightOfBrick + 1 Line 7 <calculate the quantity of bricks needed> Line 8 SEND [“The number of bricks needed is –” numberOfBricks] TO DISPLAY
1 mark each for: • conditional loop • input of brick length from user • correct complex conditions attached to loop (>15 AND <50) 1 mark each for: • Assignment any relevant example • Calculating wall area lengthOfWall * heightOfWall • Calculating brick area lengthOfBrick * heightOfBrick • Dividing wall area by brick area 1 cm has already been added to the length and height of the brick by line 6 so this should not be included in the calculation. If candidate added 1 to brick length take off 1 mark. Alternative answer: • assignment • bricksInHeight = heightOfWall/heightOfBrick • bricksInLength = lengthOfWall/lengthOfBrick • numberOfBricks = bricksInHeight * bricksInLength A function could be used to remove the decimal places from the number (1 mark) and then 1 could be added on (1 mark). or int(numberOFBricks) + 1 Marks allocated as: int(numberOFBricks) (1 mark) +1 (1 mark) Alternative answers: • round(numberOfBricks+0.5),0) (1 mark for round to 0 decimal places, 1 mark for +0.5) • floor(numberOfBricks) + 1 (mark as per int example) Some programming languages have a ceiling function that always rounds up. Award 2 marks for ceiling(numberOfBricks) If other alternative answers are found use professional judgement. Award 1 mark only for ‘round up’ as it’s a weak answer that demonstrates limited understanding. 4 4