停车场管理系统(使用数据库sqlite3)

  • 一、序言
  • 二、讲解time_t( )函数 (因为要用到)
  • 三、停车场管理系统代码(可运行)
    • 1.主函数
    • 2.功能函数
    • 3.函数声明

一、序言

本停车场管理系统使用sqlite3所写
其主要功能有
1.查看车库空位 2.车主选择车位停车
3.系统计费 4.查看指定车辆停车记录
5.查看所以车辆停车记录 6.退出

二、讲解time_t( )函数 (因为要用到)

这里讲解下
其中获取时间的函数time_t( )
其头文件为#include<time.h>
作用: 获取系统时间

方法1:
按字符串输出,格式已规定好,不可自己改变格式
格式:Thu Feb 3 21:16:17 2022

#include <time.h>int main()
{time_t timep;time(&timep); //获取从1970至今过了多少秒,存入time_t类型的timepprintf("%s", ctime(&timep));//用ctime将秒数转化成字符串格式,输出:Thu Feb 3 21:16:17 2022return 0;
}

方法2:
用stuct tm结构体,可自己改变格式
输出:2022/3/03 21:12:31

#include <time.h>int main()
{time_t timep;struct tm *p;time(&timep); //获取从1970至今过了多少秒,存入time_t类型的timepp = localtime(&timep);//用localtime将秒数转化为struct tm结构体printf("%d/%d/%d %02d:%02d:%02d\n", 1900 + p->tm_year, 1+ p->tm_mon, p->tm_mday,p->tm_hour, p->tm_min, p->tm_sec);//2022/3/03 21:12:31return 0;
}

3、大体思路

需要头文件 #include <time.h>
(关于地方时,我在第三部分用到时有简单的介绍,现在说怕待会儿用到时候就忘了hhhh)
这里用最简单的话,大致介绍一下我理解的time_t类型和struct tm结构体。

在计算机中看到的utc时间都是从(1970年01月01日 0:00:00)开始计算秒数的。
我们可以通过函数time()来获取从1970年到现在经过了多少秒,并定义time_t 这种类型(本质上是长整型long)来存储从1970年到现在经过了多少秒。
现在我们有了1970年至今的秒数了,但是我们是无法直接通过秒数看出当前的年月日的,所以需要用函数进行转化。(比如直接告诉你现在距离1970年过了1551193610秒,你是不知道今天几号的,得通过函数转化成“Tue Feb 26 20:32:53 2019”这种形式)
这里用于转化的函数,我们暂且称之为时间函数,它们有很多。
我们按照输出参数类型进行分类,一共有两种,
第一种是直接输出字符指针类型,这种函数的好处是可以直接打印字符串(输出如 :Tue Feb 26 20:32:53 2022),但是它的缺点是无法按照想要的格式输出。
第二种函数是输出struct tm结构体类型指针,这种结构体中分别定义了年月日时分秒等,我们可以利用它输出成我们想要的格式(如:2022/3/03 21:01:38)。

4.具体使用与解析

1、定义time_t类型变量,用来存储1970至今的秒数
本质上time_t是长整型,我用 long 替换后运行没有任何差别

time_t timep;

2、利用函数time()获取从1970年至今的秒数

 time(&timep);

函数原型 : time_t time(time_t *t);

 time(&timep);printf("%d",timep);

输出 : 1551193610

如果还是不太懂time_t函数的话 去查查资料 我就不细讲了

三、停车场管理系统代码(可运行)

如果有看不懂的地方 可以留言 我会第一时间解答

1.主函数

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<sqlite3.h>
#include<time.h>
#include"paking_admin.h"#include <stddef.h>int main(){sqlite3 * pdb;int ret;int num;ret = sqlite3_open("database.db",&pdb);//打开或创建数据库if(ret == SQLITE_OK){printf("open database success!\n");}else{printf("open database fail\n");exit(-1);}create_table(pdb);//创建车库表create_all_table(pdb);//创建存放以往所有车的停车记录//  init_table(pdb);//  welcome();while(1){welcome();printf("请输入你的选择:\n");scanf("%d",&num);switch(num){case 1:select_all(pdb);//查看车库空位和停车信息break;case 2:insert_values(pdb);//车主根据车位选择停车break;case 3:count_fee(pdb);//出库并计算价钱break;case 4:select_paking(pdb);//根据车牌查询该车停车记录break;case 5:select_allpaking(pdb);//查看此车库以往所有车的停车记录break;case 6:sqlite3_close(pdb);//退出printf("已退出\n");exit(-1);}}return 0;
}

