Sams Teach Yourself C++ in 21 Days

(singke) #1
145: PartsList::PartsList():
146: pHead(0),
147: itsCount(0)
148: {}
149:
150: PartsList::~PartsList()
151: {
152: delete pHead;
153: }
154:
155: Part* PartsList::GetFirst() const
156: {
157: if (pHead)
158: return pHead->GetPart();
159: else
160: return NULL; // error catch here
161: }
162:
163: Part * PartsList::operator[](int offSet) const
164: {
165: PartNode* pNode = pHead;
166:
167: if (!pHead)
168: return NULL; // error catch here
169:
170: if (offSet > itsCount)
171: return NULL; // error
172:
173: for (int i=0;i<offSet; i++)
174: pNode = pNode->GetNext();
175:
176: return pNode->GetPart();
177: }
178:
179: Part* PartsList::Find(int & position, int PartNumber) const
180: {
181: PartNode * pNode = 0;
182: for (pNode = pHead, position = 0;
183: pNode!=NULL;
184: pNode = pNode->GetNext(), position++)
185: {
186: if (pNode->GetPart()->GetPartNumber() == PartNumber)
187: break;
188: }
189: if (pNode == NULL)
190: return NULL;
191: else
192: return pNode->GetPart();
193: }
194:

566 Day 16


LISTING16.6 Continued
Free download pdf