Lab #2: CDT, ADT, Polymorphism, and Object(2)

glintplainvilleΛογισμικό & κατασκευή λογ/κού

18 Νοε 2013 (πριν από 3 χρόνια και 8 μήνες)

75 εμφανίσεις

Lab #2: CDT, ADT, Polymorphism, and Object
(2)

3. Polymorphism

In this problem, your job is to implement a polymorphic data type
tuple
. Download
this
program

to start with.

The newly added files are
tuple.h

and
tuple.c
. Your job is to filled the
code that absent in file
tuple.c
. Note that in this problem, we'll also
make use of the
complex

ADT as we did in problem 2. So you should first
copy your code in problem 2 here.

We h
ave suppied, in file
main.c
, some test code. After finishing the
problem, write more test cases to test your code.

Question #1:

How can we generalize the
tuple

ADT to a
nTuple

ADT? Recall
that
nTuple

is of the form:
(x_1, x_2, ..., x_n)

and each element
x
_i
(1<=i<=n)

may be of different type.

4. (Optional) Object

In this problem, we will do some object
-
oriented programming. To be specific, we will implement
both the
complex

and
tuple

ADTs in an object
-
oriented style, that is, each data item will carry
fu
nction pointers. Download
this program

to start with.

Problem #1:

The object layout we offered you in the code is more or less
primitive, in the sense that it only supports vir
tual functions and
dynamic method dispatch. Investigate how to modify the object layout so
that it can support more object
-
oriented language features, such as RTTI
(runtime type indentification), reflection, etc.. Then try to implement
your ideas.

Problem

#2:

Could we modify the object layout we offered you in the code,
to support inheritance or mutiple inheritance? Why or Why not?