C++实现停车场管理系统(2)

CarSystem::~CarSystem()
{
    QCarNode *ptemp;
    while (CarBase->top != 0)
        CarBase->CarStack[--CarBase->top] = NULL;
    while (WaitQueue->head != WaitQueue->rear)
    {
        ptemp = WaitQueue->head;
        WaitQueue->head = WaitQueue->head->next;
        delete ptemp;
    }
}

int CarSystem::Arrival()    //车辆进站登记
{
    CarNode *p;      //汽车临时指针
    QCarNode *t;      //队列中汽车临时指针
    CTime start_time = CTime::GetCurrentTime();  //获取系统当前时间作为车辆进站时间
    p = new CarNode;   
    cout << "登记车牌号:";
    cin >> p->num;
    if (CarBase->top < MAX)      //有空车位
    {
        CarBase->top++;
        cout << "车辆在停车场第 " << CarBase->top  << " 号车位" ;
        p->reach.year = start_time.GetYear();
        p->reach.month = start_time.GetMonth();
        p->reach.day = start_time.GetDay();
        p->reach.hour = start_time.GetHour();
        p->reach.min = start_time.GetMinute();
        CarBase->CarStack[CarBase->top] = p;
        return 1;
    }
    else          //没有空车位
    {
        cout << "停车场已满,请在便道等待...";
        t = new QCarNode;
        t->data = p;
        t->next = NULL;
        WaitQueue->rear->next = t;
        WaitQueue->rear = t;
        return 1;
    }
}

void CarSystem::Leave()    //车辆出站登记
{
    int item;
    CarNode *p, *t; 
    QCarNode *q;
    if (CarBase->top > 0)      //车站有车时
    {
        while (1)
        {
            cout << "请输入车在车场的位置:";
            cin >> item;
            if (item >= 1 && item <= CarBase->top) break;    //判断输入位置
        }
        while (CarBase->top > item)  //位置不在栈顶的汽车出站
        {
            QuitTemp->top++;
            QuitTemp->CarStack[QuitTemp->top] = CarBase->CarStack[CarBase->top];
            CarBase->CarStack[CarBase->top] = NULL;
            CarBase->top--;
        }

p = CarBase->CarStack[CarBase->top];
        CarBase->CarStack[CarBase->top] = NULL;
        CarBase->top--;

while (QuitTemp->top >= 1)  //当暂时存储汽车的栈结构中有汽车时汽车重新进站
        {
            CarBase->top++;
            CarBase->CarStack[CarBase->top] = QuitTemp->CarStack[QuitTemp->top];
            QuitTemp->CarStack[QuitTemp->top] = NULL;
            QuitTemp->top--;
        }

ShowLeaveInfo(p, item);

if ((WaitQueue->head != WaitQueue->rear) && CarBase->top<MAX)    //停车场有车位且便道有车时,便道中车辆进入停车场
        {
            CTime start_time = CTime::GetCurrentTime();  //获取系统当前时间作为车辆进站时间
            q = WaitQueue->head->next;
            t = q->data;
            CarBase->top++;
            cout << "\n便道的" << t->num << "号车进入车场第" << CarBase->top << "号车位.";
            t->reach.year = start_time.GetYear();
            t->reach.month = start_time.GetMonth();
            t->reach.day = start_time.GetDay();
            t->reach.hour = start_time.GetHour();
            t->reach.min = start_time.GetMinute();

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/51504bb524e497378398263fe3db3c5f.html