日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > windows >内容正文

windows

C[泊车管理系统]

發(fā)布時(shí)間:2025/7/14 windows 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C[泊车管理系统] 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

//

//? main.c

//? 泊車管理系統(tǒng)

//

//? Created by 丁小未 on 13-7-14.

//? Copyright (c) 2013 dingxiaowei. All rights reserved.

//

//題目:泊車管理系統(tǒng)

//1)管理人員根據(jù)口令進(jìn)入系統(tǒng)

//2)管理車位信息(車位編號,狀態(tài))和每分鐘的收費(fèi)率;

//3)停車時(shí)錄入汽車停泊信息(車牌號,車型,停泊位置,停泊開始時(shí)間);如果車位已滿要給出提示;

//4)取車時(shí),根據(jù)車牌取,如果沒有給出提示;需要根據(jù)車輛停泊時(shí)間自動計(jì)算費(fèi)用并顯示在屏幕上。

#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]; //開始停泊時(shí)間

? ? int h;? //記錄小時(shí)

? ? int m;? //記錄分鐘

};

int total;? //總記錄數(shù)

char password[20]; //密碼

struct StopedCar stopedcar[MAX];

int price=1.0;//默認(rèn)泊車單價(jià)為11M


/***************函數(shù)申明******************************************/

void Init();//初始化,文件不存在,則建立,同時(shí)記錄下文件中記錄的個(gè)數(shù)

int get_menu_choice(); //接受菜單選擇

void menu();//菜單相應(yīng)

void Show_menu();//顯示菜單

FILE *file_operate(char *mode); //文件操作類型

void set_psw();//設(shè)置密碼

int psw_check();//密碼驗(yàn)證

int Inputonecar(int i);//根據(jù)車位號增加一條記錄

void Inputfile(int i,FILE *fp);//將下標(biāo)為i的記錄寫入文件

void Input(FILE *fp);//向管理系統(tǒng)中增加記錄

int SetPrice();//設(shè)置停車單價(jià)(例如:1for1s

void GetCarByAreaNum(FILE *fp);//根據(jù)車位號取車

/*****以下函數(shù)是為了簡化部分工作從上面的函數(shù)中劃分出來的功能**************/

void PrintTitle();//打印頭信息

void ShowAllCarInfo(); //顯示所有停車信息

void Showonecarinfo(int i);? //顯示停車信息

float countMoney(float danjia);//計(jì)算根據(jù)傳入的單價(jià)來計(jì)算泊車的費(fèi)用

void Readfile(int i,FILE *fp);//從文件中讀取一條記錄

int CheckNumber(int areaNum_temp);//檢查車位號是否為空,存在返回序號,如果該車位有停車則返回-1

char* GetTime();//獲取當(dāng)前時(shí)間

int Cost(char *time1,int danjia);//根據(jù)單價(jià)和時(shí)間差來計(jì)算停車消費(fèi)的價(jià)格


int Cost2(int h,int m,int danjia);

void GetCarByAreaNum2(FILE *fp);

int timeh();

int timem();

/***************函數(shù)的實(shí)現(xiàn)****************************************/

//獲取當(dāng)前系統(tǒng)時(shí)間

char* GetTime()

{

? ? {

? ? ? ? time_t now;

? ? ? ? struct tm *timenow;

? ? ? ? time(&now);

? ? ? ? timenow = localtime(&now);

? ? char *p = asctime(timenow);

? ? return p;

? ? }

}

//返回當(dāng)前小時(shí)

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;

}

//返回當(dāng)前分鐘

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("輸入菜單選項(xiàng):");

? ? ? ? scanf("%d",&menu_ch);

? ? ? ? if((menu_ch<0)||(menu_ch>9))

? ? ? ? ? ? printf("輸入錯(cuò)誤!");

? ? } while ((menu_ch<0)||(menu_ch>9));

? ? return menu_ch;

}

//顯示菜單

void Show_menu()

