Sams Teach Yourself C++ in 21 Days

(singke) #1
Advanced Inheritance 573

16


34: public:
35: CarPart():itsModelYear(94){}
36: CarPart(int year, int partNumber);
37: virtual void Display() const
38: {
39: Part::Display();
40: cout << “Model Year: “;
41: cout << itsModelYear << endl;
42: }
43: private:
44: int itsModelYear;
45: };
46:
47: CarPart::CarPart(int year, int partNumber):
48: itsModelYear(year),
49: Part(partNumber)
50: {}
51:
52:
53: // **************** AirPlane Part ************
54:
55: class AirPlanePart : public Part
56: {
57: public:
58: AirPlanePart():itsEngineNumber(1){};
59: AirPlanePart(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(int EngineNumber, int PartNumber):
71: itsEngineNumber(EngineNumber),
72: Part(PartNumber)
73: {}
74:
75: // **************** Part Node ************
76: class PartNode
77: {
78: public:
79: friend class PartsList;
80: PartNode (Part*);
81: ~PartNode();
82: void SetNext(PartNode * node)
83: { itsNext = node; }
84: PartNode * GetNext() const;
85: Part * GetPart() const;

LISTING16.7 continued

Free download pdf