The answersDownload the PDF
Worksheet

A1.6 Programming paradigms and procedural programming

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

BugBotLab
NameClassDate

What this lesson is about

Procedural, object-oriented, declarative and low-level paradigms, the structured approach, and hierarchy charts.

Questions 5 marks in all

  1. [1 mark]Which describes a declarative language?

    1. AYou state what result you want, and the language works out how to get it
    2. BYou give step-by-step instructions that change the program's state
    3. CYou write instructions for one particular processor
    4. DYou organise the program into classes and objects
  2. [1 mark]Which are features of the structured approach to programming?

    Tick every answer that is true.

    1. AOnly sequence, selection and iteration are used
    2. BProblems are designed top-down and split into subroutines
    3. CEach block has one entry and one exit point
    4. DGOTO statements jump between parts of the program
  3. [1 mark]In a hierarchy chart, what does a line from box A down to box B mean?

    1. ASubroutine A calls subroutine B
    2. BB runs before A
    3. CA and B share a variable
    4. DB is called exactly once
  4. [1 mark]Which paradigm would the Little Man Computer instruction set belong to?

    1. ALow-level (assembly)
    2. BObject-oriented
    3. CFunctional
    4. DLogic
  5. [1 mark]Which are advantages of the structured approach?

    Tick every answer that is true.

    1. ASubroutines can be tested individually
    2. BDifferent programmers can work on different subroutines
    3. CA change is often confined to one subroutine
    4. DThe program never needs testing as a whole

The task: structure it from the hierarchy chart

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.

QR code
Do it on the robot
www.bugbotlab.com/learn/a1-6-programming-paradigms/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Add a star(points, length) subroutine to the chart and the code. Which existing boxes does it call?
  2. Write the shapes program in AQA pseudo-code, with one SUBROUTINE for each box.
  3. Pick a program from earlier in the module and draw its hierarchy chart. Does any box call a subroutine that also appears under a different box?