{

? ? printf(">>>>>>>>>>>>>>>歡迎使用泊車管理系統(tǒng)<<<<<<<<<<<<<<<<\n");

? ? printf("************************************************\n");

? ? printf("* ? 1.新增停車信息 ? ? ? ? | ? 2.顯示所有停車信息 ? *\n");

? ? printf("* ? 3.按照車牌號取車 ? ? ? | ? 4.按照車位號取車 ? ? *\n");

? ? printf("* ? 5.按照車牌號查詢車信息? | ? 6.按照車位號查詢車信息*\n");

? ? printf("* ? 7.設(shè)置泊車單價(jià) ? ? ? ? | ? 8.密碼設(shè)置 ? ? ? ? *\n");

? ? printf("* ? 9.主動清屏? ? ? ? ? ? | ? 0.退出 ? ? ? ? ? ? *\n");

? ? printf("************************************************\n");

}

//清屏,有點(diǎn)問題

//void clear()

//{

//? ? system("pause");

//? ? system("cls");

//}


//菜單響應(yīng)

void menu()

{

? ? while (1) {

? ? ? ? Show_menu();

? ? ? ? switch (get_menu_choice()) {

? ? ? ? ? ? case 1://新增停車信息

? ? ? ? ? ? ? ? Input(file_operate("ab"));? //二進(jìn)制追加寫入

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? case 2://顯示所有泊車信息

? ? ? ? ? ? ? ? ShowAllCarInfo();

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? case 3://按照車牌好取車

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? case 4://按照車位號取車

? ? ? ? ? ? ? ? GetCarByAreaNum2(file_operate("wb"));

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? case 5://按照車牌號查詢車位信息

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? case 6: //按照車位號查詢車位信息

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? case 7://設(shè)置停車價(jià)格(例如:1for1s

? ? ? ? ? ? ? ? SetPrice();

? ? ? ? ? ? ? ? break;

?? ? ? ? ? ? case 8://密碼設(shè)置

? ? ? ? ? ? ? ? set_psw();

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? case 9://手動清屏

? ? ? ? ? ? ? ? //clear();

? ? ? ? ? ? ? ? printf("手動清屏有誤!");

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? case 0://結(jié)束程序

? ? ? ? ? ? ? ? //system("cls");

? ? ? ? ? ? ? ? printf("*********************\n");

? ? ? ? ? ? ? ? printf(" ? ? 歡迎使用本系統(tǒng) ? ? \n");

? ? ? ? ? ? ? ? printf("**********************\n");

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? //exit(0);

? ? ? ? ? ? default:

? ? ? ? ? ? ? ? break;

? ? ? ? }

? ? }

}

//打印頭信息

void PrintTitle()

{

? ? printf("-------------------------------------------------------------\n");

? ? printf(" ? 車牌號? ? ? ? ? 車型 ? 停泊車位號? ? ? ? ? 停泊開始時(shí)間 ? \n");

? ? printf("-------------------------------------------------------------\n");

}



//初始化,文件不存在,則建立,同時(shí)記錄下文件中的記錄數(shù)

void Init()

{

? ? int ii;

? ? FILE *fp;

? ? total=0;

? ? if((fp=fopen("stopedcar.txt","rb"))==NULL)

? ? {

? ? ? ? fp=fopen("stopedcar.txt","ab");

? ? ? ? //clear();

? ? ? ? menu();

? ? }

? ? else

? ? {

? ? ? ? for(ii=0;feof(fp)==0;ii++) ? //feof檢查文件是否結(jié)束

? ? ? ? {

? ? ? ? ? ? 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("stopedcar.txt",mode))==NULL)

? ? ? ? {

? ? ? ? ? ? puts("Fail to open the file!");

? ? ? ? ? ? puts("Try again!(Y/N)?");

? ? ? ? ? ? scanf("%c",&choice);

? ? ? ? }

? ? ? ? else

? ? ? ? ? ? fp=fopen("stopedcar.txt",mode);

? ? }

? ? while(choice=='y'||choice=='Y');

? ? if(choice=='n'||choice=='N'){}

