Sams Teach Yourself C++ in 21 Days

(singke) #1

In Review


The Week in Review program for Week 2 brings together
many of the skills you’ve acquired over the past fortnight and
produces a powerful program.
This demonstration of linked lists utilizes virtual functions,
pure virtual functions, function overriding, polymorphism,
public inheritance, function overloading, pointers, references,
and more.
On Day 13, “Managing Arrays and Strings,” linked lists were
mentioned. In addition, Appendix E, “A Look at Linked
Lists,” provides a robust example of using a linked list. If you
haven’t looked at Appendix E, don’t fret, linked lists are com-
posed of C++ code you have learned about already. Note that
this is a different linked list from the one shown in the appen-
dix; in C++, there are many ways to accomplish the same
thing.
The goal of Listing R2.1 is to create a linked list. The nodes
on the list are designed to hold parts, as might be used in a
factory. Although this is not the final form of this program, it
does make a good demonstration of a fairly advanced data
structure. The code list is 298 lines. Try to analyze the code
on your own before reading the analysis that follows the
output.

WEEK 2 8

9


10


11


12


13


14


19 0672327112_w2_wir.qxd 11/19/04 12:28 PM Page 491

Free download pdf