Lab #2: CDT, ADT, Polymorphism, and ObjectIntroductionThis lab is split into four parts. The first part concentrates on getting familiarized with the construction of concrete data types (CDT). The second part examines a ADT (abstract data types). And the third part deals with polymorphic code. Finally, the fourth part delves into objects. Both the latter two parts are optional.1. Concrete Data Types (CDT)CDTs are data types that the concrete data representations are transparent. In this problem, we'd like to experience with CDT via one example: thecomplex data type. Download
this program to start with.
Now compile the code we offered you, you may see a bunch of
warning messages emitted by the compiler. And partly due to
the fact some source files are incomplete. Open the file
Your job is to fill in the code that marked as
After finishing the task, try to modify the client code in file
2. Abstract Data Types (ADT)ADTs are data types that the concrete data representations are opaque. In this problem, we'd like to experience with ADT by rethinking our previous example: thecomplex
data type. Download this program to start with.
Your job is to fill in the code that marked as What's the difference between CDT and ADT? Can we access data representations directly in ADTs? Make some demos to support your conclusions.
3. PolymorphismIn this problem, your job is to implement a polymorphic data typetuple . Download this program
to start with.
The newly added files are
We have suppied, in file
Question #1: How can we generalize the 4. (Optional) ObjectIn this problem, we will do some object-oriented programming. To be specific, we will implement both thecomplex and
tuple ADTs in an object-oriented style, that is, each
data item will carry function 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 virtual 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? |