Advanced Inheritance 555
16
36: virtual void Display() const
37: {
38: Part::Display();
39: cout << “Model Year: “;
40: cout << itsModelYear << endl;
41: }
42: private:
43: int itsModelYear;
44: };
45:
46: CarPart::CarPart(int year, int partNumber):
47: itsModelYear(year),
48: Part(partNumber)
49: {}
50:
51:
52: // **************** AirPlane Part ************
53:
54: class AirPlanePart : public Part
55: {
56: public:
57: AirPlanePart():itsEngineNumber(1){};
58: AirPlanePart
59: (int EngineNumber, int PartNumber);
60: virtual void Display() const
61: {
62: Part::Display();
63: cout << “Engine No.: “;
64: cout << itsEngineNumber << endl;
65: }
66: private:
67: int itsEngineNumber;
68: };
69:
70: AirPlanePart::AirPlanePart
71: (int EngineNumber, int PartNumber):
72: itsEngineNumber(EngineNumber),
73: Part(PartNumber)
74: {}
75:
76: // **************** Part Node ************
77: class PartNode
78: {
79: public:
80: PartNode (Part*);
81: ~PartNode();
82: void SetNext(PartNode * node)
83: { itsNext = node; }
84: PartNode * GetNext() const;
85: Part * GetPart() const;
86: private:
87: Part *itsPart;
LISTING16.5 continued