//

//  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泊车管理系统的更多相关文章

  1. C[泊车管理系统]

    // //  main.c //  泊车管理系统 // //  Created by 丁小未 on 13-7-14. //  Copyright (c) 2013年 dingxiaowei. All ...

  2. ASP.NET MVC5+EF6+EasyUI 后台管理系统(1)-前言与目录(持续更新中...)

    开发工具:VS2015(2012以上)+SQL2008R2以上数据库  您可以有偿获取一份最新源码联系QQ:729994997 价格 666RMB  升级后界面效果如下: 任务调度系统界面 http: ...

  3. ASP.NET MVC5+EF6+EasyUI 后台管理系统 (源码购买说明)

    系列目录 升级日志 !!!重大版本更新:于2016-12-20日完成了系统的结构重构并合并简化了T4(这是一次重要的更新,不需要修改现有功能的代码),代码总行数比上个版本又少了1/3.更新了代码生成器 ...

  4. ASP.NET MVC5+EF6+EasyUI 后台管理系统(63)-Excel导入和导出-自定义表模导入

    系列目录 前言 上一节使用了LinqToExcel和CloseXML对Excel表进行导入和导出的简单操作,大家可以跳转到上一节查看: ASP.NET MVC5+EF6+EasyUI 后台管理系统(6 ...

  5. ShenNiu.MVC管理系统

    本篇将要和大家分享的是一个简单的后台管理系统,这里先发个地址http://www.lovexins.com:8081/(登陆账号:youke,密码:123123:高级用户账号:gaoji,密码:123 ...

  6. Asp.Net Core 项目实战之权限管理系统(4) 依赖注入、仓储、服务的多项目分层实现

    0 Asp.Net Core 项目实战之权限管理系统(0) 无中生有 1 Asp.Net Core 项目实战之权限管理系统(1) 使用AdminLTE搭建前端 2 Asp.Net Core 项目实战之 ...

  7. 基于jsp+servlet图书管理系统之后台万能模板

    前奏: 刚开始接触博客园写博客,就是写写平时学的基础知识,慢慢发现大神写的博客思路很清晰,知识很丰富,非常又价值,反思自己写的,顿时感觉非常low,有相当长一段时间没有分享自己的知识.于是静下心来钻研 ...

  8. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(14)-EasyUI缺陷修复与扩展

    系列目录 不知不觉已经过了13讲,(本来还要讲多一讲是,数据验证之自定义验证,基于园友还是对权限这块比较敢兴趣,讲不讲验证还是看大家的反映),我们应该对系统有一个小结.首先这是一个团队开发项目,基于接 ...

  9. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(23)-权限管理系统-角色组模块

    系列目录 距离上次发布22讲已经有少许日子了,真是太抱歉,最近年关项目比较急,时间太紧,没有时间发布.请大家见谅 接下来我们的目标是 角色组管理 角色组权限设置 用户管理 把角色组授权给用户 给用户分 ...

随机推荐

  1. HttpServletRequest中得到各种信息

    1.获得domain: StringBuffer url = request.getRequestURL(); String domain = url.delete(url.length() - re ...

  2. pydev导入eclipse

    编辑器:Python 自带的 IDLE 简单快捷, 学习Python或者编写小型软件的时候.非常有用. 编辑器: Eclipse + pydev插件 1. Eclipse是写JAVA的IDE, 这样就 ...

  3. linux 共享内存实现

    说起共享内存,一般来说会让人想起下面一些方法:1.多线程.线程之间的内存都是共享的.更确切的说,属于同一进程的线程使用的是同一个地址空间,而不是在不同地址空间之间进行内存共享:2.父子进程间的内存共享 ...

  4. ssh自动登陆

    突然碰到有人问ssh再传输密钥时候能不手动输入密码,由于没有碰到过这种情况,所以查了一下发现可以用sshpass做到. sshpass [参数] ssh命令: 参数: -p password  #将参 ...

  5. 【Python升级录】--基础知识

    创建角色成功! 正在载入python........ [python介绍] python是一门动态解释性的强类型定义语言. python的创始人为吉多·范罗苏姆(Guido van Rossum).1 ...

  6. mysql无法启动

    当在安装mysql服务时,有时会遇到恶心的PID错误而导致安装后无法启动以下为针对mysql-5.5版本在安装mysql时所遇到的问题的解决方法. 1.可能是/usr/local/mysql/data ...

  7. Ajax与Jquery题库

    一.    填空题 1.在JQuery中被誉为工厂函数的是 $() . 2.在jQuery中需要选取<div>元素里所有<a>元素的选择器是 $("div a&quo ...

  8. October 13th 2016 Week 42nd Thursday

    If the world seems cold to you, kindle fires to warm it. 若世界以寒相待,请点燃火堆以温暖相报. Kindle fires to warm th ...

  9. September 29th 2016 Week 40th Thursday

    Prosperity discovers vice, adversity virtue. 得意时露瑕疵,逆境中见品质. I wish I would have someone like you, fr ...

  10. mongoose学习笔记1--基础知识1

    今天我们将学习Mongoose,什么是Mongoose呢,它于MongoDB又是什么关系呢,它可以用来做什么呢? MongoDB是一个开源的NoSQL数据库,相比MySQL那样的关系型数据库,它更显得 ...