用c/c++完成停车场管理系统设计

纯c /c++
停车场管理系统设计
●一、设计内容
停车场有M个入口,P个出口,停车场共有N个车位,其中每5个车位为一个小型立体车库,先来后到原则进行入场,入场后开始进行计费。若停车场满了之后,门口的车一次排队,出来一辆车之后,放行一辆车再入场。要求:
1)每个入口使用队列结构模拟排队场景,排序车辆需要记录排队时间,根据时间先后进场放行。
2)每个小型立体车库只用散列表进行模拟入库及出库。
3)计费原则:15分钟以下免费,超过15分钟按0.5元/15分钟。小型车夜间停车1元/小时。

使用编程语言实现停车场管理系统至少实现:
。数据结构选择合理,能够实现动态输入·能够模拟排队场景
·能够模拟入库及出库、计费等功能。
二、要求 ·界面美观

听你的描述,队列散列表都行

img

img

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#define MAX_CAR_NUM 100 
#define MAX_QUEUE_NUM 5 
#define CAR_TYPE_SMALL 1 
#define CAR_TYPE_BIG 2 

typedef struct Car {
    char license[10]; 
    int type; 
    time_t enter_time; 
    time_t leave_time;
    float fee; 
} Car;

typedef struct Queue {
    Car cars[MAX_CAR_NUM]; 
    int front; 
    int rear; 
} Queue;

typedef struct HashTable {
    Car* cars[MAX_CAR_NUM]; 
} HashTable;

Queue* init_queue() {
    Queue* queue = (Queue*) malloc(sizeof(Queue));
    queue->front = queue->rear = 0;
    return queue;
}

int is_queue_empty(Queue* queue) {
    return queue->front == queue->rear;
}
int get_queue_length(Queue* queue) {
    return (queue->rear - queue->front + MAX_CAR_NUM) % MAX_CAR_NUM;
}

void enqueue(Queue* queue, Car* car) {
    if (get_queue_length(queue) == MAX_CAR_NUM - 1) {
        printf("队列已满,无法入队。\n");
        return;
    }
    queue->cars[queue->rear] = *car;
    queue->rear = (queue->rear + 1) % MAX_CAR_NUM;
}

Car* dequeue(Queue* queue) {
    if (is_queue_empty(queue)) {
        printf("队列为空,无法出队。\n");
        return NULL;
    }
    Car* car = &(queue->cars[queue->front]);
    queue->front = (queue->front + 1) % MAX_CAR_NUM;
    return car;
}

Car* get_front_car(Queue* queue) {
    if (is_queue_empty(queue)) {
        printf("队列为空,无法获取队首车辆。\n");
        return NULL;
    }
    Car* car = &(queue->cars[queue->front]);
    return car;
}

HashTable* init_hash_table() {
    HashTable* hash_table = (HashTable*) malloc(sizeof(HashTable));
    for (int i = 0; i < MAX_CAR_NUM; i++) {
        hash_table->cars[i] = NULL;
    }
    return hash_table;
}

int get_car_position_in_hash_table(HashTable* hash_table, char* license) {
    int pos = atoi(license) % MAX_CAR_NUM;
    while (hash_table->cars[pos] != NULL && strcmp(hash_table->cars[pos]->license, license) != 0) {
        pos = (pos + 1) % MAX_CAR_NUM;
    }
    return pos;
}

void add_car_to_hash_table(HashTable* hash_table, Car* car) {
    int pos = get_car_position_in_hash_table(hash_table, car->license);
    if (hash_table->cars[pos] != NULL) {
        free(hash_table->cars[pos]);
    }
    hash_table->cars[pos] = car;
}

Car* find_car_in_hash_table(HashTable* hash_table, char* license) {
    int pos = get_car_position_in_hash_table(hash_table, license);
    return hash_table->cars[pos];
}

void remove_car_from_hash_table(HashTable* hash_table, char* license) {
    int pos = get_car_position_in_hash_table(hash_table, license);
    if (hash_table->cars[pos] != NULL) {
        free(hash_table->cars[pos]);
        hash_table->cars[pos] = NULL;
    }
}

float calculate_fee(Car* car) {
    int minutes = (int) (car->leave_time - car->enter_time) / 60;
    float fee;
    if (car->type == CAR_TYPE_SMALL) {
        fee = minutes * 0.5;
    } else {
        fee = minutes * 1.0;
    }
    car->fee = fee;
    return fee;
}

