C语言完整源码停车场管理系统+文档,制作不易,勿白嫖

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
下面展示一些 内联代码片

参考源码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 定义停车场容量
#define CAPACITY 2
// 车辆信息结构体
typedef struct {
    char city[20]; // 城市名称
    char code[20]; // 编码名称
    char licensePlate[10]; // 车牌号
    int entryYear; // 进入时间的年份
    int entryMonth; // 进入时间的月份
    int entryDay; // 进入时间的日期
    int entryHour; // 进入时间的小时数
    int entryMinute; // 进入时间的分钟数
    int entrySecond; // 进入时间的秒数
    int isParked; // 是否停在停车场中
} CarInfo;
// 获取省份编号
void getProvinceCode(char *city, char *code) {
    if (strcmp(city, "南京") == 0) {
        strcpy(code, "苏A·");
    } else if (strcmp(city, "无锡") == 0) {
        strcpy(code, "苏B·");
    } else if (strcmp(city, "徐州") == 0) {
        strcpy(code, "苏C·");
    } else if (strcmp(city, "常州") == 0) {
        strcpy(code, "苏D·");
    }else if (strcmp(city, "苏州") == 0) {
        strcpy(code, "苏E·");
    } else if (strcmp(city, "南通") == 0) {
        strcpy(code, "苏F·");
    } else if (strcmp(city, "连云港") == 0) {
        strcpy(code, "苏G·");
    }
}
// 查找空闲车位
int findEmptySpace( CarInfo *car) {
    for (int i = 0; i < CAPACITY; i++) {
        if (!car[i].isParked) {
            return i; // 返回空闲车位索引
        }
    }
    return -1; // 所有车位都被占用
}
// 入场操作
void enterParkingLot(CarInfo *car, char *city, char *licensePlate, int entryYear, int entryMonth, int entryDay, int entryHour, int entryMinute, int entrySecond) {
    char code[3];
    getProvinceCode(city, code);
	int emptySpace = findEmptySpace(car); // 查找空闲车位
    if (emptySpace != -1) { // 存在空闲车位
	    strcpy(car[emptySpace].city, city);
        strcpy(car[emptySpace].code, code);
	    strcpy(car[emptySpace].licensePlate, licensePlate);
	    car[emptySpace].entryYear = entryYear;
        car[emptySpace].entryMonth = entryMonth;
        car[emptySpace].entryDay = entryDay;
        car[emptySpace].entryHour = entryHour;
        car[emptySpace].entryMinute = entryMinute;
        car[emptySpace].entrySecond = entrySecond;
        car[emptySpace].isParked = 1;

    printf("车辆 %s%s 已成功入场\n", code, licensePlate);
    } else {
        printf("停车场已满,无法入场,排在便道上等候\n");
    }
}

// 出场操作
void exitParkingLot(CarInfo *car, char *code, char *licensePlate, int exitYear, int exitMonth, int exitDay, int exitHour, int exitMinute, int exitSecond) {
    int index = -1;
    for (int i = 0; i < CAPACITY; i++) {
        if (car[i].isParked && strcmp(car[i].code, code) == 0 && strcmp(car[i].licensePlate, licensePlate) == 0) {
            index = i;
            break;
        }
    }
	if (index != -1) {
        int entryYear = car[index].entryYear;
        int entryMonth = car[index].entryMonth;
        int entryDay = car[index].entryDay;
        int entryHour = car[index].entryHour;
        int entryMinute = car[index].entryMinute;
        int entrySecond = car[index].entrySecond;

        int yearDiff = exitYear - entryYear;
        int monthDiff = exitMonth - entryMonth;
        int dayDiff = exitDay - entryDay;
        int hourDiff = exitHour - entryHour;
        int minuteDiff = exitMinute - entryMinute;
        int secondDiff = exitSecond - entrySecond;

        // 处理时间差的负值情况
        if (secondDiff < 0) {
            minuteDiff--;
            secondDiff += 60;
        }
        if (minuteDiff < 0) {
            hourDiff--;
            minuteDiff += 60;
        }
        if (hourDiff < 0) {
            dayDiff--;
            hourDiff += 24;
        }
        if (dayDiff < 0) {
            monthDiff--;
            dayDiff += 30; // 假设每月30天
        }
        if (monthDiff < 0) {
            yearDiff--;
            monthDiff += 12; // 假设一年有12个月
        }

        double duration = yearDiff * 365 * 24 * 60 * 60 + monthDiff * 30 * 24 * 60 * 60 + dayDiff * 24 * 60 * 60 + hourDiff * 60 * 60 + minuteDiff * 60 + secondDiff; // 计算停车时长

        double fee = 0.0;

        if (duration <= 3600.0) { // 不足1小时按1小时收费
            fee = 10.0;
        } else {
            fee = 10.0 + (duration - 3600.0) / 1800.0 * 5.0; // 超过1小时按每半小时5元收费
        }

        printf("车辆 %s 已成功出场\n", licensePlate);
        printf("停车时长: %.2f小时\n", duration/3600);
        printf("停车费用: %.2f元\n", fee);
        
        car->isParked = 0;
    } else {
        printf("车辆 %s 不在停车场内\n", licensePlate);
    }
}

int main() {
    CarInfo cars[CAPACITY];
    int choice;
    int entryYear, entryMonth, entryDay, entryHour, entryMinute, entrySecond;
    int exitYear, exitMonth, exitDay, exitHour, exitMinute, exitSecond;
    char city[20];
    char code[20];
    char licensePlate[10];
    for (int i = 0; i < CAPACITY; i++) {
        cars[i].isParked = 0; // 初始化停车场车位为空
    }

    do {
        printf("--------------------停车场管理系统 ------------------\n");
        printf("-                1. 进入停车场                      -\n");
        printf("-                2. 离开停车场                      -\n");
        printf("-                3. 退出程序                        -\n");
        printf("-----------------------------------------------------\n");
        printf("请输入您的选择:");
        scanf("%d", &choice);

        switch (choice) {
            case 1:
            	printf("请输入到达:");
                char c[20];
				scanf("%s",c); 
            	printf("请输入车牌号:");
                scanf("%s%s", city, licensePlate);
                printf("请输入车辆进入时间(年 月 日 时 分 秒):");
                scanf("%d %d %d %d %d %d", &entryYear, &entryMonth, &entryDay, &entryHour, &entryMinute, &entrySecond);
                enterParkingLot(cars, city, licensePlate, entryYear, entryMonth, entryDay, entryHour, entryMinute, entrySecond);
                fflush(stdin);
                break;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

徐瑶万正源码,可堪头相,徐福费

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值