C泊车管理系统
//
// main.c
// 泊车管理系统
//
// Created by 丁小未 on 13-7-14.
// Copyright (c) 2013年 dingxiaowei. All rights reserved.
//
//题目:泊车管理系统
//(1)管理人员根据口令进入系统
//(2)管理车位信息(车位编号,状态)和每分钟的收费率;
//(3)停车时录入汽车停泊信息(车牌号,车型,停泊位置,停泊开始时间);如果车位已满要给出提示;
//(4)取车时,根据车牌取,如果没有给出提示;需要根据车辆停泊时间自动计算费用并显示在屏幕上。
#include <stdio.h>
#include <string.h>
#include <time.h>
#define MAX 20
struct StopedCar
{
char carNum[20]; //车牌号
char carshap[20];//车型
int areaNum; //停泊位置号码
char stopedTime[30]; //开始停泊时间
int h; //记录小时
int m; //记录分钟
};
int total; //总记录数
char password[20]; //密码
struct StopedCar stopedcar[MAX];
int price=1.0;//默认泊车单价为1¥1M
/***************函数申明******************************************/
void Init();//初始化,文件不存在,则建立,同时记录下文件中记录的个数
int get_menu_choice(); //接受菜单选择
void menu();//菜单相应
void Show_menu();//显示菜单
FILE *file_operate(char *mode); //文件操作类型
void set_psw();//设置密码
int psw_check();//密码验证
int Inputonecar(int i);//根据车位号增加一条记录
void Inputfile(int i,FILE *fp);//将下标为i的记录写入文件
void Input(FILE *fp);//向管理系统中增加记录
int SetPrice();//设置停车单价(例如:¥1for1s)
void GetCarByAreaNum(FILE *fp);//根据车位号取车
/*****以下函数是为了简化部分工作从上面的函数中划分出来的功能**************/
void PrintTitle();//打印头信息
void ShowAllCarInfo(); //显示所有停车信息
void Showonecarinfo(int i); //显示停车信息
float countMoney(float danjia);//计算根据传入的单价来计算泊车的费用
void Readfile(int i,FILE *fp);//从文件中读取一条记录
int CheckNumber(int areaNum_temp);//检查车位号是否为空,存在返回序号,如果该车位有停车则返回-1
char* GetTime();//获取当前时间
int Cost(char *time1,int danjia);//根据单价和时间差来计算停车消费的价格
int Cost2(int h,int m,int danjia);
void GetCarByAreaNum2(FILE *fp);
int timeh();
int timem();
/***************函数的实现****************************************/
//获取当前系统时间
char* GetTime()
{
{
time_t now;
struct tm *timenow;
time(&now);
timenow = localtime(&now);
char *p = asctime(timenow);
return p;
}
}
//返回当前小时
int timeh()
{
int h;
time_t now;
struct tm *timenow;
time(&now);
timenow = localtime(&now);
char *p = asctime(timenow);
h=timenow->tm_hour;
return h;
}
//返回当前分钟
int timem()
{
int m;
time_t now;
struct tm *timenow;
time(&now);
timenow = localtime(&now);
char *p = asctime(timenow);
m=timenow->tm_min;
return m;
}
//接受菜单选择
int get_menu_choice()
{
int menu_ch;
do {
printf("输入菜单选项:");
scanf("%d",&menu_ch);
if((menu_ch<0)||(menu_ch>9))
printf("输入错误!");
} while ((menu_ch<0)||(menu_ch>9));
return menu_ch;
}
//显示菜单
void Show_menu()
{
printf(">>>>>>>>>>>>>>>欢迎使用泊车管理系统<<<<<<<<<<<<<<<<\n");
printf("************************************************\n");
printf("* 1.新增停车信息 | 2.显示所有停车信息 *\n");
printf("* 3.按照车牌号取车 | 4.按照车位号取车 *\n");
printf("* 5.按照车牌号查询车信息 | 6.按照车位号查询车信息*\n");
printf("* 7.设置泊车单价 | 8.密码设置 *\n");
printf("* 9.主动清屏 | 0.退出 *\n");
printf("************************************************\n");
}
//清屏,有点问题
//void clear()
//{
// system("pause");
// system("cls");
//}
//菜单响应
void menu()
{
while (1) {
Show_menu();
switch (get_menu_choice()) {
case 1://新增停车信息
Input(file_operate("ab")); //二进制追加写入
break;
case 2://显示所有泊车信息
ShowAllCarInfo();
break;
case 3://按照车牌好取车
break;
case 4://按照车位号取车
GetCarByAreaNum2(file_operate("wb"));
break;
case 5://按照车牌号查询车位信息
break;
case 6: //按照车位号查询车位信息
break;
case7://设置停车价格(例如:¥1for1s)
SetPrice();
break;
case 8://密码设置
set_psw();
break;
case 9://手动清屏
//clear();
printf("手动清屏有误!");
break;
case 0://结束程序
//system("cls");
printf("*********************\n");
printf(" 欢迎使用本系统 \n");
printf("**********************\n");
break;
//exit(0);
default:
break;
}
}
}
//打印头信息
void PrintTitle()
{
printf("-------------------------------------------------------------\n");
printf(" 车牌号 车型 停泊车位号 停泊开始时间 \n");
printf("-------------------------------------------------------------\n");
}
//初始化,文件不存在,则建立,同时记录下文件中的记录数
void Init()
{
int ii;
FILE *fp;
total=0;
if((fp=fopen("/Users/zl201/Desktop/泊车管理系统/泊车管理系统/stopedcar.txt","rb"))==NULL)
{
fp=fopen("/Users/zl201/Desktop/泊车管理系统/泊车管理系统/stopedcar.txt","ab");
//clear();
menu();
}
else
{
for(ii=0;feof(fp)==0;ii++) //feof检查文件是否结束
{
Readfile(ii,fp);
}
total=ii-1;
}
//total=ii-1;
fclose(fp);
}
//文件操作类型
FILE *file_operate(char *mode)
{
char choice;
FILE *fp;
do
{
fflush(stdin);//清空输入缓存,以便不影响后面的输入
if((fp=fopen("/Users/zl201/Desktop/泊车管理系统/泊车管理系统/stopedcar.txt",mode))==NULL)
{
puts("Fail to open the file!");
puts("Try again!(Y/N)?");
scanf("%c",&choice);
}
else
fp=fopen("/Users/zl201/Desktop/泊车管理系统/泊车管理系统/stopedcar.txt",mode);
}
while(choice=='y'||choice=='Y');
if(choice=='n'||choice=='N'){}
//exit(1); //异常退出 exit(0);系统正常退出
return(fp);
}
//从文件中读取一条记录
void Readfile(int i,FILE *fp)
{
fscanf(fp,"%20s",&stopedcar[i].carNum);
fscanf(fp,"%20s",&stopedcar[i].carshap);
fscanf(fp,"%5d",&stopedcar[i].areaNum);
fscanf(fp,"%30s",&stopedcar[i].stopedTime);
}
//显示打印一条泊车信息
void Showonecarinfo(int i)
{
printf("%10s %10s %1d %30s \n",stopedcar[i].carNum,stopedcar[i].carshap,stopedcar[i].areaNum,stopedcar[i].stopedTime);
}
//显示打印所有的泊车信息
void ShowAllCarInfo()/*显示打印所有的信息 */
{
int i;
printf("有%d个记录:\n",total);
PrintTitle();
for(i=0;i<total;i++)
Showonecarinfo(i);
}
//检查车位号是否为空,存在返回序号,如果该车位没有停车则返回-1
int CheckNumber(int areaNum_temp)
{
int i,result=0;
for(i=0;i<total;i++)
{
if(stopedcar[i].areaNum==areaNum_temp)
{
result=1;
break;
}
}
if(result==1)
return i;
else
return -1;
}
//根据车位号增加一条记录
int Inputonecar(int i)
{
int areaNum;
do
{
printf("输入车位号:(如1)");
scanf("%d",&areaNum);
if(areaNum<0)
printf("error!\n");
if (areaNum>MAX) {
printf("没有大于%d的车位\n",MAX);
}
}
while(areaNum<0);
//该车位有停车
if(CheckNumber(areaNum)>0)
{
printf("该车位已经停了车!\n");
return 0;
}
//如果该车位没有停车
else
{
stopedcar[i].areaNum=areaNum; //将停车的车位号记录为当前的车位号
printf("Input 车牌号(less than 20 chars):");
scanf("%s",stopedcar[i].carNum);
printf("车型号(例如:baomaX6):");
scanf("%s",&stopedcar[i].carshap);
char *time=GetTime();//获取当前系统时间
stopedcar[i].h=timeh();//记录小时
stopedcar[i].m=timem();//记录分钟
char *q=stopedcar[i].stopedTime;
strcpy(q, time);//将当前时间赋值给car.StopedTime
PrintTitle();
Showonecarinfo(i);
//Inputfile(i,fp);
return 1;
}
}
//把下标为i 的记录写入文件
void Inputfile(int i,FILE *fp)
{
fscanf(fp,"%20s",&stopedcar[i].carNum);
fscanf(fp,"%20s",&stopedcar[i].carshap);
fscanf(fp,"%5d",&stopedcar[i].areaNum);
fscanf(fp,"%30s",&stopedcar[i].stopedTime);
}
//向管理系统中增加记录
void Input(FILE *fp)
{
int i;
i=total;
if(Inputonecar(i))
{
total++;
Inputfile(i,fp);
}
fclose(fp);
}
//设置泊车单价
int SetPrice()
{
printf("请设置泊车单价:(例如:1¥for 1 m)\n");
scanf("%d",&price);
printf("您设置的单价是:%d¥1M\n",price);
return price;
}
int Cost2(int h,int m,int danjia)
{
int money;
//获取当前小时和分钟
int hnow=timeh();
int mnow=timem();
return money=((hnow-h)*60+(mnow-m))*danjia;
}
//根据单价和时间差来计算停车消费的价格
int Cost(char *time1,int danjia)
{
int money;
char forein[2];
char now[2];
int minu;
int sec;
int t1,t2;
for (int i=14; i<=15; i++,time1++) {
forein[i-14]=time1[i];
}
minu=(forein[0]-48)*10+(forein[1]-48);
for (int i=17; i<=18; i++,time1++) {
forein[i-17]=time1[i];
}
sec=(forein[0]-48)*10+(forein[1]-48);
t1=minu*60+sec;
char *p=GetTime();
for (int i=14; i<=15; i++,time1++) {
forein[i-14]=p[i];
}
minu=(forein[0]-48)*10+(forein[1]-48);
for (int i=17; i<=18; i++,time1++) {
forein[i-17]=p[i];
}
sec=(forein[0]-48)*10+(forein[1]-48);
t2=minu*60+sec;
money=(t2-t1)*danjia;
return money;
}
//根据车位号取车
void GetCarByAreaNum2(FILE *fp)
{
int i,j,k,no_temp,choice2;
printf("输入要取车的车位号:(例如1)");
scanf("%d",&no_temp);
i=CheckNumber(no_temp);
if(i>=0)
{
PrintTitle();
Showonecarinfo(i);//根据车位号来查询是第几个
printf("确认取车?(1.是/2.否)");
scanf("%d",&choice2);
if(choice2==1)
{
// char *time1=stopedcar[i].stopedTime;
// printf(time1);
int h=stopedcar[i].h;
int m=stopedcar[i].m;
printf("您需要支付¥%d的停车费\n",Cost2(h,m,price));
for (j=i; j<total; j++) {
strcpy(stopedcar[j].carNum, stopedcar[j+1].carNum);
strcpy(stopedcar[j].carshap, stopedcar[j+1].carshap);
}
total--;
for (k=0; k<total; k++) {
Inputfile(k, fp);
}
}
}
else
printf("该车位上没有停车\n");
}
//根据车位号取车
void GetCarByAreaNum(FILE *fp)
{
int i,j,k,no_temp,choice2;
printf("输入要取车的车位号:(例如1)");
scanf("%d",&no_temp);
i=CheckNumber(no_temp);
if(i>=0)
{
PrintTitle();
Showonecarinfo(i);//根据车位号来查询是第几个
printf("确认取车?(1.是/2.否)");
scanf("%d",&choice2);
if(choice2==1)
{
char *time1=stopedcar[i].stopedTime;
printf(time1);
printf("您需要支付¥%d的停车费\n",Cost(time1,price));
for (j=i; j<total; j++) {
strcpy(stopedcar[j].carNum, stopedcar[j+1].carNum);
strcpy(stopedcar[j].carshap, stopedcar[j+1].carshap);
}
total--;
for (k=0; k<total; k++) {
Inputfile(k, fp);
}
}
}
else
printf("该车位上没有停车\n");
}
//设置密码
void set_psw()
{
char psw_set[20],psw_check[20],c;
unsignedint i;
FILE *fp;
do
{ printf("You must set password first!\n");
printf("Enter password:(less than 12 numbers and key'.'for end)\n");
for(i=0;(c=getchar())!='.';i++)
{
//putchar('*');
psw_set[i]=c;
}
psw_set[i]='\0';
printf("-----------------\n");
printf("conform password:");
for(i=0;(c=getchar())!='.';i++)
{
//putchar('*');
psw_check[i]=c;
}
psw_check[i]='\0';
//printf("------------\n");
if(strcmp(psw_set,psw_check)==0)
{printf("Set password success!\n");
strcpy(password,psw_set);
}
else
printf("error!\n");
}
while(strcmp(psw_set,psw_check)!=0);
//clear();
fp=fopen("/Users/zl201/Desktop/泊车管理系统/泊车管理系统/password.txt","wb");
fprintf(fp,"%s",password);
fclose(fp);
}
//密码验证
int psw_check()
{
unsigned int i=1,j=1;
FILE *fp;
char pword[20],c;
if((fp=fopen("/Users/zl201/Desktop/泊车管理系统/泊车管理系统/password.txt","rb"))==NULL)
{
fp=fopen("/Users/zl201/Desktop/泊车管理系统/泊车管理系统/password.txt","a");
set_psw();
}
fscanf(fp,"%s",password);
fclose(fp);
do
{
printf("\nInput password:key'.'for end(%d/three times)",j);
for(j=0;(c=getchar())!='.';j++)
{
//putchar('*');
pword[j]=c;
}
pword[j]='\0';
i++;
}
while(strcmp(pword,password)!=0&&i<=3);
if(i<=3)
return 1;
else
{
printf("You have tryed for three times,fail to open the file!\n");
return 0;
}
}
int main(int argc, const char * argv[])
{
if(psw_check())
{
Init();
//clear();
menu();
}
return 0;
}
C泊车管理系统的更多相关文章
- C[泊车管理系统]
// // main.c // 泊车管理系统 // // Created by 丁小未 on 13-7-14. // Copyright (c) 2013年 dingxiaowei. All ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(1)-前言与目录(持续更新中...)
开发工具:VS2015(2012以上)+SQL2008R2以上数据库 您可以有偿获取一份最新源码联系QQ:729994997 价格 666RMB 升级后界面效果如下: 任务调度系统界面 http: ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统 (源码购买说明)
系列目录 升级日志 !!!重大版本更新:于2016-12-20日完成了系统的结构重构并合并简化了T4(这是一次重要的更新,不需要修改现有功能的代码),代码总行数比上个版本又少了1/3.更新了代码生成器 ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(63)-Excel导入和导出-自定义表模导入
系列目录 前言 上一节使用了LinqToExcel和CloseXML对Excel表进行导入和导出的简单操作,大家可以跳转到上一节查看: ASP.NET MVC5+EF6+EasyUI 后台管理系统(6 ...
- ShenNiu.MVC管理系统
本篇将要和大家分享的是一个简单的后台管理系统,这里先发个地址http://www.lovexins.com:8081/(登陆账号:youke,密码:123123:高级用户账号:gaoji,密码:123 ...
- Asp.Net Core 项目实战之权限管理系统(4) 依赖注入、仓储、服务的多项目分层实现
0 Asp.Net Core 项目实战之权限管理系统(0) 无中生有 1 Asp.Net Core 项目实战之权限管理系统(1) 使用AdminLTE搭建前端 2 Asp.Net Core 项目实战之 ...
- 基于jsp+servlet图书管理系统之后台万能模板
前奏: 刚开始接触博客园写博客,就是写写平时学的基础知识,慢慢发现大神写的博客思路很清晰,知识很丰富,非常又价值,反思自己写的,顿时感觉非常low,有相当长一段时间没有分享自己的知识.于是静下心来钻研 ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(14)-EasyUI缺陷修复与扩展
系列目录 不知不觉已经过了13讲,(本来还要讲多一讲是,数据验证之自定义验证,基于园友还是对权限这块比较敢兴趣,讲不讲验证还是看大家的反映),我们应该对系统有一个小结.首先这是一个团队开发项目,基于接 ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(23)-权限管理系统-角色组模块
系列目录 距离上次发布22讲已经有少许日子了,真是太抱歉,最近年关项目比较急,时间太紧,没有时间发布.请大家见谅 接下来我们的目标是 角色组管理 角色组权限设置 用户管理 把角色组授权给用户 给用户分 ...
随机推荐
- C++基础知识面试精选100题系列(21-30)[C++ basics]
[本文链接] http://www.cnblogs.com/hellogiser/p/100-interview-questions-of-cplusplus-basics-21-30.html [题 ...
- Centos7 修改SSH 端口
修改/etc/ssh/sshd_config vi /etc/ssh/sshd_config #Port 22 //这行去掉#号,防止配置不好以后不能远程登录,还得去机房修改,等修改以后的端口能使用以 ...
- ios UIButton 选中后背景图片变化发灰问题
UIButton的类型如果选择了System类型,那么设置背景图后,点击的效果是图片发灰,而不是默认的那种图片变淡黑色效果,需要用customer类型就好了.
- Android Broadcast 和 iOS Notification
感觉以上2个机能有许多相似之处,作个记录,待研究!
- MongoDB 3.0 新特性【转】
本文来自:http://www.open-open.com/lib/view/open1427078982824.html#_label3 更多信息见官网: http://docs.mongodb.o ...
- Effective C++ -----条款06:若不想使用编译器自动生成的函数,就该明确拒绝
为驳回编译器自动提供的功能,可将相应的成员函数声明为private并且不予实现. 使用像Uncopyable这样的base class也是一种做法(即先声明一个基类,然后私有继承它).这其实有点像使用 ...
- MST:Agri-Net(POJ 1258)
Agri-Net 题目大意:农夫有一片农场,现在他要把这些田地用管子连起来,田地之间有一定距离,铺设每一段管子的长度与这些田地与田地距离是一样的,问你最小的铺设方案. 这一题很裸,Kruskal算法 ...
- javax.transaction.xa.XAException: java.sql.SQLException: 无法创建 XA 控制连接。错误: 未能找到存储过程 'master..xp_sqljdbc_xa_init'
配置JTA SQL Server XADataSource参考:https://msdn.microsoft.com/zh-cn/library/aa342335.aspx 使用 JDBC 驱动程序 ...
- Android实现Banner界面广告图片循环轮播(包括实现手动滑动循环)
前言:经常会看到有一些app的banner界面可以实现循环播放多个广告图片和手动滑动循环.本以为单纯的ViewPager就可以实现这些功能.但是蛋疼的事情来了,ViewPager并不支持循环翻页.所以 ...
- 【leetcode】Rotate List(middle)
Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1 ...