int main() {
    Queue* queues[MAX_QUEUE_NUM]; 
    HashTable* hash_table = init_hash_table(); 
    for (int i = 0; i < MAX_QUEUE_NUM; i++) {
        queues[i] = init_queue();
    }
    int entrance_num, exit_num, parking_space_num;
    char name[20];
    printf("请输入停车场名称:");
    scanf("%s", name);
    printf("请输入停车场位置:");
    char location[20];
    scanf("%s", location);
    printf("请输入停车场车位数量:");
    scanf("%d", &parking_space_num);
    printf("请输入停车场小型车位数量:");
    int small_parking_space_num;
    scanf("%d", &small_parking_space_num);
    int parked_car_num = 0; 
    int total_car_num = parking_space_num + small_parking_space_num; 
    while (1) {
        printf("\n请选择操作:\n");
        printf("1. 车辆进入停车场\n");
        printf("2. 车辆离开停车场\n");
        printf("3. 显示当前停车场情况\n");
        printf("4. 退出程序\n");
        int choice;
        scanf("%d", &choice);
        if (choice == 1) {
            if (parked_car_num == total_car_num) {
                printf("停车场已满,请稍后再试。\n");
                continue;
            }
            printf("请输入车牌号:");
            char license[10];
            scanf("%s", license);
            printf("请输入车型(1为小型车,2为大型车):");
            int type;
            scanf("%d", &type);
            Car* car = (Car*) malloc(sizeof(Car));
            strcpy(car->license, license);
            car->type = type;
            car->enter_time = time(NULL);
            int queue_index = parked_car_num % MAX_QUEUE_NUM; 
            if (get_queue_length(queues[queue_index]) < MAX_CAR_NUM) {
                enqueue(queues[queue_index], car);
            } else {
                enqueue(queues[queue_index], car);
                Car* front_car = get_front_car(queues[queue_index]);
                enqueue(queues[queue_index], dequeue(queues[queue_index]));
                add_car_to_hash_table(hash_table, front_car);
            }
            parked_car_num++;
            printf("车辆已进入停车场,停放在第 %d 个入口的第 %d 个位置上。\n", queue_index + 1, get_queue_length(queues[queue_index]));
        } else if (choice == 2) {
            if (parked_car_num == 0) {
                printf("停车场没有车辆,无法进行此操作。\n");
                continue;
            }
            printf("请输入车牌号:");
            char license[10];
            scanf("%s", license);
            Car* car = find_car_in_hash_table(hash_table, license);
            if (car == NULL) {
                printf("停车场中没有该车辆信息。\n");
                continue;
            }
            car->leave_time = time(NULL);
            float fee = calculate_fee(car);
            printf("车辆已离开停车场,停放时长为 %d 分钟,停车费用为 %.2f 元。\n", (int) (car->leave_time - car->enter_time) / 60, fee);
            remove_car_from_hash_table(hash_table, license);
            parked_car_num--;
        } else if (choice == 3) {
            printf("停车场名称:%s\n", name);
            printf("停车场位置:%s\n", location);
            printf("停车场车位数量:%d\n", parking_space_num);
            printf("停车场小型车位数量:%d\n", small_parking_space_num);
            printf("停车场当前情况:\n");
            printf("总车位数:%d,已停放车辆数:%d,空余车位数:%d\n", total_car_num, parked_car_num, total_car_num - parked_car_num);
            printf("各个入口的队列情况:\n");
            for (int i = 0; i < MAX_QUEUE_NUM; i++) {
                printf("第 %d 个入口:", i + 1);
                Queue* queue = queues[i];
                if (is_queue_empty(queue)) {
                    printf("队列为空。\n");
                } else {
                    printf("队列长度为 %d,第一辆车牌号为 %s。\n", get_queue_length(queue), queue->cars[queue->front].license);
                }
            }
            printf("停车场内已停放车辆情况:\n");
            int count = 0;
            for (int i = 0; i < MAX_CAR_NUM; i++) {
                Car* car = hash_table->cars[i];
                if (car != NULL) {
                    printf("第 %d 辆车:车牌号为 %s,车型为 %s,停放时长为 %d 分钟,停车费用为 %.2f 元。\n", ++count, car->license, car->type == CAR_TYPE_SMALL ? "小型车" : "大型车", (int) (car->leave_time - car->enter_time) / 60, car->fee);
                }
            }
        } else if (choice == 4) {
            break;
        } else {
            printf("输入有误,请重新输入。\n");
        }
    }
    return 0;
}


还要ui?

参考

img

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define MAX_CARS 100 // 最大车辆数
#define MAX_QUEUE_SIZE 20 // 每个入口队列的最大长度
#define PARKING_RATE 0.5 // 计费速率

// 车辆结构体
typedef struct {
    int carNumber; // 车牌号
    time_t arrivalTime; // 到达时间
} Car;

// 入口队列结构体
typedef struct {
    Car cars[MAX_QUEUE_SIZE];
    int front;
    int rear;
    int count;
} EntranceQueue;

// 散列表(小型立体车库)
typedef struct {
    Car* slots[MAX_CARS];
} ParkingLot;

// 初始化队列
void initQueue(EntranceQueue* queue) {
    queue->front = 0;
    queue->rear = -1;
    queue->count = 0;
}

// 判断队列是否为空
int isQueueEmpty(EntranceQueue* queue) {
    return queue->count == 0;
}

// 判断队列是否已满
int isQueueFull(EntranceQueue* queue) {
    return queue->count == MAX_QUEUE_SIZE;
}

// 入队
void enqueue(EntranceQueue* queue, Car car) {
    if (isQueueFull(queue)) {
        printf("Queue is full. Car %d cannot enter.\n", car.carNumber);
        return;
    }
    queue->rear = (queue->rear + 1) % MAX_QUEUE_SIZE;
    queue->cars[queue->rear] = car;
    queue->count++;
    printf("Car %d entered the queue.\n", car.carNumber);
}

