// ferry.cpp // ---------------------------------------------------------------------- // // CSE 143 // Homework 4 // http://www.cs.washington.edu/education/courses/143/00su/homework/ // 21 Jul 2000, Ken Yasuhara #include #include "ferry.h" Ferry::Ferry(const int newArrivalTime, const int newTimeBetweenArrivals, const int newCarCapacity, const int newPersonCapacity) { assert(newArrivalTime > 0); assert(newTimeBetweenArrivals > 0); assert(newCarCapacity > 0 && newPersonCapacity > 0); arrivalTime = newArrivalTime; timeBetweenArrivals = newTimeBetweenArrivals; carCapacity = newCarCapacity; personCapacity = newPersonCapacity; carCount = 0; personCount = 0; } bool Ferry::canFit(const Car *car) const { // This car and the people inside must fit. return (getRemainingCarCapacity() >= 1 && getRemainingPersonCapacity() >= car->getPassengerCount() + 1); // (recall: Car::getPassengerCount() doesn't include driver.) } bool Ferry::board(const Car *car) { if (!canFit(car)) { return false; } carCount++; personCount += car->getPassengerCount() + 1; return true; }