实验六 智能停车系统设计 (综合类)含源码 福利

news2024/10/7 6:24:17

某停车场停车费用计算规则如下:

①每小时 10 元,不足 1 小时的部分按照 1 小时计算;
②超过 8 小时,未超过 24 小时的按照 8 小时计算;
③超过 24 小时,超过部分按照上述标准重新计算。
本程序的任务是模拟一个智能停车管理系统,可以进行汽车停车入库、出场结算、数据导入、数据导出、查询、排序、停车费用汇总、僵尸车统计、输出显示、异常处理等操作,具体要求如下:
入库:输入车牌号码和入场时间(入场时间由相关时间函数自动获取并处理),完成停车入库操作。
注:某车牌已入场则不允许再次进行入库操作;若某车牌号码已经完成入场、出场操作,允许其再次入场。
出库:输入车牌号码、出场时间(出场时间由相关时间函数自动获取并处理)和停车时长,完成出库、停车费用结算。
3、数据导入:实现停车信息从文件parkingLot.txt 读入。
4、数据导出:将停车信息存放到文件 parkingLot_new.txt 中。
5、查询:查找车辆停车信息(不查找已出场的停车信息)。
6、排序:对所有停车信息,按入场时间从前到后排序,排序算法不限。
7、停车费用汇总:计算停车场目前总收入(还没有出场结算的不计算在内)。
8、僵尸车统计:遍历已有停车信息,查找停车 7 天及以上还未出场的车辆,显示僵尸车列表。
注:停车场中超过 7 天还未出场的车辆称为僵尸车,这种车辆未来很可能继续滞留在停车场,造成车位紧张,需要进行统计以便及时处理(异常车辆摸排)。
运行界面及部分结果如下:
在这里插入图片描述

测试文件参考如下

1 沪A7828 2023-07-29:12:36:00 2023-07-29:18:48:00 6.2 70
2 沪B6826 2023-07-24:08:08:00 2023-07-25:11:54:00 27.9 120
3 浙B0529 2023-07-25:12:25:00 2023-07-27:20:49:00 56.4 240
4 沪D9855 2023-07-23:07:17:00 2023-07-24:12:22:00 29.1 140
5 浙A1234 2023-07-28:08:38:00 0 0 0
6 皖B5678 2023-07-30:10:27:00 0 0 0
7 沪A7299 2023-08-02:14:55:00 0 0 0

程序框架参考如下:

