QT 停车场管理系统

发布于:2023-07-04 ⋅ 阅读:(163) ⋅ 点赞:(0)

 源码链接:

QT停车场管理系统,有图形界面-C++文档类资源-CSDN下载

停车场管理模拟商场的地下停车场,有一个入口、一个出口,在入口前有便道,如果车库满了, 可以在便道上排队等候。 自己定义停车场内部的车位数,便道上的等候数。停车场内部不要求先来先走,也不要求先来后走, 所以停车场内部可以不用堆栈,也可以不用队列,设置一个数组即可。便道必须是队列, 先来等候的车先进停车场。完成入库、出库、查询等工作。

可实现功能:(1)如果停车场内部有空位置, 则便道上的车就直接进停车场停车, 进停车场时记录入库的时间、车牌号、停的车位号

         (2)  如果停车场满了,则在便道上等候, 如果便道上也满了, 则提示满了,不能入库也不能等候

        (3)停车场的任一位置上的车可以出库, 出库时计算停车费,提示停车费用,如果这时在便道上有等候的车辆, 则便道上的第一辆车进停车场入库

      (4)可以查看某一车位上的车辆的信息, 也可以查看整个停车场的统计数据(如: 停车场内有多少量车? 有多少个空位置?)

      (5)要有界面, 要有动画演示入库和出库的动作,希望每一个车位的大小是可调整的, 即根据停车位数量的不同,每个车位的大小随之改变

代码思想:1.停车场定义为结构体数组

2.便道定义为队列,队列元素为字符串

3.定义三个功能:驶入,驶出,和查询功能

.h函数

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include<iostream>
#include<iomanip>
#include<malloc.h>
#include<time.h>
#include<qqueue.h>
#include<queue>
using namespace std;
//#define Price     1			//每秒的单价
#define MAX_STOP  2
#define MAX_PAVE  2
//数组中还有一个空闲单元时,就认为这个队列已经满了
typedef string  ElemType;


typedef struct{
    long TimeIn;					// 进入停车场时间
    long TimeOut;				// 离开停车场时间
    int price;
    string  Lincense;	// 字符类型 车牌号
    int flag;                   //记录此时汽车所处状态,0代表在停车场,1代表在便道
}Car;



QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
    Car lot[MAX_STOP];
    queue<string>  p;
    int  Price=6;
   
private:
    Ui::Widget *ui;
   // QDialog *in;
};
#endif // WIDGET_H

.cpp函数(仅列出将汽车开入停车场和队列的代码),想要获得全部代码,关注点赞私信即可。

#include "widget.h"
#include "ui_widget.h"
#include<QtDebug>
#include <QPushButton>
#include<QDialog>
#include<QLabel>
#include<QTextBlock>
#include<QLineEdit>
#include<iostream>
#include<iomanip>
#include<malloc.h>
#include<time.h>
#include<queue>
#include<qqueue.h>
using namespace std;
//#define Price    6			//每秒的单价
#define MAX_STOP  2
#define MAX_PAVE  2


//定义停车场全局变量
//每个汽车是一个结构体
//停车场是结构体数组
//便道是一个队列,队列元素是汽车结构体


//汽车信息结构体


//停车场数组



Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    this->setFixedSize(1500,800);

//int Price=6;
    //初始化停车场
    for (int i=0;i<MAX_STOP;i++) {
        lot[i].flag=2;
    }




    //向停车场开入车
    connect(ui->IN,&QPushButton::clicked,[=]{
        //获取停车场内现有车的个数
        int t1=0;

         //遍历结构体数组
        for (int i=0;i<MAX_STOP;i++) {
          if(lot[i].flag!=2){
             t1++;
          }

        }
       qDebug()<<t1;
        qDebug()<<p.size();
        //当停车场还有车位时且便道还有位置时
        if(t1<=MAX_STOP&&p.size()<=MAX_PAVE)
       { QDialog *in=new QDialog(this);
            in->setModal(false);
            in->setFixedSize(800,600);
            in->setWindowTitle("开入汽车");
            in->show();
           QLabel *l1=new QLabel(in);
           l1->setFixedSize(100,100);
           l1->move(100,100);
           l1->setVisible(true);
           l1->setText("车牌号");

            l1->adjustSize();

           QLineEdit *l2=new QLineEdit;
           l2->setFixedSize(200,100);
           l2->move(200,100);
           l2->setParent(in);
           l2->setVisible(true);
            //in->show();
           QLabel *ll=new QLabel(in);
           ll->setFixedSize(300,200);
           ll->move(100,300);
           ll->adjustSize();
           ll->setWordWrap(true);
           if(t1==MAX_STOP){
             ll->setText("当前停车场已满,车只能停入便道");
           }
           else{
               ll->setText("停车场仍有空位,可以停进停车场");
           }
           ll->setVisible(true);
           QString str=l2->text();
           string t2=str.toStdString();

            QPushButton *l3=new QPushButton(in);
            l3->setFixedSize(100,50);
            l3->move(500,400);
            l3->setText("确定");
            l3->setVisible(true);
//            for (int i=0;i<MAX_STOP;i++) {
//              if(strcmp( t2.c_str(), lot[i].Lincense.c_str() ) == 0){
//                 l3->setVisible(false);
//              }
//              }
           // l3->setVisible(true);
            QPushButton *l4=new QPushButton(in);
            l4->setFixedSize(100,50);
            l4->move(700,400);
            l4->setText("取消");
            l4->setVisible(true);

            //点击确认按钮后的操作
            connect(l3,&QPushButton::clicked,[=]{

                if(t1==MAX_STOP){
                     p.push(t2);

                }
                else{
                   // enqueue(&p,t2);
                    for (int i=0;i<MAX_STOP;i++) {
                      if(lot[i].flag==2){
                        lot[i].Lincense=t2;
                        lot[i].TimeIn=time(NULL);
                        lot[i].flag=0;
                       break;
                      }

                    }
                }
                int t3=0;
                for (int i=0;i<MAX_STOP;i++) {
                  if(lot[i].flag!=2){
                     t3++;
                  }

                }
                qDebug()<<str ;
                qDebug()<<t3;
                //qDebug()<<lot[i].TimeIn;
                in->close();
            });
    }

        else{
            QDialog *full=new QDialog(this);
                        full->setModal(false);
                        full->setFixedSize(800,600);
                        full->setWindowTitle("开入汽车");
                        full->show();
                       QLabel *l5=new QLabel(full);
                       l5->setFixedSize(200,200);
                       l5->move(100,100);
                       l5->setVisible(true);
                       l5->setFont(QFont("宋体",40));
                       l5->setText("当前便道和车位已满");

                       QPushButton *l6=new QPushButton(full);
                       l6->setFixedSize(100,50);
                       l6->move(500,400);
                       l6->setText("确定");
                       l6->setVisible(true);
                       connect(l6,&QPushButton::clicked,[=]{
                           full->close();
                       });
        }
    });










仅列出部分运行图片

源码连接QT停车场管理系统,有图形界面-C++文档类资源-CSDN下载


网站公告

今日签到

点亮在社区的每一天
去签到