Exemplo n.º 1
0
/**
 * Function: retrieveCar(int tNumber)
 * Purpose: Iterate through each node and search for the car with the ticketnumber
 * Parameters: tNumber - integer value that represents the ticket number
 * Class MemberVariable:
 *          carInFront - equivalent to headPointer
 *          currentCar - equivalent to currentPointer
 *          lastCar - equivalent to tailPointer
 *          previousToCurrentCar - equivalent to previous (holds the pointer to the one node prior to current being changed)
 **/
void Parking::retrieveCar(int tNumber)
{
    //change the pointer to the top
    currentCar = carInFront;
    
    //iterate through the node until current reaches the end
    while (currentCar != 0)
    {
        //first car...
        if (carInFront == currentCar && tNumber == currentCar->getAssignedTicketNumber())
        {
            cout << VEHICLE_FOUND << currentCar << " with ticket #: " << tNumber << endl;
            removeThisCar = currentCar;
            currentCar = currentCar->getLinkToNextCar();
            delete removeThisCar;
            //setting the new front car
            carInFront = currentCar;
            break;
        }
        //end of the node car....
        else if(currentCar->getLinkToNextCar() == 0)
        {
            cout << VEHICLE_FOUND << currentCar << " with ticket #: " << tNumber << endl;
            removeThisCar = currentCar;
            previousToCurrentCar->setLinkToNextCar(0);
            currentCar = previousToCurrentCar;
            delete removeThisCar;
            //setting the last car
            lastCar = currentCar;
            break;
        }
        else if (carInFront == currentCar && lastCar == currentCar && currentCar->getLinkToNextCar() == 0)
        {
            cout << VEHICLE_FOUND << currentCar << " with ticket #: " << tNumber << endl;
            break;
        }
        
        else if (currentCar->getAssignedTicketNumber() == tNumber)
        {
            cout << VEHICLE_FOUND << currentCar << " with ticket #: " << tNumber << endl;
            removeThisCar = currentCar;
            currentCar = currentCar->getLinkToNextCar();
            delete removeThisCar;
            previousToCurrentCar->setLinkToNextCar(currentCar);
            
            break;
        }
        else
        {
            previousToCurrentCar = currentCar;
            currentCar = currentCar->getLinkToNextCar();
        }
        
    }
}
Exemplo n.º 2
0
/**
 * Function: parkNewCar()
 * Purpose: Instantiate a new car object and link the node
 * Parameters: No Pramater: NA
 * Class MemberVariable:
 *          carInFront - equivalent to headPointer
 *          currentCar - equivalent to currentPointer
 *          lastCar - equivalent to tailPointer
 *          previousToCurrentCar - equivalent to previous (holds the pointer to the one node prior to current being changed)
 **/
void Parking::parkNewCar()
{
    Car *newCarSmellyCar = getNewCar();
    
    // deal with the very first car...
    if (carInFront == 0 && previousToCurrentCar == 0 && currentCar == 0 && lastCar == 0)
    {
        carInFront = newCarSmellyCar;
        previousToCurrentCar = newCarSmellyCar;
        currentCar = newCarSmellyCar;
        currentCar->setAssignedTicketNumber(getNewTicketNumber());
        currentCar->setLinkToNextCar(0);
        lastCar = newCarSmellyCar;
        
        cout << "License Plate #: " << currentCar << " Ticket #: " << currentCar->getAssignedTicketNumber() << " PARKED" << endl;
        //DEBUG
        //currentPointerStatus();
    }
    else if (!isLotFull())
    {
        lastCar->setLinkToNextCar(newCarSmellyCar);
        previousToCurrentCar = currentCar;
        currentCar = lastCar->getLinkToNextCar();
        currentCar->setAssignedTicketNumber(getNewTicketNumber());
        lastCar = currentCar;
        
        cout << "License Plate #: " << currentCar << " Ticket #: " << currentCar->getAssignedTicketNumber() << " PARKED" << endl;
        
        //DEBUG
        //currentPointerStatus();
    }
    else
    {
        cout << "PARKING LOT IS FULL !" << endl;
    }
    
}