Advanced Inheritance 577
16
238: return;
239: }
240:
241: // if this goes after this one and before the next
242: // then insert it here, otherwise get the next
243: pNext = pCurrent->itsNext;
244: Next = pNext->itsPart->GetPartNumber();
245: if (Next > New)
246: {
247: pCurrent->itsNext = pNode;
248: pNode->itsNext = pNext;
249: return;
250: }
251: pCurrent = pNext;
252: }
253: }
254:
255: class PartsCatalog : private PartsList
256: {
257: public:
258: void Insert(Part *);
259: int Exists(int PartNumber);
260: Part * Get(int PartNumber);
261: operator+(const PartsCatalog &);
262: void ShowAll() { Iterate(Part::Display); }
263: private:
264: };
265:
266: void PartsCatalog::Insert(Part * newPart)
267: {
268: int partNumber = newPart->GetPartNumber();
269: int offset;
270:
271: if (!Find(offset, partNumber))
272: PartsList::Insert(newPart);
273: else
274: {
275: cout << partNumber << “ was the “;
276: switch (offset)
277: {
278: case 0: cout << “first “; break;
279: case 1: cout << “second “; break;
280: case 2: cout << “third “; break;
281: default: cout << offset+1 << “th “;
282: }
283: cout << “entry. Rejected!” << endl;
284: }
285: }
286:
287: int PartsCatalog::Exists(int PartNumber)
288: {
289: int offset;
LISTING16.7 continued