高速公路计费系统_高速公路计费系统设计

2020-02-27 其他范文 下载本文

高速公路计费系统由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“高速公路计费系统设计”。

C课设:高速公路计费系统

作者:周岳

C课设:高速公路计费系统第

printf(“**************************欢迎使用高速公路计费系统***************************”);printf(“nnnn”);if((fp=fopen(“vehicle.txt”,“r”))==NULL)

{

printf(“tt未找到目标文件,系统将为您创建该文件!”);//打开程序,系统首先检查是否存在vehicle文件,若不存在将自动创建文件

fp=fopen(“vehicle.txt”,“w+”);

printf(“ntt***************************************************”);

printf(“ntt*

文件已建立!

*”);

printf(“ntt*

按任意键进入菜单!

*”);

printf(“ntt***************************************************”);

getch();

return;

}

fseek(fp,0,2);

//以下部分作用为检测文件是否为空

if(ftell(fp)>0)

{

fseek(fp,0,0);

for(count=0;!feof(fp)&&fread(&vehicle[count],sizeof(struct vehicle),1,fp);count++);

printf(“ntt***************************************************”);

printf(“ntt*

文件导入成功!

*”);

printf(“ntt*

按任意键进入系统!

*”);

printf(“ntt***************************************************”);

getch();

return;

}

printf(“ntt***************************************************”);printf(“ntt*

已成功打开文件!

*”);

printf(“ntt*

按任意键进入菜单!

*”);

printf(“ntt***************************************************”);getch();

return;}

void menu(){ system(“cls”);

//清屏

char n;printf(“n”);printf(“tt上次保存在磁盘文件中的收费总额为:%.2f元。n”,total());

//通过

作者:周岳

C课设:高速公路计费系统第

total()函数计算上次保存在存盘中的总金额

printf(“nnnnn”);printf(“t

高速公路收费系统!n”);printf(“t╔═════════════════════════════╗n”);

printf(“t║

欢迎使用!

║n”);

printf(“t║┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈║n”);

printf(“t║输入车辆信息显示车辆信息

║n”);

printf(“t║

║n”);

printf(“t║显示车辆总数打印报表

║n”);

printf(“t║

║n”);printf(“t║保存并退出系统

║n”);printf(“t║┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈║n”);

printf(“t╚═════════════════════════════╝n”);

printf(“

请输入数字选择操作类型:n”);n=getch();switch(n){

case '1': input();break;

case '2': show();break;

case '3': all();break;

case '4': print();break;

case '5': writefile();break;

default: break;} }

void input()

//输入车辆信息函数,同时计算费用 { system(“cls”);double l1=100,l2=200,l3=300;

//定义入口,此处有3个入口。里程数分别为100、200、300 printf(“请输入车辆信息n”);printf(“车牌号:n”);scanf(“%s”,&vehicle[count].num);printf(“车辆类型(a,b,c分别代表大,中,小):n”);scanf(“%s”,vehicle [count].variety);printf(“进入时间:n”);scanf(“%s”,&vehicle [count].entime);printf(“入口(1,2,3代表三个入口):n”);scanf(“%s”,&vehicle [count].enter);if((strcmp(vehicle [count].variety,“a”)!=0)&&(strcmp(vehicle [count].variety,“b”)!=0)&&(strcmp(vehicle [count].variety,“c”)!=0))

作者:周岳

C课设:高速公路计费系统第

{

printf(“车辆类型输入错误,请重输!”);

//判断车辆类型是否输入错误

getch();

input();} if(strcmp(vehicle [count].variety,“a”)==0&&strcmp(vehicle [count].enter,“1”)==0)

//以下为计算单车费用部分

vehicle [count].money=0.5*l1;

else if(strcmp(vehicle [count].variety,“a”)==0&&strcmp(vehicle [count].enter,“2”)==0)

vehicle [count].money=0.5*l2;else if(strcmp(vehicle [count].variety,“a”)==0&&strcmp(vehicle [count].enter,“3”)==0)

vehicle [count].money=0.5*l3;else if(strcmp(vehicle [count].variety,“b”)==0&&strcmp(vehicle [count].enter,“1”)==0)

