// pstand.cc: the PumpStand class. #include #include "car.h" #include "pump.h" #include "pstand.h" PumpStand::PumpStand (int n) : numPumps (n) { if (n < 1) { cout << "Error! pump stand needs more than 0 pumps\n"; return; } pumps = new Pump*[numPumps]; topPump = numPumps - 1; for (int p = 0; p < numPumps; p++) pumps[p] = new Pump(); } void PumpStand::releasePump (Pump *p) { if (topPump >= numPumps) { cout << "Error! attempt to release a free pump?\n"; return; } pumps[++topPump] = p; } Pump *PumpStand::takeAvailablePump () { if (topPump < 0) { cout << "Error! no pump available when needed\n"; return 0; } return pumps[topPump--]; }