// 出队
Car dequeue(EntranceQueue* queue) {
    if (isQueueEmpty(queue)) {
        Car emptyCar = {0, 0};
        printf("Queue is empty.\n");
        return emptyCar;
    }
    Car car = queue->cars[queue->front];
    queue->front = (queue->front + 1) % MAX_QUEUE_SIZE;
    queue->count--;
    printf("Car %d exited the queue.\n", car.carNumber);
    return car;
}

// 初始化散列表(小型立体车库)
void initParkingLot(ParkingLot* lot) {
    for (int i = 0; i < MAX_CARS; i++) {
        lot->slots[i] = NULL;
    }
}

// 获取当前时间
time_t getCurrentTime() {
    return time(NULL);
}

// 计算停车时长(分钟)
int calculateParkingDuration(time_t arrivalTime, time_t departureTime) {
    return (int)(difftime(departureTime, arrivalTime) / 60);
}

// 计算停车费用
float calculateParkingFee(int duration) {
    if (duration <= 15) {
        return 0;
    } else {
        return (duration / 15) * PARKING_RATE;
    }
}

// 小型车夜间停车费用
float calculateNightParkingFee(int duration) {
    return duration * 1.0 / 60;
}

int main() {
    EntranceQueue entranceQueue;
    ParkingLot parkingLot;

    initQueue(&entranceQueue);
    initParkingLot(&parkingLot);

    int carCount = 1;
    int carNumber;
    int entranceCount, exitCount, parkingCapacity;
    time_t arrivalTime, departureTime;
    float totalRevenue = 0;

    printf("Enter the number of entrances: ");
    scanf("%d", &entranceCount);
    printf("Enter the number of exits: ");
    scanf("%d", &exitCount);
    printf("Enter the parking capacity: ");
    scanf("%d", &parkingCapacity);

    while (1) {
        printf("\n1. Car Arrival\n");
        printf("2. Car Departure\n");
        printf("3. Exit\n");
        printf("Enter your choice: ");
        int choice;
        scanf("%d", &choice);

        switch (choice) {
            case 1:
                if (!isQueueFull(&entranceQueue)) {
                    printf("Enter car number: ");
                    scanf("%d", &carNumber);
                    arrivalTime = getCurrentTime();
                    Car newCar = {carNumber, arrivalTime};
                    enqueue(&entranceQueue, newCar);
                } else {
                    printf("Parking lot is full. Car cannot enter.\n");
                }
                break;
            case 2:
                if (!isQueueEmpty(&entranceQueue)) {
                    Car car = dequeue(&entranceQueue);
                    departureTime = getCurrentTime();
                    int duration = calculateParkingDuration(car.arrivalTime, departureTime);
                    float fee = calculateParkingFee(duration);
                    printf("Car %d departed. Parking duration: %d minutes\n", car.carNumber, duration);
                    printf("Parking fee: %.2f RMB\n", fee);
                    totalRevenue += fee;
                    parkingLot.slots[car.carNumber] = NULL;
                } else {
                    printf("No cars in the queue.\n");
                }
                break;
            case 3:
                printf("Total revenue: %.2f RMB\n", totalRevenue);
                printf("Exiting the program...\n");
                exit(0);
            default:
                printf("Invalid choice. Try again.\n");
                break;
        }
    }

    return 0;
}

参考GPT


// 汽车信息的结构体 
typedef struct{
    int TimeIn;                    // 进入停车场时间
    int TimeOut;                // 离开停车场时间
    char ct[50];
    char Lincense[10];            // 字符类型 车牌号
}Car;
// 停放车辆的栈 
typedef struct{
    Car Stop[MAX_STOP];            // 用来停放车辆的栈
    int top;                    // 标记栈顶位置
}Stopping;
// 等候队列
typedef struct{
    Car Pave[MAX_PAVE];            // 便道上的队列 
    int count;                    // 标记队列等候车辆个数 
    int front, rear;            // 标记队头和队尾 
}Pavement; 
// 用来让路的栈
typedef struct{
    Car Let[MAX_STOP];            // 用来让路的栈 
    int top;                    // 标记栈顶位置 
}Buffer;                        
// 用来让路的队列
typedef struct{                    
    Car Wait[MAX_PAVE];            // 临时便道的队列
    int count;                    // 标记队列等候车辆个数 
    int front, rear;            // 标记队头和队尾
}Waiting; 
// 声明每个全局变量/结构体 
Stopping s;
Pavement p;
Buffer   b;
Car      c;
Waiting  w;
char     C[10];

void Car_Come();                // 车辆进入函数 
void Car_Leave();                // 车辆离开函数
void Stop_To_Pave();            // 当停车场满时车辆驶入便道
void Stop_To_Buff();            // 有车辆驶出时车辆暂时驶入缓冲栈
void Leave_Pavement();            // 车辆离开便道(说明要出停车场的汽车在便道上)
void DisPlay();                    // 展示停车场内的车辆位序
void DisPlayPave();                // 展示便道上的车辆位序
void Welcome();                    // 显示菜单
void SmallWelcome();
void Car_Leave_menu();
void Search();