? ? ? ? //exit(1); //異常退出? exit(0);系統(tǒng)正常退出

? ? 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個(gè)記錄:\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;

}

//根據(jù)車位號增加一條記錄

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("該車位已經(jīng)停了車!\n");

? ? ? ? return 0;

? ? }

? ? //如果該車位沒有停車

? ? else

? ? {

? ? ? ? stopedcar[i].areaNum=areaNum;? //將停車的車位號記錄為當(dāng)前的車位號

? ? ? ? printf("Input 車牌號(less than 20 chars):");

? ? ? ? scanf("%s",stopedcar[i].carNum);

? ? ? ? printf("車型號(例如:baomaX6):");

? ? ? ? scanf("%s",&stopedcar[i].carshap);

? ? ? ? char *time=GetTime();//獲取當(dāng)前系統(tǒng)時(shí)間

? ? ? ? stopedcar[i].h=timeh();//記錄小時(shí)

? ? ? ? stopedcar[i].m=timem();//記錄分鐘

? ? ? ? char *q=stopedcar[i].stopedTime;

? ? ? ? strcpy(q, time);//將當(dāng)前時(shí)間賦值給car.StopedTime

? ? ? ? PrintTitle();

? ? ? ? Showonecarinfo(i);

? ? ? ? //Inputfile(i,fp);

? ? ? ? return 1;

? ? }

}

//把下標(biāo)為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);

}

//向管理系統(tǒng)中增加記錄

void Input(FILE *fp)

{

? ? int i;

? ? i=total;

? ? if(Inputonecar(i))

? ? {

? ? ? ? total++;

? ? ? ? Inputfile(i,fp);

? ? }

? ? fclose(fp);

}


//設(shè)置泊車單價(jià)

int SetPrice()

{

? ? printf("請?jiān)O(shè)置泊車單價(jià):(例如:1for 1 m\n");

? ? scanf("%d",&price);

? ? printf("您設(shè)置的單價(jià)是:%d1M\n",price);

? ? return price;

}

int Cost2(int h,int m,int danjia)

{

? ? int money;

? ? //獲取當(dāng)前小時(shí)和分鐘

? ? int hnow=timeh();

? ? int mnow=timem();

? ? return money=((hnow-h)*60+(mnow-m))*danjia;

}

//根據(jù)單價(jià)和時(shí)間差來計(jì)算停車消費(fèi)的價(jià)格

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;

}

//根據(jù)車位號取車

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);//根據(jù)車位號來查詢是第幾個(gè)

? ? ? ? printf("確認(rèn)取車?(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的停車費(fèi)\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");

}

//根據(jù)車位號取車

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);//根據(jù)車位號來查詢是第幾個(gè)

? ? ? ? printf("確認(rèn)取車?(1./2.否)");

? ? ? ? scanf("%d",&choice2);

? ? ? ? if(choice2==1)

? ? ? ? {

? ? ? ? ? ? char *time1=stopedcar[i].stopedTime;

? ? ? ? ? ? printf(time1);

? ? ? ? ? ? printf("您需要支付¥%d的停車費(fèi)\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");

}


//設(shè)置密碼

void set_psw()

{

? ? char psw_set[20],psw_check[20],c;

? ? unsigned int 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("password.txt","wb");

? ? fprintf(fp,"%s",password);

? ? fclose(fp);

}

//密碼驗(yàn)證

int psw_check()

{

? ? unsigned int i=1,j=1;

? ? FILE *fp;

? ? char pword[20],c;

? ? if((fp=fopen("password.txt","rb"))==NULL)

? ? {

? ? ? ? fp=fopen("password.txt","a");

? ? ? ? set_psw();

? ? }

? ? fscanf(fp,"%s",password);

? ? fclose(fp);

? ? do

? ? {

? ? ? ? printf("\nInput passwordkey'.'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;

}


轉(zhuǎn)載于:https://blog.51cto.com/dingxiaowei/1366853

總結(jié)

以上是生活随笔為你收集整理的C[泊车管理系统]的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。