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)The hint students can ask for: Write the subroutines at the bottom of the chart first, and test each one alone. Each box becomes one subroutine, and each line down from a box is a call inside it. The main program at the top only calls the boxes directly under it.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
def side(length):
forward(60, distance=length)
def corner(sides):
turn_right(30, angle=360 / sides)
def polygon(sides, length):
for i in range(sides):
side(length)
corner(sides)
print("polygon", sides, "done")
def fanfare():
for note in [523, 659, 784]:
tone(note, 0.15)
polygon(4, 20)
polygon(3, 20)
fanfare()
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.