// 车辆进入函数 
void Car_Come(){                         
    printf("请输入即将停车的车牌号:");
    scanf("%s", &C);            // 先分别在栈和队列中检测是否已经停入
    int i = s.top;
    while(i != -1){
        if(0 == strcmp(s.Stop[i].Lincense, C)){
            printf("输入有误,此汽车已存在!\n");
            return;
        }
        i--;
    }
    int k = MAX_PAVE;
    while(k != 0){
        if(0 == strcmp(p.Pave[k].Lincense, C)){
            printf("输入有误,此汽车已存在!\n");
            return;
        }
        k--;
    }
    if (s.top >= MAX_STOP - 1){
        Stop_To_Pave();                    // 当停车栈已满,停入便道函数 
    }
    else{
        time_t t1;
        long int t = time(&t1);            // 记录停入时间
        char* t2;                        // 将当前时间转换程字符串 
        t2 = ctime(&t1); 
        s.Stop[++s.top].TimeIn = t;
        strcpy(s.Stop[s.top].ct, t2);
        strcpy(s.Stop[s.top].Lincense, C);        // 登记车牌号 
        printf("牌照为%s的汽车停入停车位的%d车位,当前时间:%s\n", C, s.top+1, t2);
    }
}

// 停车场查找汽车 
void Search(){
    printf("请输入要搜索的车牌号:\n");
    scanf("%s", &C);
    int i, j, k, flag = 0;         // flag用来标记车辆位置,如果在停车场内会置为1 
    time_t t1;
    long int t = time(&t1);
    if(s.top >= 0){
        for(i = s.top; i >= 0; i--){
            if(0 == strcmp(s.Stop[i].Lincense, C)){
            printf("此汽车在停车场内,信息如下:\n");
            printf("\t车牌号\t\t停车位序\t当前所需支付金额\t进入时间\t\n");
            printf("\t%s\t第%d个\t\t%0.f元\t\t\t%s", s.Stop[i].Lincense, i+1, Price * (t - s.Stop[i].TimeIn), s.Stop[i].ct);
            flag = 1;
            break;
            } 
        }
    }
    if(flag == 0 && p.count > 0){         
        i = p.front, k = 1, j = p.rear;            
        while(i != j ){
            if(0 == strcmp(p.Pave[i].Lincense, C)){
                printf("此汽车在停便道上\n");
                printf("\t车牌号\t\t停车位序\n");
                printf("\t%s\t第%d个",p.Pave[i].Lincense, k);
                flag = 2;
                break;
            }
            i++;
            k++;
        }    
    }
    if(0 == flag)
        printf("停车场内外不存在该汽车信息!\n");
    
}

// 车辆离开函数 
void Car_Leave(){                            // 还需要加上检测车辆是否在队列中 
    printf("请输入即将离开的车牌号:");
    scanf("%s", &C);
    int i, j, flag = 1, flag2 = 1;
    if(s.top >= 0){                            // 在停车场栈内寻找该车牌, 
        for(i = s.top; i >=0; i-- ){            // 存在则flag会变为0 
            flag = flag * strcmp(s.Stop[i].Lincense, C);
            i--;
        }
    }

    if(0 == flag){                                    // 当flag == 0 汽车必在停车场栈内 
        Stop_To_Buff();                                // 调用缓冲栈函数 
    }    

    if(flag !=0 /*&& flag2 != 0*/)                        // 此情况说明汽车一定不在停车场内外 
    printf("停车场内没有该汽车的信息!\n"); 
}

// 车辆离开便道(说明要出停车场的汽车在便道上) 
void Leave_Pavement(){
    int i, j, flag = 0;
    printf("请输入即将离开的车牌号:");
    scanf("%s", &C);
    if(p.count  <= 0){
        printf("便道上不存在汽车!\n");
        return;
    }
    while(p.count > 0){                            // 找到该车位置时退出while循环 
        i = p.front; 
        if(0 == strcmp(p.Pave[i].Lincense, C)){
            break;    
        }
        printf("牌照为%s的汽车暂时从便道进入临时便道\n", p.Pave[p.front].Lincense);
        strcpy(w.Wait[w.rear].Lincense, p.Pave[p.front].Lincense);
        p.front = (p.front + 1) % MAX_PAVE;        // 出p队:队头指针的移动 
        w.rear = (w.rear + 1) % MAX_PAVE;        // 入w队:队尾指针的移动 
        w.count++;                                // w.count + 1 
        p.count--;                                // p.count - 1 
    }
    printf("\n牌照为%s的汽车从便道上开走,不收取任何费用!\n\n", p.Pave[i].Lincense); // 让该车辆驶出 
    p.front = (p.front + 1) % MAX_PAVE;
    p.count--;
    while(p.count > 0){                        // 让其后的车辆继续驶入临时便道 
        printf("牌照为%s的汽车暂时从便道进入临时便道\n", p.Pave[p.front].Lincense);
        strcpy(w.Wait[w.rear].Lincense, p.Pave[p.front].Lincense);
        p.front = (p.front + 1) % MAX_PAVE;
        w.rear = (w.rear + 1) % MAX_PAVE;
        w.count++;
        p.count--;
    }
    while(w.count > 0){                        // 将临时便道的车辆全部驶回便道中 
        printf("\n牌照为%s的汽车返回便道\n",w.Wait[w.front].Lincense);
        strcpy(p.Pave[p.rear].Lincense, w.Wait[w.front].Lincense);
        w.front = (w.front + 1) % MAX_PAVE;     
        p.rear = (p.rear + 1) % MAX_PAVE;
        w.count--;
        p.count++;
    }
}