vehicle [count].money=0.4*l1;else if(strcmp(vehicle [count].variety,“b”)==0&&strcmp(vehicle [count].enter,“2”)==0)

vehicle [count].money=0.4*l2;else if(strcmp(vehicle [count].variety,“b”)==0&&strcmp(vehicle [count].enter,“3”)==0)

vehicle [count].money=0.4*l3;else if(strcmp(vehicle [count].variety,“c”)==0&&strcmp(vehicle [count].enter,“1”)==0)

vehicle [count].money=0.3*l1;else if(strcmp(vehicle [count].variety,“c”)==0&&strcmp(vehicle [count].enter,“2”)==0)

vehicle [count].money=0.3*l2;else if(strcmp(vehicle [count].variety,“c”)==0&&strcmp(vehicle [count].enter,“3”)==0)

vehicle [count].money=0.3*l3;count++;printf(“n”);printf(“是否继续添加(Y/N)n”);if(getch()=='y'||getch()=='Y')

input();}

void show()

//输出车辆信息函数 {

system(“cls”);char num[8];char enter[2];int i;printf(“请输入车牌号:n”);scanf(“%s”,num);for(i=0;i

//检索部分

{

if(strcmp(vehicle[i].num,num)==0)

{

作者:周岳

C课设:高速公路计费系统第

printf(“车辆信息:n”);

printf(“车牌号:%sn”,vehicle[i].num);

if(strcmp(vehicle[i].variety,“a”)==0)

printf(“车辆类型:大n”);

if(strcmp(vehicle[i].variety,“b”)==0)

printf(“车辆类型:中n”);

if(strcmp(vehicle[i].variety,“c”)==0)

printf(“车辆类型:小n”);

printf(“入口站:%sn”,vehicle[i].enter);

printf(“进入时间:%sn”,vehicle[i].entime);

printf(“该车应缴费为:%.2f元n”,vehicle[i].money);

break;

} } if((i==count)&&(strcmp(vehicle[i].num,num)!=0))//因为在上面for循环中使用了break语句,所以当检索到车辆信息时会跳出循环,此时

{

//i的值一般不会达到count,要判断是否有匹配信息,则需先检测i值是否达到count,再

printf(“无此车!请重输!”);

//进一步判断第count条信息是否为所要查找的内容。

getch();

show();} printf(“n”);printf(“是否继续查看(Y/N)n”);if(getch()=='y'||getch()=='Y')

show();}

void writefile()

//写入、保存函数 {

int i;

if((fp=fopen(“vehicle.txt”,“w”))==NULL)

{

printf(“ntt文件打开失败”);

}

for(i=0;i

{

if(fwrite(&vehicle[i],sizeof(struct vehicle),1,fp)!=1)

{

printf(“ntt写入文件错误!n”);

}

}

作者:周岳

C课设:高速公路计费系统第

fclose(fp);

printf(“ntt 文件已保存”);

printf(“ntt按任意键退出程序ntt”);

exit(0);}

void all()

//计算总车数函数 {

system(“cls”);printf(“车辆总数为:%d”,count);getch();}

double total()

//计算总金额函数 { int i=0;double total = 0;for(i=0;i

total = total+vehicle[i].money;return total;}

void print()

//打印报表函数,输出所有信息 { int i;system(“cls”);for(i = 0;i

printf(“车牌号:%sn”,vehicle[i].num);

if(strcmp(vehicle[i].variety,“a”)==0)

printf(“车辆类型:大n”);

if(strcmp(vehicle[i].variety,“b”)==0)

printf(“车辆类型:中n”);

if(strcmp(vehicle[i].variety,“c”)==0)

printf(“车辆类型:小n”);

printf(“入口站:%sn”,vehicle[i].enter);

printf(“进入时间:%sn”,vehicle[i].entime);

printf(“该车应缴费为:%.2f元n”,vehicle[i].money);

printf(“n”);} getch();}

作者:周岳

《高速公路计费系统.docx》
将本文的Word文档下载,方便收藏和打印
推荐度:
高速公路计费系统
点击下载文档
相关专题 高速公路计费系统设计 高速公路 计费系统 高速公路计费系统设计 高速公路 计费系统
[其他范文]相关推荐
    [其他范文]热门文章
      下载全文