#include <stdio.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#define MAX_CAPACITY 100
struct ParkingRecord
{
    int id;             //停车入库单号 ,从1开始 
    char licenseNum[10];//车牌号码 
    char timeIn[20];    //停车入场时间 
    char timeOut[20];   //停车出场时间
    float parkTime;     //停车时长
    int cost;           //停车费用 
};
time_t get_timestamp(char* time_str)//日期格式转时间戳
{
    struct tm tm;//时间结构体
    time_t timestamp;//时间类型,表示1970.01.01到特定日期的秒数
    int a;//sscanf的返回值,不给返回值会警告
    a = sscanf(time_str, "%d-%d-%d:%d:%d:%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min,&tm.tm_sec);//将数据写入结构体
    //与时间戳相对应的时间结构体中tm_year的值从1900开始,tm_mon的取值范围是[0,11],故转时间戳前要将实际年份减去1900,实际月份减去1,之后才能转成正确的时间戳
    tm.tm_year -= 1900;
    tm.tm_mon -= 1;
    timestamp = mktime(&tm);//转时间戳
    return timestamp;
}
int search(struct ParkingRecord parkingLot[],int n,char licenseNum[])//函数功能:查找车辆停车信息(不查找已出场的停车信息)。
{
   
}
int parkCar(struct ParkingRecord parkingLot[],int n)//函数功能:输入车牌号码和入场时间(入场时间由相关时间函数自动获取并处理),完成停车入库操作。
{
   
}
int charge(int hours)//函数功能:按照费用计算规则计算停车费用

{
   
}
void checkOutCar(struct ParkingRecord parkingLot[],int n,char licenseNum[10])//函数功能:输入车牌号码、出场时间(出场时间由相关时间函数自动获取并处理)和停车时长,完成出库、停车费用结算。 

{
    
}
void ShowRecords(struct ParkingRecord parkingLot[],int n)//函数功能:显示所有停车信息。 

{
}
int import_data(struct ParkingRecord parkingLot[])//函数功能:实现停车信息从文件parkingLot.txt 读入。

{ 
}
void save_data(struct ParkingRecord parkingLot[], int n)//函数功能:将停车信息存放到文件 parkingLot_new.txt 中(为测试方便保留原parkingLot.txt中的数据)。

{ 
   
}
void sort(struct ParkingRecord parkingLot[],int n)//函数功能:对所有停车信息,按入场时间从前到后排序,排序算法不限。

{
   
}
int sum(struct ParkingRecord parkingLot[],int n)//函数功能:计算停车场目前总收入(还没有出场结算的不计算在内)。

{
    
} 
void abnormal_data(struct ParkingRecord parkingLot[],int n)//函数功能:遍历已有停车信息,查找停车 7 天及以上还未出场的车辆,显示僵尸车列表。
{
   
}
void display_data(struct ParkingRecord parkingLot[],char licenseNum[],int n)//函数功能:输入车牌号,输出显示该车辆的所有停车记录。 

{
    
}
void menu(void)//菜单显示 
{
    printf("\n 智能停车系统\n 1:显示\n 2:查找\n 3:停车入库\n 4:出库结算\n 5:计算总费用\n 6:排序\n 7:导出\n 8异常车辆摸排\n 0:退出\n");
}
int main(void)
{
    struct ParkingRecord parkingLot[MAX_CAPACITY];//存放停车信息的结构体数组
    int parkCout=0;//停车记录数 
    char licenseNum[10];
    int choice,total;
    menu(); 
    parkCout=import_data(parkingLot);//数据初始化 ,从文本文件导入 
    ShowRecords(parkingLot,parkCout);
    while(1)
    {
        printf("请输入你的选择(0~8):");
        scanf("%d",&choice);
        if(choice==0)
        {
            printf("谢谢使用!\n");
            break;
        } 
        else if(choice==1)
        {
            
            ShowRecords(parkingLot,parkCout);
        }
        else if(choice==2)
        {
            printf("请输入你要查找的车牌号码:");
            scanf("%s",licenseNum);
            display_data(parkingLot,licenseNum,parkCout);
        }
        else if(choice==3)
        {
            parkCout=parkCar(parkingLot,parkCout);
        }
        else if(choice==4)
        {
            printf("请输入要出库结算的车牌号码:\n");
            scanf("%s",licenseNum);
            checkOutCar(parkingLot,parkCout,licenseNum);
        }
        else if(choice==5)
        {
            total=sum(parkingLot,parkCout);
            printf("停车场目前总收入为%d元\n",total);
        }
        else if(choice==6)
        {
            sort(parkingLot,parkCout);
            save_data(parkingLot,parkCout);
            ShowRecords(parkingLot,parkCout);
        }
        else if(choice==7)
        {
            save_data(parkingLot,parkCout);
        }
        else if(choice==8)
        {
            abnormal_data(parkingLot,parkCout);
        }
    }
   return 0;
}
 


完整源码

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

#define MAX_CAPACITY 100

struct ParkingRecord {
    int id;             // 停车入库单号,从1开始
    char licenseNum[10];// 车牌号码
    char timeIn[20];    // 停车入场时间
    char timeOut[20];   // 停车出场时间
    float parkTime;     // 停车时长
    int cost;           // 停车费用
};

time_t get_timestamp(char* time_str) {
    struct tm tm;
    time_t timestamp;
    int a;
    a = sscanf(time_str, "%d-%d-%d %d:%d:%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
    tm.tm_year -= 1900;
    tm.tm_mon -= 1;
    timestamp = mktime(&tm);
    return timestamp;
}

int search(struct ParkingRecord parkingLot[], int n, char licenseNum[]) {
    for (int i = 0; i < n; i++) {
        if (strcmp(parkingLot[i].licenseNum, licenseNum) == 0 && parkingLot[i].timeOut[0] == '\0') {
            return i;
        }
    }
    return -1;
}

int parkCar(struct ParkingRecord parkingLot[], int n) {
    if (n >= MAX_CAPACITY) {
        printf("停车场已满,无法入库!\n");
        return n;
    }
    struct ParkingRecord newRecord;
    newRecord.id = n + 1;
    printf("请输入车牌号码:");
    scanf("%s", newRecord.licenseNum);
    if (search(parkingLot, n, newRecord.licenseNum) != -1) {
        printf("该车牌已入场,不允许再次入库!\n");
        return n;
    }
    time_t now = time(NULL);
    strftime(newRecord.timeIn, 20, "%Y-%m-%d %H:%M:%S", localtime(&now));
    newRecord.timeOut[0] = '\0';
    newRecord.parkTime = 0;
    newRecord.cost = 0;
    parkingLot[n] = newRecord;
    printf("车牌 %s 已入库,入场时间:%s\n", newRecord.licenseNum, newRecord.timeIn);
    return n + 1;
}

int charge(int hours) {
    if (hours <= 8) {
        return hours * 10;
    } else if (hours <= 24) {
        return 80;
    } else {
        return 80 + charge(hours - 24);
    }
}

void checkOutCar(struct ParkingRecord parkingLot[], int n, char licenseNum[10]) {
    int index = search(parkingLot, n, licenseNum);
    if (index == -1) {
        printf("未找到该车牌的入场记录!\n");
        return;
    }
    time_t now = time(NULL);
    strftime(parkingLot[index].timeOut, 20, "%Y-%m-%d %H:%M:%S", localtime(&now));
    time_t timeIn = get_timestamp(parkingLot[index].timeIn);
    parkingLot[index].parkTime = difftime(now, timeIn) / 3600.0;
    parkingLot[index].cost = charge(ceil(parkingLot[index].parkTime));
    printf("车牌 %s 已出库,出场时间:%s,停车时长:%.2f小时,费用:%d元\n", 
           parkingLot[index].licenseNum, parkingLot[index].timeOut, parkingLot[index].parkTime, parkingLot[index].cost);
}

void ShowRecords(struct ParkingRecord parkingLot[], int n) {
    printf("停车记录如下:\n");
    for (int i = 0; i < n; i++) {
        printf("ID: %d, 车牌: %s, 入场时间: %s, 出场时间: %s, 停车时长: %.2f小时, 费用: %d元\n", 
               parkingLot[i].id, parkingLot[i].licenseNum, parkingLot[i].timeIn, parkingLot[i].timeOut, parkingLot[i].parkTime, parkingLot[i].cost);
    }
}

int import_data(struct ParkingRecord parkingLot[]) {
    FILE *file = fopen("parkingLot.txt", "r");
    if (!file) {
        printf("无法打开文件 parkingLot.txt\n");
        return 0;
    }
    int count = 0;
    while (fscanf(file, "%d %s %s %s %f %d", &parkingLot[count].id, parkingLot[count].licenseNum, parkingLot[count].timeIn, parkingLot[count].timeOut, &parkingLot[count].parkTime, &parkingLot[count].cost) != EOF) {
        count++;
    }
    fclose(file);
    return count;
}

void save_data(struct ParkingRecord parkingLot[], int n) {
    FILE *file = fopen("parkingLot_new.txt", "w");
    if (!file) {
        printf("无法打开文件 parkingLot_new.txt\n");
        return;
    }
    for (int i = 0; i < n; i++) {
        fprintf(file, "%d %s %s %s %.2f %d\n", parkingLot[i].id, parkingLot[i].licenseNum, parkingLot[i].timeIn, parkingLot[i].timeOut, parkingLot[i].parkTime, parkingLot[i].cost);
    }
    fclose(file);
}

void sort(struct ParkingRecord parkingLot[], int n) {
    for (int i = 0; i < n - 1; i++) {
        for (int j = 0; j < n - i - 1; j++) {
            if (get_timestamp(parkingLot[j].timeIn) > get_timestamp(parkingLot[j + 1].timeIn)) {
                struct ParkingRecord temp = parkingLot[j];
                parkingLot[j] = parkingLot[j + 1];
                parkingLot[j + 1] = temp;
            }
        }
    }
}

int sum(struct ParkingRecord parkingLot[], int n) {
    int total = 0;
    for (int i = 0; i < n; i++) {
        if (parkingLot[i].timeOut[0] != '\0') {
            total += parkingLot[i].cost;
        }
    }
    return total;
}

void abnormal_data(struct ParkingRecord parkingLot[], int n) {
    printf("僵尸车列表:\n");
    for (int i = 0; i < n; i++) {
        if (parkingLot[i].timeOut[0] == '\0') {
            time_t now = time(NULL);
            time_t timeIn = get_timestamp(parkingLot[i].timeIn);
            if (difftime(now, timeIn) >= 7 * 24 * 3600) {
                printf("车牌: %s, 入场时间: %s\n", parkingLot[i].licenseNum, parkingLot[i].timeIn);
            }
        }
    }
}

void display_data(struct ParkingRecord parkingLot[], char licenseNum[], int n) {
    int found = 0;
    for (int i = 0; i < n; i++) {
        if (strcmp(parkingLot[i].licenseNum, licenseNum) == 0 && parkingLot[i].timeOut[0] == '\0') {
            printf("ID: %d, 车牌: %s, 入场时间: %s, 出场时间: %s, 停车时长: %.2f小时, 费用: %d元\n", 
                   parkingLot[i].id, parkingLot[i].licenseNum, parkingLot[i].timeIn, parkingLot[i].timeOut, parkingLot[i].parkTime, parkingLot[i].cost);
            found = 1;
        }
    }
    if (!found) {
        printf("未找到该车牌的入场记录!\n");
    }
}

void menu(void) {
    printf("\n 智能停车系统\n 1:显示\n 2:查找\n 3:停车入库\n 4:出库结算\n 5:计算总费用\n 6:排序\n 7:导出\n 8:异常车辆摸排\n 0:退出\n");
}

int main(void) {
    struct ParkingRecord parkingLot[MAX_CAPACITY];
    int parkCount = 0;
    char licenseNum[10];
    int choice, total;
    menu();
    parkCount = import_data(parkingLot);
    ShowRecords(parkingLot, parkCount);
    while (1) {
        printf("请输入你的选择(0~8):");
        scanf("%d", &choice);
        if (choice == 0) {
            printf("谢谢使用!\n");
            break;
        } else if (choice == 1) {
            ShowRecords(parkingLot, parkCount);
        } else if (choice == 2) {
            printf("请输入你要查找的车牌号码:");
            scanf("%s", licenseNum);
            display_data(parkingLot, licenseNum, parkCount);
        } else if (choice == 3) {
            parkCount = parkCar(parkingLot, parkCount);
        } else if (choice == 4) {
            printf("请输入要出库结算的车牌号码:\n");
            scanf("%s", licenseNum);
            checkOutCar(parkingLot, parkCount, licenseNum);
        } else if (choice == 5) {
            total = sum(parkingLot, parkCount);
            printf("停车场目前总收入为%d元\n", total);
        } else if (choice == 6) {
            sort(parkingLot, parkCount);
            save_data(parkingLot, parkCount);
            ShowRecords(parkingLot, parkCount);
        } else if (choice == 7) {
            save_data(parkingLot, parkCount);
        } else if (choice == 8) {
            abnormal_data(parkingLot, parkCount);
        }
    }
    return 0;
}

在这里插入图片描述
包可以运行的
CoderJoon一个致力于帮助大学的解决难题的专业coder

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1891996.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

qt5.15关于qradiobutton遇到的坑

前言 不知道是只有我遇到了&#xff0c;还是qt本身就存在这个bug 当将2个qradiobutton放入到一个布局内&#xff0c;然后进行来回切换&#xff0c;若无数据刷新的情况下&#xff0c;切换无异常&#xff0c;当窗体内有数据开始刷新了&#xff0c;则点击其中一个qradiobutton&am…

考PMP一定要报培训班么?

曾有自学PMP想法学员分享&#xff1a;不如选择性价比高通过率高的PMP项目管理培训机构威班PMP 其实参加PMP考试如果非要自学也能参加考试的&#xff0c;只是需要找一个能卖给你35学时的机构&#xff0c;也只有PMI授权的PMP机构能开具35学时证明&#xff0c;这种生意也只有小机…

工厂自动化相关设备工业一体机起到什么作用?

在当今的制造业领域&#xff0c;工厂自动化已成为提高生产效率、保证产品质量和降低成本的关键。在这一进程中&#xff0c;工业一体机作为一种重要的设备&#xff0c;发挥着不可或缺的作用。 工业一体机是自动化生产线上的控制中心。它能够整合和处理来自各个传感器、执行器和其…

Hadoop3:集群压测-读写性能压测

一、准备工作 首先&#xff0c;我们要知道&#xff0c;平常所说的网速和文件大小的MB是什么关系。 100Mbps单位是bit&#xff1b;10M/s单位是byte ; 1byte8bit&#xff0c;100Mbps/812.5M/s。 测试 配置102、103、104虚拟机网速 102上用Python开启一个文件下载服务&#x…

没有找到openslide-win64xxxx文件 ! ! ! (openslide-python安装教程)

各位小伙伴大家好&#xff0c;今天给大家带来教程&#xff1a;openslide-python安装 说实话这个库我之前也没有用到过&#xff0c;然后今天代码需要&#xff0c;就安装了一下 但是在import openslide的时候报错&#xff0c;找了很多教程 说句心里话&#xff1a;那些教程都是…

又一个被催的相亲对象!家庭不和,是因为智慧不够?——早读(逆天打工人爬取热门微信文章解读)

你相亲过吗&#xff1f; 引言Python 代码第一篇 洞见 家庭不和&#xff0c;是因为智慧不够第二篇 口播结尾 引言 yue 昨天居然忘记了 正事&#xff1a;拍视频j 居然忘记了 别着急 让我找下理由&#xff08;借口&#xff09; 前天我妈给我介绍了个相亲对象 推给我了她的微信 我…

基于opencv-python开发的长度测量-角度测量算法

使用OpenCV-Python进行长度和角度测量的项目可以应用于多个领域&#xff0c;如工业自动化、机器人视觉、测绘、教育等。这类项目的核心是利用计算机视觉技术从图像或视频中提取有用的信息&#xff0c;进而计算出物体的尺寸或角度。以下是一个基于OpenCV-Python进行长度和角度测…

软考《信息系统运行管理员》-2.4信息系统运维管理标准

2.4信息系统运维管理标准 信息系统运维的相关标准 ITIL信息技术基础设施库 基于服务生命周期主要包含五个方面&#xff1a;服务战略&#xff08;轴心&#xff09;、服务设计、服务转换、服务运营及服务改进 COBIT信息系统和技术控制目标 考法1&#xff1a;概念 在ITILv3基于…

开源 复刻GPT-4o - Moshi;自动定位和解决软件开发中的问题;ComfyUI中使用MimicMotion;自动生成React前端代码

✨ 1: Moshi 法国 AI 实验室 Kyutai 刚刚推出了开源 复刻GPT-4o - Moshi Moshi是一款现代化聊天平台&#xff0c;旨在提供用户友好和高效的即时通讯体验。它整合了多种功能&#xff0c;包括文本消息、语音和视频通话、文件共享等&#xff0c;为个人用户和团队协作提供了强大的…

grid布局下的展开/收缩过渡效果【vue/已验证可正常运行】

代码来自GPT4o&#xff1a;国内官方直连GPT4o <template><div class"container"><button class"butns" click"toggleShowMore">{{ showAll ? 收回 : 显示更多 }}</button><transition-group name"slide-fade&…

Hadoop-11-MapReduce JOIN 操作的Java实现 Driver Mapper Reducer具体实现逻辑 模拟SQL进行联表操作

章节内容 上一节我们完成了&#xff1a; MapReduce的介绍Hadoop序列化介绍Mapper编写规范Reducer编写规范Driver编写规范WordCount功能开发WordCount本地测试 背景介绍 这里是三台公网云服务器&#xff0c;每台 2C4G&#xff0c;搭建一个Hadoop的学习环境&#xff0c;供我学…

【10年有效】阿里云域名,出阿里云私人子域名

出&#xff1a;阿里云私人子域名&#xff0c;主要是帮助没域名的&#xff0c;又需要使用域名绑定程序的人。 有效期十年&#xff0c;就只要几块&#xff0c;简直是薅羊毛薅到家了~~ 本域名已经备案了。 目标&#xff1a;https://h5.m.goofish.com/item?id811115711415 ---…

【楚怡杯】职业院校技能大赛 “Python程序开发”赛项样题二

Python程序开发实训 &#xff08;时量&#xff1a;240分钟&#xff09; 中国XX 实训说明 注意事项 1. 请根据提供的实训环境&#xff0c;检查所列的硬件设备、软件清单、材料清单是否齐全&#xff0c;计算机设备是否能正常使用。 2. 实训结束后&#xff0c;将各试题代码整合…

QQ录屏文件保存在哪里?一键教你快速查询

无论是记录重要的工作内容&#xff0c;还是分享生活中的点滴&#xff0c;屏幕录制都发挥着至关重要的作用。在众多屏幕录制工具中&#xff0c;qq录屏以其简单易用、功能丰富的特点&#xff0c;受到了广大用户的喜爱。本文将为您揭示qq录屏文件保存在哪里&#xff0c;帮助大家更…

DAY18-力扣刷题

1.从前序与中序遍历序列构造二叉树 105. 从前序与中序遍历序列构造二叉树 - 力扣&#xff08;LeetCode&#xff09; 给定两个整数数组 preorder 和 inorder &#xff0c;其中 preorder 是二叉树的先序遍历&#xff0c; inorder 是同一棵树的中序遍历&#xff0c;请构造二叉树…

C# 实现位比较操作

1、目标 对两个字节进行比较&#xff0c;统计变化位数、一位发生变化的位数、二位发生变化的位数、多位发生变化的位数。 2、代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Lin…

大模型时代数据库技术创新

本文整理自 2024 年 6 月 ArchSummit&#xff08;深圳站&#xff09; Data4AI 和 AI4Data 方面的探索和实践案例专题的同名主题分享。 大家好&#xff0c;我今天讲的内容总共分为三部分&#xff0c;先是数据库和大模型的演变历程&#xff0c;尤其是两者的结合的过程。然后在分别…

高浓度锡回收的工艺流程

高浓度锡回收的工艺流程是一个复杂而精细的过程&#xff0c;它旨在从废旧锡制品或含锡废料中高效、环保地提取出高纯度的锡。以下是对该工艺流程的详细阐述&#xff1a; 一、收集与预处理 收集&#xff1a;高浓度锡回收的第一步是收集废旧锡制品或含锡废料&#xff0c;这些材料…

【分布式系统】监控平台Zabbix自定义模版配置

目录 一.添加Zabbix客户端主机 1.服务端跟客户端配置时间同步 2.安装 zabbix-agent2 3.修改 agent2 配置文件 4.服务端安装 zabbix-get验证客户端数据的连通性 5.Web 页面中添加 agent 主机 6.监控模板 二.自定义监控内容 1.客户端创建自定义key 1.1.明确需要执行的 …

Http 实现请求body体和响应body体的双向压缩方案

目录 一、前言 二、方案一(和http header不进行关联) 二、方案二(和http header进行关联) 三、 客户端支持Accept-Encoding压缩方式,服务器就一定会进行压缩吗? 四、参考 一、前言 有时请求和响应的body体比较大,需要进行压缩,以减少传输的带宽。 二、方案一(和…