2.功能函数

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sqlite3.h>
#include<time.h>
#include"paking_admin.h"#include <stddef.h>#define MAX 10void welcome(){printf("*************************************************************************\n");printf("****************                                        *****************\n");printf("****************               停车收费                 *****************\n");printf("****************       (撞坏栏杆 罚款1000元)          *****************\n");printf("*************************************************************************\n");printf("\n");printf("****************      what can I do for you ,sir        *****************\n");printf("\n");printf("******         1 查看所有车位         2 车主选择车位停车           ******\n");printf("******         3 汽车出库并计算费用   4 查看车辆停车记录           ******\n");printf("******         5 查看所有车辆停车记录 6 退出                       ******\n");printf("******                收费标准5¥/s(概不还价)                    ******\n");printf("*************************************************************************\n");
}int create_table(sqlite3 *pdb){//创建此表 将其变为车库 char *sql = NULL;char *errmsg = NULL;int ret;sql = "create table if not exists mytable (id integer primary key,name text,entertm integer,exittm integer,stall text,entertime text,exittime text);";ret = sqlite3_exec(pdb,sql,NULL,NULL,&errmsg);if(ret == SQLITE_OK){printf("create mytable success!\n");return SQLITE_OK;}else{printf("create mytable fail! %s\n",errmsg);exit(-1);}
}
int create_all_table(sqlite3 *pdb){//创建此表用于存放以往在此车库停过车的停车记录char *sql = NULL;char *errmsg = NULL;int ret;sql = "create table if not exists alltable (id integer primary key,name text,entertime text,exittime text);";ret = sqlite3_exec(pdb,sql,NULL,NULL,&errmsg);if(ret == SQLITE_OK){printf("create alltable success!\n");return SQLITE_OK;}else{printf("create alltable fail! %s\n",errmsg);return -1;}
}
void init_table(sqlite3 *pdb){//初始化车库int i;for(i = 0;i < MAX;i++){char *sql = NULL;sql = "insert into mytable (id,name,entertm,exittm,stall,entertime,exittime) values (NULL,'no',NULL,NULL,'no','no','no');";char *errmsg = NULL;int ret;ret = sqlite3_exec(pdb,sql,NULL,NULL,&errmsg);if(ret != SQLITE_OK){printf("init table fail! %s",errmsg);exit(-1);}}}void select_all(sqlite3 *pdb){//查寻车库现在的停车信息char * sql = NULL;char * errmsg = NULL;char ** ret_val = NULL;int nrow;int ncol;int ret;int i;sql = "select * from mytable;";ret = sqlite3_get_table(pdb,sql,&ret_val,&nrow,&ncol,&errmsg);if(ret != SQLITE_OK){printf("select all fail! %s",errmsg);sqlite3_free_table(ret_val);return;}else{for(i = 0;i < (nrow + 1) * ncol;i++){printf("%-20s",ret_val[i]);if((i + 1) % ncol == 0){printf("\n");}}}sqlite3_free_table(ret_val);
}void insert_values(sqlite3 * pdb){//车主根据id自行选择停在哪个车库char sql[200];char *errmsg = NULL;int ret;char name[20];int id;time_t t;printf("请输入车牌号\n");scanf("%s",name);printf("请选择车位id:\n");scanf("%d",&id);t = time(NULL);struct tm *tb;tb = localtime(&t);sprintf(sql,"update mytable set name = '%s',entertm = %ld,stall = 'paking',entertime = '%d/%d/%d %d:%d:%d' where id = %d;",name,t,tb->tm_year+1900,tb->tm_mon+1,tb->tm_mday,tb->tm_hour,tb->tm_min,tb->tm_sec,id);ret = sqlite3_exec(pdb,sql,NULL,NULL,&errmsg);if(ret == SQLITE_OK){printf("停车成功\n");return;}else{printf("停车失败! %s\n",errmsg);return;}
}void count_fee(sqlite3 *pdb){ //先将此刻时间赋值给exittm 然后将此车出库 通过entertm和exittm计算所停时间 并将停车记录给alltable表char sql1[200];char sql2[200];char *errmsg = NULL;int ret1;int ret2;char name[20];time_t t;char ** ret_val;int nrow;int ncol;int i;int a,b;char sql3[200];int ret3;char sql4[200];t = time(NULL);struct tm * tb;tb = localtime(&t);printf("出库汽车车牌号:\n");scanf("%s",name);sprintf(sql1,"update mytable set exittm = %ld,exittime = '%d/%d/%d %d:%d:%d' where name = '%s';",t,tb->tm_year + 1900,tb->tm_mon+1,tb->tm_mday,tb->tm_hour,tb->tm_min,tb->tm_sec,name);ret1 = sqlite3_exec(pdb,sql1,NULL,NULL,&errmsg);if(ret1 == SQLITE_OK){printf("exit time succcess!\n");}else{printf("exit time fail! %s",errmsg);exit(-1);}sprintf(sql2,"select entertm,exittm from mytable where name = '%s';",name);ret2 = sqlite3_get_table(pdb,sql2,&ret_val,&nrow,&ncol,&errmsg);a = atoi(ret_val[2]);b = atoi(ret_val[3]);printf("费用是:%d元\n",(b-a)*5);sprintf(sql4,"insert into alltable(id,name,entertime,exittime) select id,name,entertime,exittime from mytable where name like '%s';",name);sqlite3_exec(pdb,sql4,NULL,NULL,&errmsg);sprintf(sql3,"update mytable set stall = 'no',name = 'no',entertm = NULL,exittm = NULL,entertime='no',exittime = 'no' where name = '%s';",name);ret3 = sqlite3_exec(pdb,sql3,NULL,NULL,&errmsg);if(ret3 == SQLITE_OK){printf("车位已空\n");}else{printf("satll no is fail! %s\n",errmsg);}}void select_paking(sqlite3 *pdb){//根据车牌号查找这辆车的停车记录 char sql[200];char *errmsg = NULL;int ret;int nrow;int ncol;int i;char ** ret_val = NULL;char name[20];printf("请输入你想查询车的车牌号\n");scanf("%s",name);sprintf(sql,"select id,name,entertime,exittime from alltable where name = '%s';",name);ret = sqlite3_get_table(pdb,sql,&ret_val,&nrow,&ncol,&errmsg);if(ret != SQLITE_OK){printf("select_paking error! %s\n",errmsg);sqlite3_free_table(ret_val);return;}else{printf("select_paking success!\n");}for(i = 0;i < (nrow + 1) * ncol;i++){printf("%-20s",ret_val[i]);if((i + 1) % ncol == 0){printf("\n");}}sqlite3_free_table(ret_val);
}void select_allpaking(sqlite3 *pdb){//查询这个车库以往所有停过车的停车记录char *sql = NULL;char *errmsg = NULL;char **ret_val = NULL;int nrow;int ncol;int ret;int i;sql = "select * from alltable;";ret = sqlite3_get_table(pdb,sql,&ret_val,&nrow,&ncol,&errmsg);if(ret != SQLITE_OK){printf("select_allpaking error! %s\n",errmsg);sqlite3_free_table(ret_val);return;}else{printf("select_allpaking success!\n");}for(i = 0;i < (nrow + 1) * ncol;i++){printf("%-20s",ret_val[i]);if((i + 1) % ncol == 0){printf("\n");}}sqlite3_free_table(ret_val);
}