// 车辆暂时驶入缓冲栈 
void Stop_To_Buff(){
    while (s.top >= 0){                            // 当该车为栈顶时退出while循环 
        if(0 == strcmp(s.Stop[s.top].Lincense, C)){
            break;
        }
        strcpy(b.Let[b.top++].Lincense, s.Stop[s.top].Lincense);
        printf("牌照为%s的汽车暂时退出停车场\n", s.Stop[s.top--].Lincense);
    }
    printf("牌照为%s的汽车从停车场开走\n", s.Stop[s.top].Lincense);    // 驶出该车并收费 
    time_t t1;
    long int t = time(&t1);
    s.Stop[s.top].TimeOut = t;
    char* t2;
    t2 = ctime(&t1);
    printf("离开时间%s\n需付费%.0f元\n", t2, Price * (s.Stop[s.top].TimeOut - s.Stop[s.top].TimeIn));
    s.top--;
    while(b.top > 0){
        strcpy(s.Stop[++s.top].Lincense, b.Let[--b.top].Lincense);
        printf("牌照为%s的汽车停回停车位%d车位\n", b.Let[b.top].Lincense, s.top+1);
    }
    while(s.top < MAX_STOP-1){
        if(0 == p.count)
            break;
        else{
            strcpy(s.Stop[++s.top].Lincense, p.Pave[p.front].Lincense);
            printf("牌照为%s的汽车从便道中进入停车位的%d车位\n", p.Pave[p.front].Lincense, s.top+1);
            time_t t1;
            long int t = time(&t1);
            char* t2;
            s.Stop[s.top].TimeIn = t;
            p.front = (p.front + 1) % MAX_PAVE;
            p.count--;
        }
    }
}
// 当停车场满时车辆驶入便道 
void Stop_To_Pave(){
    if(p.count > 0 && (p.front == (p.rear + 1) % MAX_PAVE))
        printf("便道已满,请下次再来!\n");
    else{
        strcpy(p.Pave[p.rear].Lincense, C);
        p.rear = (p.rear + 1) % MAX_PAVE;
        p.count++;
        printf("牌照为%s的汽车停入便道上\n", C);
    }
}

// 展示停车场内的车辆位序
void DisPlay(){
    int i = s.top;
    if(-1 == i)
        printf("停车场目前为空\n");
    time_t t1;
    long int t = time(&t1);
    printf("\t车牌号\t\t停放时间\t当前所需支付金额\t停放位序\n");
    while(i != -1){
        printf("\t%s\t%d分%d秒\t\t%.0f元\t\t\t第%d个\n", s.Stop[i].Lincense, 
        (t - s.Stop[i].TimeIn)/60,(t - s.Stop[i].TimeIn) % 60, Price * (t - s.Stop[i].TimeIn), i+1);
        i--;
    }
}

// 展示便道上的车辆位序 
void DisPlayPave(){
    int i = p.front;
    int k = 1;                        // 用k模拟便道上汽车的位序  /***********/ 
    if(0 == p.count)                   // 0 == p.count 
    printf("便道目前为空\n");
    printf("\t车牌号\t\t停放位序\n");
    while(i != p.rear && k <= p.count){  
        printf("\t%s\t第%d个\n", p.Pave[i].Lincense, k++);
        i = (i + 1) % MAX_PAVE;
    }
}

