Programming techniques and object-oriented programming · A level · OCR H446 1.2.4, AQA 7517 4.1.2.1, Eduqas A500QS 1.4 · about 20 min
Procedural, object-oriented, declarative and low-level paradigms, the structured approach, and hierarchy charts.
[1 mark]Which describes a declarative language?
[1 mark]Which are features of the structured approach to programming?
Tick every answer that is true.
[1 mark]In a hierarchy chart, what does a line from box A down to box B mean?
[1 mark]Which paradigm would the Little Man Computer instruction set belong to?
[1 mark]Which are advantages of the structured approach?
Tick every answer that is true.
The starter drives a square and a triangle with every move typed out, then plays three notes. Restructure it to match the hierarchy chart above, with no global variables:
- side(length) drives forward length cm.
- corner(sides) turns right by the angle for a regular polygon with sides sides: a full turn, 360 degrees, divided by sides. Work it out; do not type 90 or 120.
- polygon(sides, length) repeats side then corner once for each side, then prints polygon <sides> done.
- fanfare() plays the notes 523, 659 and 784 Hz for 0.15 seconds each.
The main program calls polygon(4, 20), then polygon(3, 20), then fanfare(), and nothing else.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
forward(60, distance=20)
turn_right(30, angle=90)
forward(60, distance=20)
turn_right(30, angle=90)
forward(60, distance=20)
turn_right(30, angle=90)
forward(60, distance=20)
turn_right(30, angle=90)
print("polygon 4 done")
forward(60, distance=20)
turn_right(30, angle=120)
forward(60, distance=20)
turn_right(30, angle=120)
forward(60, distance=20)
turn_right(30, angle=120)
print("polygon 3 done")
tone(523, 0.15)
tone(659, 0.15)
tone(784, 0.15)Plan your program here, then type it in and press Run.
star(points, length) subroutine to the chart and the code. Which existing boxes does it call?SUBROUTINE for each box.