3.函数声明

#ifndef paking_admin
#define paking_admin
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sqlite3.h>#define MAX 10
void welcome();
int create_table(sqlite3 *pdb);
int create_all_table(sqlite3 *pdb);
void init_table(sqlite3 *pdb);
void select_all(sqlite3 * pdb);
void insert_values(sqlite3 *pdb);
void count_fee(sqlite3 *pdb);
void select_paking(sqlite3 *pdb);
void select_allpaking(sqlite3 *pdb);
#endif

停车场管理系统(数据库)相关推荐

  1. JAVA计算机毕业设计智能停车场管理系统Mybatis+源码+数据库+lw文档+系统+调试部署

    JAVA计算机毕业设计智能停车场管理系统Mybatis+源码+数据库+lw文档+系统+调试部署 JAVA计算机毕业设计智能停车场管理系统Mybatis+源码+数据库+lw文档+系统+调试部署 本源码技 ...

  2. 计算机毕业设计Java智能停车场管理系统(源码+系统+mysql数据库+lw文档)

    计算机毕业设计Java智能停车场管理系统(源码+系统+mysql数据库+lw文档) 计算机毕业设计Java智能停车场管理系统(源码+系统+mysql数据库+lw文档) 本源码技术栈: 项目架构:B/S ...

  3. 基于java小区停车场管理系统计算机毕业设计源码+系统+lw文档+mysql数据库+调试部署

    基于java小区停车场管理系统计算机毕业设计源码+系统+lw文档+mysql数据库+调试部署 基于java小区停车场管理系统计算机毕业设计源码+系统+lw文档+mysql数据库+调试部署 本源码技术栈 ...

  4. 计算机毕业设计JAVA小区停车场管理系统mybatis+源码+调试部署+系统+数据库+lw

    计算机毕业设计JAVA小区停车场管理系统mybatis+源码+调试部署+系统+数据库+lw 计算机毕业设计JAVA小区停车场管理系统mybatis+源码+调试部署+系统+数据库+lw 本源码技术栈: ...

  5. 基于JAVA智能停车场管理系统计算机毕业设计源码+系统+数据库+lw文档+部署

    基于JAVA智能停车场管理系统计算机毕业设计源码+系统+数据库+lw文档+部署 基于JAVA智能停车场管理系统计算机毕业设计源码+系统+数据库+lw文档+部署 本源码技术栈: 项目架构:B/S架构 开 ...

  6. mysql智能停车场,jsp357智能停车场管理系统 双数据库版 mysql

    资料介绍 提 示: 电脑 先解压,暴风影音 看 电脑 先解压,暴风影音 看 电脑 先解压,暴风影音 看 论文编号: jsp357 语言+数据库: jsp+sql2008+mysql 论文字数: 125 ...

  7. 基于java和Sql Server数据库的停车场管理系统

    一.实验内容: 实现停车场管理系统,应用于车辆的出.入管理. 二.功能要求: 包括车辆进出管理与系统管理等功能模块,可根据车辆停放时间及收费标准自动收费.用户需要事先办理停车卡并充值,停车卡分优惠卡和 ...

  8. 基于JAVA智能停车场管理系统计算机毕业设计源码+系统+mysql数据库+lw文档+部署

    基于JAVA智能停车场管理系统计算机毕业设计源码+系统+mysql数据库+lw文档+部署 基于JAVA智能停车场管理系统计算机毕业设计源码+系统+mysql数据库+lw文档+部署 本源码技术栈: 项目 ...

  9. Jsp实现停车场管理系统

    系统采用了B/S架构,Tomcat8.0作为运行服务器,基于J2EE标准.Eclipse4.6开发环境,数据库采用Mysql-5.5.37.开发过程利用MVC开发模式,层次分明.成功实现了该系统.试运 ...