// 4.汽车离去子菜单
void Car_Leave_menu(){
    while(1){
        system("cls");                        // 清屏 
        SmallWelcome();                            // 重新显示界面 
        int i, cho;
        scanf("%d", &i);
        if(1 == i)  Car_Leave();
        if(2 == i)  Leave_Pavement();
        if(3 == i)  return;
        printf("\n返回请输入0\n");
        top:                                // goto 标志位 
            scanf("%d", &cho);
        if(0 == cho){
            continue;
        }
        else{
            printf("您的输入有误,请重新输入\n");
            goto top;                        // goto 到指定标志位 top
        }
    }    
} 
// 子菜单的welcome 
void SmallWelcome(){
    printf ("\t*******************目前停车场状况***********************\n");
    printf ("\t停车场共有%d个车位,当前停车场共有%d辆车,等候区共有%d/%d辆车\n",  
    MAX_STOP, s.top+1, (p.rear + MAX_PAVE - p.front) % MAX_PAVE, MAX_PAVE-1);
    printf ("\t********************************************************\n");
    printf ("\t---------Welcome to Ep's Car Parking next time----------\n");
    printf ("\t*                                                      *\n");
    printf ("\t*                   1.从停车场内驶出汽车               *\n");
    printf ("\t*                   2.从便道上驶出汽车                 *\n");
    printf ("\t*                   3.退出子管理系统                   *\n");
    printf ("\t*请注意:从停车场内驶离的汽车按照%.0f元/分钟计费          *\n",60*Price);
    printf ("\t*望周知:从便道上驶离的汽车不收取费用                  *\n");
    printf ("\t*                                                      *\n");
    printf ("\t*------------------------------------------------------*\n");
    printf ("\t--------Press key(1/2/3) to continue the program--------\n");
}
void HideCursor(){
 CONSOLE_CURSOR_INFO cursor_info = {1, 0};
 SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
// 显示菜单 
void Welcome(){
    time_t rawtime;
    struct tm * timeinfo;
    time ( &rawtime );
    timeinfo = localtime ( &rawtime );
    printf ("\t\t\t%s", asctime(timeinfo) );
    HideCursor();
    printf ("\t*******************目前停车场状况***********************\n");
    printf ("\t停车场共有%d个车位,当前停车场共有%d辆车,等候区共有%d/%d辆车\n",  
    MAX_STOP, s.top+1, (p.rear + MAX_PAVE - p.front) % MAX_PAVE, MAX_PAVE-1);
    printf ("\t********************************************************\n");
    printf ("\t--------------Welcome to Ep's Car Parking---------------\n");
    printf ("\t*                                                      *\n");
    printf ("\t*                   1.停车场停车信息显示               *\n");
    printf ("\t*                   2.便道上停车信息显示               *\n");
    printf ("\t*                   3.汽车到达停车场操作               *\n");
    printf ("\t*                   4.汽车离去停车场操作               *\n");
    printf ("\t*                   5.查找汽车功能                     *\n");
    printf ("\t*                   6.退出管理系统                     *\n");
    printf ("\t*收费标准:本停车场按照%.0f元/分钟计费,望周知            *\n",60*Price);
    printf ("\t*                                                      *\n");
    printf ("\t*------------------------------------------------------*\n");
    printf ("\t---------Press key(1/2/3/4/5/6) to run program----------\n");
    
}

int main(){
    s.top = -1;
    b.top = 0;
    p.rear = 0;
    p.count = 0;
    p.front = 0;
    w.count = 0;
    w.front = 0;
    w.rear = 0;
    while(1){
        system("color 0B");
        system("cls");                        // 清屏 
        Welcome();                            // 重新显示界面 
        int i, cho;
        scanf("%d", &i);
        if(1 == i)  DisPlay();
        if(2 == i)  DisPlayPave();
        if(3 == i)  Car_Come();
        if(4 == i)  Car_Leave_menu();            //汽车离去:停车场内和便道上 
        if(5 == i)  Search();
        if(6 == i)  {
                        printf("\n欢迎您再次使用本系统呦 ε=ε=ε=(~ ̄▽ ̄)~\n\n");
                        break;
                    } 
        printf("\n返回请输入0\n");
        begin:                                // goto 标志位 
            scanf("%d", &cho);
        if(0 == cho){
            continue;
        }
        else{
            printf("您的输入有误,请重新输入\n");
            goto begin;                        // goto 到指定标志位 begin
        }
    }
    return 0;
}



名字:linuas
密码:111111
代码:

#include <iostream>
#include <ctime>
#include <string>
#include <stdio.h>
#include <conio.h>
#include <cstdlib>
#include <windows.h>
#include <iomanip>
#include <fstream>
using namespace std;
void mainspace();//主界面,功能界面
void stop();//停车子函数
void move();//取车子函数
void check();//检查当前库存情况子函数
int money(int n);//计时收费子函数
void code();//密码登陆子函数
string hide(int size);//输入密码输出*子函数
int park[10] = { 1,1 };//停车位序号,此时txt里预设了两组数据
struct pay //返回自定义值
{
    int timemin;
    int money;
}pay1;
int main()
{
    SetConsoleTitle("Stop Cars");//标题
    while (1) {
        time_t now = time(0);
        tm *ltm = localtime(&now);
        cout << 1900 + ltm->tm_year << "." << 1 + ltm->tm_mon << "." << ltm ->tm_mday << endl;
        cout << ltm->tm_hour << ":" << ltm->tm_min << endl;//输出时间
        code();
        mainspace();
        Sleep(60000);//一段时间不操作返回初始界面
        system("cls");
    }
}
void mainspace()
{
    cout << "功能" << endl;
    cout << "1.停车" << endl;
    cout << "2.取车" << endl;
    cout << "3.查询" << endl;
    int x;
    cin >> x;
    switch (x)
    {
    case 1:stop(); break;
    case 2:move(); break;
    case 3:check(); break;
    }
}
void code()
{
    string name = "linuas";
    string pw = "111111";
    string name1;
    string code;
    while (1)
    {
        cout << "请输入用户名:" << endl;
        cin >> name1;
        if (strcmp(name1.c_str(), name.c_str()) == 0)
        {
            system("cls");
            cout << "请输入密码:" << endl;
            code = hide(7);
            if (strcmp(pw.c_str(), code.c_str()) == 0)
            {
                system("cls");
                cout << "登陆成功!" << endl;
                Sleep(2000);
                break;
            }
            else cout << endl << "密码错误!" << endl;
            Sleep(2000);
            system("cls");
            continue;
        }
        else cout << endl << "用户名不存在!" << endl;
        Sleep(2000);
        system("cls");
        continue;
    }
}
string hide(int size)
{
    char c;
    int count = 0;
    char *password = new char[size]; // 动态申请空间
    string str;
    while ((c = _getch()) != '\r') {

        if (c == 8) { // 退格
            if (count == 0) {
                continue;
            }
            putchar('\b'); // 回退一格
            putchar(' '); // 输出一个空格将原来的*隐藏
            putchar('\b'); // 再回退一格等待输入
            count--;
        }
        if (count == size - 1) { // 最大长度为size-1
            continue;
        }
        if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <=            '9')) {  // 密码只可包含数字和字母
            putchar('*');  // 接收到一个字符后, 打印一个*
            password[count] = c;
            count++;
        }
    }
    password[count] = '\0';
    str = password;
    return str;
}
void stop()
{
    int n = 0;
    int i = 0;
    string str;
    time_t now = time(0);
    tm *ltm = localtime(&now);//获取当前系统时间准备写入
    cout << "请输入车牌号:" << endl;
    cin >> str;
    for (i = 0; i < 10; i++)//车位序号存在与否判定
    {
        if (park[i] != 1)
        {
            n = i;
            break;
        }
        else continue;
    }
    park[n] = 1;
    ofstream outfile("C:\\Users\\Linuas\\Desktop\\demo.txt", ios::app);//写入文件式打开
    outfile << endl << n << " " << str << " " << (1900 + ltm->tm_year) * 10000 + (1 + ltm->tm_mon) * 100 +ltm->tm_mday << " " << (ltm->tm_hour) * 100 + ltm->tm_min;
    outfile.close();//写入成功后关闭文件,切记!
    cout << "停车成功" << endl;
    Sleep(2000);
    mainspace();
}
void check()
{
    ifstream myfile("C:\\Users\\Linuas\\Desktop\\demo.txt");
    string temp;
    cout << "车位 " << "车牌号 " << "停车时间" << endl;
    while (getline(myfile, temp))
    {
        cout << temp << endl;
    }
    myfile.close();
    mainspace();
}
void move()
{
    ifstream file("C:\\Users\\Linuas\\Desktop\\demo.txt");
    string line;
    int m, n, count = 0;
    ofstream outfile("test2.txt", ios::out | ios::trunc);
    cout << "您停车的车位是:" << endl;
    cin >> m;
    n=money(m)+1;
    n = m + 1;
    while (!file.eof()) {
        getline(file, line);
        if (count != n - 1)//保留行
            outfile << line << endl;
        count++;
    }
    outfile.close();
    file.close();
    ofstream outfile1("C:\\Users\\Linuas\\Desktop\\demo.txt", ios::out | ios::trunc);
    fstream file1("test2.txt");
    while (!file1.eof()) {
        getline(file1, line);
        outfile1 << line << endl;
    }
    outfile1.close();
    file1.close();
    system("del test2.txt");//删除中间文件
    Sleep(2000);
    mainspace();
}
int money(int n)
{
    fstream infile;
    infile.open("C:\\Users\\Linuas\\Desktop\\demo.txt", ios::in);
    string line;
    int count = 0;
    int a, b, c, d;
    int b1, b2, c1, c2;
    if (n == 0) { infile >> a >> line >> b >> c; }
    else
    {
        while (!infile.eof()) {
            getline(infile, line);//自动回车了一次
            if (count == n - 1)
            {
                infile >> a >> line >> b >> c;
            }
            count++;
        }
    }
    infile.close();
    d = b % 10000;
    b1 = d % 100;
    b2 = (d - b1) / 100;
    c1 = c % 100;
    c2 = (c - c1) / 100;
    time_t now = time(0);
    tm *ltm = localtime(&now);
    pay1.timemin = (1 + ltm->tm_mon - b2) * 31 * 24 * 60 + (ltm->tm_mday - b1) * 24 * 60 + (ltm->tm_hour -        c2) * 60 + ltm->tm_min - c1;
    if (pay1.timemin <= 15)
    {
        pay1.money = 10;
    }
    else if (pay1.timemin <= 60)
    {
        pay1.money = 10 + pay1.timemin - 15;
    }
    else pay1.money = 60;
    cout << "停车时间为" << pay1.timemin << "分钟" << endl;
    cout << "计时收费为" << pay1.money << "元" << endl;
    Sleep(2000);
    return n;
}

