第一篇:C語言課程設計《高速公路聯網收費系統》代碼
作者:吳俠志
就讀院校:東莞理工學院
#include “stdafx.h” #define NUM 4 #define max_len 8 #include
char *mytime(struct tm *timeptr);
//獲取系統時間的函數 void Delay(int n);//延時函數 char *filename(int startkey);void initialize(struct car *cars,int num,FILE *fp);///初始化函數 int refer(struct car *cars,int startkey);//查詢
int km[10]={0,0,82,162,288,368,391,514,800,867};
/* 記錄各站與首站的里程,單位:km */ double price[6]={0.0,0.6,1.2,1.8,2.4,3.0};
/* 記錄各類車的里程價位,單位:元/輛公里 */ char *address[10]={“0”,“湛江”,“茂名”,“陽江”,“開平”,“佛山”,“廣州”,“深圳”,“汕頭”,“汾水”};char *kind[6]={“特殊車”,“一類車”,“二類車”,“三類車”,“四類車”,“五類車”};
struct car { int card_num;
/* 卡號 */ int car_type;int station_in;char time_in[26];int station_out;char time_out[26];char is_in;double money;int flag;}cars[9*NUM+1];
int num=0;int pass=0;int main(int argc, char* argv[]){ int i,key,choice,j,k,m,size;double pay,money;char enter,pwd[max_len+1],password[max_len+1],ch;FILE *fp;fp=fopen(“標記.txt”,“a+”);fclose(fp);
fp=fopen(“記錄.txt”,“a+”);
fclose(fp);
printf(“t歡迎登錄廣東同三高速公路聯網收費系統n”);printf(“┏━━━━━━━━━━━━━━━━━━━━┓n”);printf(“┃
1.湛江
2.茂名
3.陽江
┃n”);printf(“┃
4.開平
5.佛山
6.廣州
┃n”);printf(“┃
7.深圳
8.汕頭
9.汾水關
┃n”);printf(“┗━━━━━━━━━━━━━━━━━━━━┛n”);printf(“請選擇所在站點,并輸入該序號:”);int startkey;while(1){
fflush(stdin);
while(scanf(“%d%c”,&startkey,&enter)==0 || enter!='n')
{
printf(“terror!!input again:”);
fflush(stdin);
}
if(startkey==1 || startkey==2 || startkey==3 || startkey==4 || startkey==5 || startkey==6 || startkey==7 || startkey==8 || startkey==9)
{
break;
}
else
{
printf(“terror!!input again:”);
continue;
} } printf(“初始化中……”);
fp=fopen(“標記.txt”,“a+”);fscanf(fp,“%d”,&num);fclose(fp);
fp=fopen(“password.txt”,“a+”);fscanf(fp,“%d”,&pass);fclose(fp);if(pass==0)
{
} fp=fopen(“password.txt”,“w+”);fprintf(fp,“%d”,88888888);fclose(fp);
fp=fopen(“記錄.txt”,“a+”);rewind(fp);initialize(cars,num,fp);
fclose(fp);Delay(5);time_t timer;struct tm *tblock,*a;timer=time(NULL);a=localtime(&timer);while(1){ system(“cls”);fflush(stdin);printf(“所在地:%s站n登錄時間:%sn”,address[startkey],mytime(a));printf(“┏━━━━━━━━━━━━━━━━━━━━━┓n”);printf(“┃
1.發卡
┃n”);printf(“┃
2.檢卡并收費
┃n”);printf(“┃
3.查詢
┃n”);printf(“┃
4.注銷并退出系統
┃n”);printf(“┃
5.退出系統
┃n”);printf(“┗━━━━━━━━━━━━━━━━━━━━━┛n”);printf(“請選擇,并輸入序號:”);while(1){
while(scanf(“%d%c”,&key,&enter)==0 || enter!='n')
{
printf(“terror!!input again:”);
fflush(stdin);
}
fp=fopen(“標記.txt”,“r+”);
fscanf(fp,“%d”,&num);
fclose(fp);
fp=fopen(“記錄.txt”,“r+”);
rewind(fp);
initialize(cars,num,fp);
fclose(fp);
j=0;
for(i=1;i<=9*NUM;i++){
if(cars[i].is_in=='y' && cars[i].station_in!=startkey && cars[i].station_out==0)
{
j++;
break;
} } k=0;for(m=1;m<=9*NUM;m++){
if(cars[m].is_in=='n' && cars[m].station_in==0 && cars[m].station_out==startkey)
{
k++;
cars[m].flag=k;
} } if((key==1 && k>0)||(key==2 && j>0)|| key==3 || key==4 || key==5)break;else if(key==2 && j==0){
printf(“t目前尚無車輛要離站!!input again:”);
fflush(stdin);
continue;} else if(key==1 && k==0){
printf(“t目前卡片不足!!input again:”);
fflush(stdin);
continue;} else {
printf(“terror!!input again:”);
fflush(stdin);
continue;} } if(key==1){ system(“cls”);timer=time(NULL);tblock=localtime(&timer);srand((unsigned)time(NULL));//用即時的系統時間來做隨機數種子.生成隨機數
choice=(rand()%k)+1;//隨機生成choice,格式rand()%k即要求產生k以內的
for(m=1;m<=9*NUM;m++)
{
if(cars[m].is_in=='n' && cars[m].station_in==0 && cars[m].station_out==startkey && cars[m].flag==choice)
{
break;
}
}
printf(“卡號是:%dn現在時間是:%sn”,m,mytime(tblock));
cars[m].station_in=startkey;
cars[m].station_out=0;
strcpy(cars[m].time_in,mytime(tblock));
strcpy(cars[m].time_out,“無”);
num=1;
fp=fopen(“標記.txt”,“w+”);
fprintf(fp,“%d”,num);
fclose(fp);
fp=fopen(“記錄.txt”,“w+”);
for(i=1;i<=9*NUM;i++)
{
fprintf(fp,“%d %d %c %lf %d %d %st%stn”,cars[i].card_num,cars[i].car_type,cars[i].is_in,cars[i].money,cars[i].station_in,cars[i].station_out,cars[i].time_in,cars[i].time_out);
}
fclose(fp);
printf(“┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓n”);
printf(“┃0.特殊車:軍警車、緊急車
┃n”);
printf(“┃1.一類車:小轎車、吉普車、的士頭人貨車、摩托車
┃n”);
printf(“┃2.二類車:面包車、小型人貨車、輕型貨車、小型客車
┃n”);
printf(“┃3.三類車:中型客車、大型普通客車、中型貨車、大型豪華客車┃n”);
printf(“┃4.四類車: 大型貨車、大型拖(掛)車、20英尺集裝箱車
┃n”);
printf(“┃5.五類車: 重型貨車、重型拖(掛)車、40英尺集裝箱車
┃n”);
printf(“┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛n”);
printf(“請選擇車型,并輸入序號:”);
while(1)
{
fflush(stdin);
while(scanf(“%d%c”,&size,&enter)==0 || enter!='n')
{
printf(“terror!!input again:”);
fflush(stdin);
}
if(size==0 || size==1 || size==2 || size==3 || size==4 || size==5)break;
else
{
printf(“terror!!input again:”);
continue;
}
}
cars[m].is_in='y';
cars[m].car_type=size;
fp=fopen(filename(startkey),“a+”);
fprintf(fp,“%30s%8d%12s%20snn”,mytime(tblock),m,kind[cars[m].car_type],“發卡,放行”);
fclose(fp);
fp=fopen(“標記.txt”,“w+”);
fprintf(fp,“%d”,num);
fclose(fp);
fp=fopen(“記錄.txt”,“w+”);
for(i=1;i<=9*NUM;i++)
{
fprintf(fp,“%d %d %c %lf %d %d %st%stn”,cars[i].card_num,cars[i].car_type,cars[i].is_in,cars[i].money,cars[i].station_in,cars[i].station_out,cars[i].time_in,cars[i].time_out);
}
fclose(fp);
printf(“登記完畢,請發卡放行,并按任意鍵回到主菜單a”);
getche();
}
else if(key==2)
{
system(“cls”);
printf(“請輸入卡號(按0返回):”);
while(1)
{
ch='y';
fflush(stdin);
while(scanf(“%d%c”,&choice,&enter)==0 || enter!='n')
{
printf(“terror!!input again:”);
fflush(stdin);
}
fp=fopen(“標記.txt”,“r+”);
fscanf(fp,“%d”,&num);
fclose(fp);
fp=fopen(“記錄.txt”,“r+”);
rewind(fp);
initialize(cars,num,fp);
fclose(fp);
if(choice<0 || choice>9*NUM)
{
printf(“無此卡號...ntinput again:”);
continue;
}
else if(choice==0)
{
ch='n';
break;
}
else if(choice>0 && choice<=9*NUM && cars[choice].is_in=='n')
{
printf(“該卡號尚未發布...ntinput again:”);
continue;
}
else if(choice>0 && choice<=9*NUM && cars[choice].is_in=='y' && cars[choice].station_in!=startkey && cars[choice].station_out==0)
{
break;
}
else if(choice>0 && choice<=9*NUM && cars[choice].is_in=='y' && cars[choice].station_in==startkey && cars[choice].station_out==0)
{
printf(“該卡號車于%s從本站進入高速,尚在行...ntinput again:”,cars[choice].time_in);
continue;
}
else
{
printf(“terror!!input again:”);
continue;
}
}
if(ch=='n')continue;
cars[choice].station_out=startkey;
fp=fopen(“記錄.txt”,“w+”);
for(i=1;i<=9*NUM;i++)
{
fprintf(fp,“%d %d %c %lf %d %d %st%stn”,cars[i].card_num,cars[i].car_type,cars[i].is_in,cars[i].money,cars[i].station_in,cars[i].station_out,cars[i].time_in,cars[i].time_out);
}
fclose(fp);
if(cars[choice].car_type==0)
{
printf(“該車于%s在%s進入高速,為特殊車,無需收費n”,cars[choice].time_in,address[cars[choice].station_in]);
}
else
{
i=abs(km[cars[choice].station_in]-km[cars[choice].station_out]);
money=cars[choice].money=i*price[cars[choice].car_type];
printf(“該車于%s在%s進入高速,需繳費%.1lf款:”,cars[choice].time_in,address[cars[choice].station_in],cars[choice].money);
fflush(stdin);
while(1)
{
while(scanf(“%lf%c”,&pay,&enter)==0 || enter!='n')
{
printf(“terror!!input again:”);
fflush(stdin);
}
if(pay>money)
{
printf(“繳付%.1lf元,找零%.1lf元...n”,pay,pay-money);
money=0;
break;
}
else if(pay { money=money-pay; printf(“繳付%.1lf元,需再繳付%.1lf元:”,pay,money); continue; } else { printf(“已繳費完畢,共收取人民幣%.1lf元...n”,cars[choice].money); break; } } } timer=time(NULL); tblock=localtime(&timer); printf(“現在時間是:%sn”,mytime(tblock)); strcpy(cars[choice].time_out,mytime(tblock)); 元,請付 fp=fopen(“檔案.txt”,“a+”); fprintf(fp,“%5d%12s%15s%30s%10.1lf元n”,choice,kind[cars[choice].car_type],address[cars[choice].station_in],cars[choice].time_in,cars[choice].money); fprintf(fp,“%32s%30snn”,address[cars[choice].station_out],cars[choice].time_out); fclose(fp); cars[choice].money=0; cars[choice].is_in='n'; cars[choice].station_in=0; cars[choice].station_out=startkey; strcpy(cars[choice].time_in,“無”); strcpy(cars[choice].time_out,“無”); fp=fopen(filename(startkey),“a+”); if(cars[choice].car_type==0)fprintf(fp,“%30s%8d%12s%20snn”,mytime(tblock),choice,kind[cars[choice].car_type],“收卡,放行”); else fprintf(fp,“%30s%8d%12s%20snn”,mytime(tblock),choice,kind[cars[choice].car_type],“繳費,收卡,放行”); fclose(fp); cars[choice].car_type=0; fp=fopen(“記錄.txt”,“w+”); for(i=1;i<=9*NUM;i++) { fprintf(fp,“%d %d %c %lf %d %d %st%stn”,cars[i].card_num,cars[i].car_type,cars[i].is_in,cars[i].money,cars[i].station_in,cars[i].station_out,cars[i].time_in,cars[i].time_out); } fclose(fp); printf(“請收卡放行,并按任意鍵回到主菜單a”); getche(); } else if(key==3) { system(“cls”); refer(cars,startkey); } else if(key==4) { while(1) { system(“cls”); printf(“input password: ”); for(i=0;;) { fflush(stdin); ch=getch();if(ch=='r' || ch=='n') { break;} else if(ch=='b'){ if(i-->0) { pwd[i]='
主站蜘蛛池模板:
黄色视频在线免费观看|
亚洲av福利天堂一区二区三|
国产成人精品永久免费视频|
亚洲熟妇另类久久久久久|
亚洲综合色婷婷在线影院p厂|
中文字幕精品亚洲人成在线|
亚洲乱码日产精品bd在|
日本国产成人国产在线播放|
成片免费观看视频大全|
国产狂喷水潮免费网站www|
а天堂中文最新一区二区三区|
97人妻精品一区二区三区|
日日日日做夜夜夜夜无码|
精品日产卡一卡二卡国色天香|
欧美做受又硬又粗又大视频|
日本高清中文字幕免费一区二区|
无码人妻丰满熟妇区五十路在线|
国产av无码一区二区二三区j|
丰满人妻熟妇乱又伦精品视频三|
一本久久精品一区二区|
久久这里精品国产99丫e6|
玖玖资源站最稳定网址|
日韩人妻精品一区二区三区视频|
国外精品视频在线观看免费|
亚洲国产精品嫩草影院|
国产精品爆乳在线播放第一人称|
内射国产内射夫妻免费频道|
男人靠女人免费视频网站|
国产成+人+综合+亚洲欧美丁香花|
少妇高潮潮喷到猛进猛出小说|
国产二级一片内射视频播放|
人人妻人人爽人人澡欧美一区|
日本xxxx片免费观看|
www插插插无码视频网站|
国产精品日本亚洲777|
国产精品成人va在线观看|
国产亚洲精品成人aa片新蒲金|
国产在线精品视频二区|
天堂v亚洲国产ⅴ第一次|
樱花草在线社区www中国中文|
国产亚洲精选美女久久久久|