最新文章

  1. 【最简代码】1076 Wifi密码 (15分)_8行代码AC
  2. BZOJ.1024.[SCOI2009]生日快乐(记忆化搜索)
  3. esd/wim格式Win7/8.1/win10系统怎么安装两种方法教程
  4. TCP/UDP套接字网络协议
  5. Windows as a Service(3)——使用SCCM管理Windows10更新
  6. IDEA搭建SpringMVC+Spring+Mybatis项目
  7. 世界排名在20多位的无名小站
  8. 戴尔服务器开机自动关机,戴尔台式电脑自动关机怎么办
  9. 【吐血整理-历时两个月,长达万字】FDTD Solutions学习笔记
  10. java 打印jpg、pdf、word
  11. Moblin开发手册:理解 Hildon应用程序
  12. 3:输出名言“贵有恒,何必三更起五更睡:最无益,只怕一日曝十日寒。”
  13. #计算机应用与技巧分享 #应用推荐 #录屏 Captura 免费开源的屏幕录制工具
  14. might和could的区别用法_地道的英语口语:Might、 may、could用法区分
  15. echarts 漏斗图
  16. webos开发 html,尝试在WebOS中创建HTML5表,但失败
  17. c++ string最大长度_关于C++ std::string类内存布局的探究
  18. 漏洞扫描器 XRAY
  19. 神舟十二号航天员名单确定,3名航天员本次上天将完成这些任务
  20. 阐述在html文档中html,行间距在哪里设置?

热门文章

  1. Long Short-Term Memory Recurrent Neural Network Architectures for Large Scale Acoustic Modeling论文阅读
  2. 淘宝秒杀(Python源代码)
  3. 软工大作业·倾物语(一)
  4. 脑空间管理神器:SpaceSniffer
  5. 多相滤波 信道化接收机 matlab程序,基于复多相滤波器组的信道化接收机
  6. Exact Low-Rank Matrix Completion from Sparsely Corrupted Entries Via Adaptive Outlier Pursuit
  7. python爬取猪八戒网的内容
  8. python爬虫兼职-学会Python有哪些可以做的兼职?
  9. 西门子828D系统PLC轴控制伺服刀塔应用
  10. 51 SJA1000驱动程序