这个系统要求比较复杂了,界面可以用QT或者wxWidgets这两个UI库来实现

c实现停车场管理系统设计,总体来看,功能不难,主要是输入输出和基本的逻辑处理。给你找个资料,有完整的代码。
https://blog.csdn.net/qq_42562989/article/details/129223232
这个代码实现了一个基本的停车场管理系统,包括停车、结算费用和显示停车记录等功能。你可以根据自己的需求修改代码,添加更多功能。

11111111111111111

这是一个比较复杂的系统,需要用到多种数据结构和算法来实现。下面是一个简单的停车场管理系统的设计思路:

停车场包含M个入口和P个出口,可以使用队列来模拟排队场景。每个入口维护一个队列,车辆进入队列时记录进入时间。当有车辆出场时,从队列中选择最早进入的车辆放行。可以使用优先队列来维护车辆的排队顺序。

停车场共有N个车位,其中每5个车位为一个小型立体车库,可以使用散列表来模拟入库和出库。散列表中可以使用车位编号作为键,记录车辆的信息。当车辆进入小型立体车库时,将车辆信息插入到散列表中,并将车位标记为已占用。当车辆出库时,从散列表中删除车辆信息,并将车位标记为未占用。

计费原则可以使用一个简单的算法来实现。当车辆出场时,计算停车时间,如果小于等于15分钟则不收费。否则,按照停车时间向上取整到15分钟的倍数,计算费用。对于小型车夜间停车收费,可以在计费时判断停车时间是否在夜间,如果是则按照1元/小时计费。

