Exercises: Box-and-Pointer Diagrams
Feb 192018Before attempting these exercises, you should view the box-and-pointer diagrams video lecture.
The following classes are defined:
class Foo:
def __init__(self, baz, qux):
self.baz = baz
self.qux = qux
class Bar:
def __init__(self, quux, quuz):
self.quux = quux
self.quuz = quuz
In each of the exercises below, your box-and-pointer diagrams should show the program state after the code has been executed, including all variables, objects, and references.
Exercises
-
Draw a box-and-pointer diagram showing the program state after the following Python code has been executed:
corge = Foo(1, 2) grault = Foo(3, 4) garply = Bar(corge, grault)
-
Draw a box-and-pointer diagram showing the program state after the following Python code has been executed:
waldo = Foo(5, 6) fred = waldo fred.baz = 7
-
Draw a box-and-pointer diagram showing the program state after the following Python code has been executed:
plugh = Foo(8, 9) xyzzy = Bar(plugh, None) thud = Bar(xyzzy, xyzzy)
-
Draw a box-and-pointer diagram showing the program state after the following Python code has been executed:
wibble = Foo(1, 2) wibble = Foo(3, 4) wibble = Foo(5, 6)
-
Draw a box-and-pointer diagram showing the program state after the following Python code has been executed:
wobble = Bar(None, None) wobble = Bar(wobble, None) wobble.quuz = wobble
There are no published comments.