界面可以使用Qt框架来实现,Qt提供了丰富的GUI组件和界面设计工具,可以快速构建美观的用户界面。可以使用Qt的信号和槽机制来实现界面和后台逻辑的交互。

引用gpt4:


#include <iostream>

#include <queue>

#include <vector>

#include <map>

#include <ctime>

using namespace std;



// 定义车位类型

struct ParkingSpace {

    int id; // 车位编号

    int is_occupied; // 是否被占用

    int time_entered; // 进入时间

    int time_left; // 离开时间

};



// 定义入口类型

struct Entrance {

    int id; // 入口编号

    queue<ParkingSpace> parking_spaces; // 存储等待入场的车辆信息

};



// 定义小型立体车库类型

struct SmallParkingGarage {

    int id; // 小型立体车库编号

    int capacity; // 容量(车位数)

    int occupied_spaces; // 已占用的车位数

    map<int, int> spaces_used; // 已使用的车位编号和对应的入库时间

};



// 定义停车场管理类

class ParkingLotManager {

public:

    ParkingLotManager(int m, int p, int n) : entrances(m), garages(p), parking_lot(n) {}

    ~ParkingLotManager() {}

    

    void addEntrance(int id) { entrances.push_back(Entrance()); }

    void addGarage(int id, int capacity) { garages.push_back(SmallParkingGarage()); }

    int parkCar(int entrance_id, int garage_id, int car_id) {

        Entrance& entrance = entrances[entrance_id];

        SmallParkingGarage& garage = garages[garage_id];

        

        if (entrance.parking_spaces.size() >= parking_lot.size()) return -1; // 如果停车场已满,则无法停车,返回-1表示失败

        

        int space_id = random() % parking_lot.size(); // 在剩余车位中随机选择一个空闲车位进行停车

        int time_entered = time(NULL); // 记录进入时间

        parking_lot[space_id].is_occupied = true; // 将该车位标记为已占用状态

        parking_lot[space_id].time_left = time_entered + (5 * (random() % (600/5) + 1)); // 根据先来后到原则计算该车位的离开时间,并将该车位标记为已离开状态

        entrance.parking_spaces.push(ParkingSpace{car_id, space_id, time_entered, time_left}); // 将该车辆信息加入队列中等待入场放行操作

        garage.occupied_spaces++; // 该小型立体车库已占用一个车位

        garage.spaces_used[car_id] = time_entered; // 将该车辆的信息和入库时间保存在散列表中,用于后续出库操作时查找对应信息的时间戳

        return space_id; // 返回该车辆所停放的车位编号,便于后续出库操作时查找对应位置的车位信息

    }

    int leaveCar(int entrance_id, int garage_id, int car_id) {

        Entrance& entrance = entrances[entrance_id];

        SmallParkingGarage& garage = garages[garage_id];

        
        if (!entrance.parking_spaces.front().is_occupied || entrance.parking_spaces.front().time_left <= time(NULL)) return -1; // 如果该车辆没有停车或者已经离开了停车场,则无法出库,返回-1表示失败

        

        int space_id = entrance.parking_spaces.front().id; // 从队列头部取出该车辆的信息,获取其停车的车位编号和进入停车场的时间戳等信息

        int time_left = parking_lot[space_id].time_left; // 根据该车辆在队列中的先后顺序和先来后到原则计算其离开停车场的时间戳,并将该车位标记为已离开状态

        parking_lot[space_id].is_occupied = false; // 将该车位标记为未占用状态,准备给其他车辆使用

        entrance.parking_spaces.pop(); // 从队列头部弹出该车辆的信息,释放其占用的车位资源,准备给其他车辆使用

        garage.occupied_spaces--; // 该小型立体车库已释放一个车位资源,准备给其他车辆使用解

回答部分参考、引用ChatGpt以便为您提供更准确的答案:

为了制定工厂的工作安排,使得生产n件产品的总时长最少,可以使用贪心算法来解决该问题。下面是一种可能的解决方案:

  1. 将所有产品按照其第一道工序的耗时进行排序,耗时最短的产品排在前面。
  2. 初始化一个空的工作队列。
  3. 依次将产品加入工作队列,并根据其第二道工序的耗时插入到队列中适当的位置,使得工作队列中的产品按照第二道工序的耗时从小到大有序排列。
  4. 继续按照上述方式,将产品插入到工作队列中适当的位置,使得工作队列中的产品按照第三道工序的耗时从小到大有序排列。
  5. 当所有产品都加入到工作队列后,按照顺序处理工作队列中的产品,计算总的加工时间。
  6. 返回总的加工时间作为最优的加工顺序。

为了比较程序的运行时间,可以选择不同的n值进行测试,至少给出3组运行数据。例如,可以选择n为10、100和1000,并记录每组数据的运行时间。通过对比运行时间,可以评估程序在不同规模下的性能。

需要注意的是,由于我是一个文本模型,无法直接运行程序并测量运行时间。您需要根据上述思路编写相应的代码,并使用适当的编程语言来实现工厂流水线工作安排。