交通处罚单管理系统(C语言课程设计).doc
交通处罚单管理系统中国地质大学(武汉) 地球科学学院 014072班2010-11-26用C语言编写一个简单的模拟交通处罚单管理系统要求 交通处罚单涉及到车辆、驾驶员和开单交警的信息,还有交通处罚单号码、处罚时间等信息;功能(1) 要求可以输入、删除、浏览交通处罚单信息;(2) 可以按车辆、驾驶员和开单交警查询;(3) 统计某段时间某个驾驶员的交通处罚单数目及交通处罚单号;源代码:#include<stdio.h>#include<string.h>#include<stdlib.h>#define N 100struct Plist /处罚单 char vno20; /车牌号 char dname20; /驾驶员姓名 char pname20; /交警姓名 char pno20; /交警编号 char no20; /处罚单编号 char date20; /处罚日期 listN; /处罚单数组void input(); /输入模块void dele(); /删除模块void browse(); /浏览模块void search(); /查询模块void count(); /统计模块void menu(); /主菜单void vno_search(); /按车牌号查询void dna_search(); /按驾驶员姓名查询void pna_search(); /按开单交警姓名查询main() menu(); getchar();void menu() int n; int r; do system("cls"); printf("ntttt交通处罚单管理系统n"); printf("········································"); printf(" 菜单: 1-信息录入 2-信息删除 3-信息浏览 4-信息查询 5-信息统计 6-退出系统n"); printf("········································"); printf("请从输入数字选择相应的功能:"); scanf("%d",&n); if(n<1|n>6) r=1;getchar(); else r=0;while(r=1);switch(n) case 1:input();break; case 2:dele();break; case 3:browse();break; case 4:search();break; case 5:count();break; case 6:exit(0); void input() FILE*fp; int num; int i,j; if(fp=fopen("list.txt","r+")=NULL) if(fp=fopen("list.txt","w")=NULL) printf("文件打开或创建失败!n"); printf("npress enter to return menun"); getchar(); menu(); printf("n请输入处罚单数量:"); scanf("%d",&i); printf("nn"); for(j=0;j<i;j+) printf("输入第%d张处罚单的:n",j+1); printf("n 车牌号、驾驶员姓名、交警姓名、交警号、处罚单号、日期(如20101112)n"); printf("n注意:中间用空格隔开!n"); scanf("%s%s%s%s%s%s",&listj.vno,&listj.dname,&listj.pname,&listj.pno,&listj.no,&listj.date); for(j=0;j<i;j+) fprintf(fp,"n%st%st%st%st%st%s",listj.vno,listj.dname,listj.pname,listj.pno,listj.no,listj.date); fclose(fp); printf("n保存成功!"); printf("npress enter to return menun"); getchar(); getchar(); menu(); printf("n请输入处罚单数量:"); scanf("%d",&i); for(j=0;!feof(fp);j+) /读取文件 fscanf(fp,"%s%s%s%s%s%s",&listj.vno,&listj.dname,&listj.pname,&listj.pno,&listj.no,&listj.date); num=j+i; if(num>N) printf("n结构体数组数的N太小,请先修改N的值n"); printf("npress enter to return menun"); getchar(); getchar(); menu(); printf("n"); for(j=0;j<i;j+) printf("输入第%d张处罚单的:n",j+1); printf("n车牌号、驾驶员姓名、交警姓名、交警号、处罚单号、日期(如20101112)n"); printf("n注意:中间用空格隔开!n"); scanf("%s%s%s%s%s%s",&listj.vno,&listj.dname,&listj.pname,&listj.pno,&listj.no,&listj.date); for(j=0;j<i;j+) fprintf(fp,"n%st%st%st%st%st%s",listj.vno,listj.dname,listj.pname,listj.pno,listj.no,listj.date); fclose(fp); printf("n保存成功!"); printf("npress enter to return menun"); getchar(); getchar(); menu();void dele() int j; int num; int f=-1; FILE*fp1,*fp2; char s120; if(fp1=fopen("list.txt","r")=NULL) printf("can not open filen"); printf("npress enter to return menun"); getchar(); getchar(); menu(); for(j=0;!feof(fp1);j+) /读取文件 fscanf(fp1,"%s%s%s%s%s%s",&listj.vno,&listj.dname,&listj.pname,&listj.pno,&listj.no,&listj.date); num=j; fclose(fp1); printf("请输入要删除的处罚单的编号n"); scanf("%s",s1); for(j=0;j<num;j+) if(strcmp(s1,listj.no)=0) f=j; if(f<num-1) for(j=f;j<num-1;j+) strcpy(listj.vno,listj+1.vno); strcpy(listj.dname,listj+1.dname); strcpy(listj.pname,listj+1.pname); strcpy(listj.pno,listj+1.pno); strcpy(listj.no,listj+1.no); strcpy(listj.date,listj.date); if(fp2=fopen("list.txt","w")=NULL) printf("文件打不开!n"); printf("npress enter to return menun"); getchar(); menu(); for(j=0;j<num-1;j+) /保存文件 fprintf(fp2,"n%st%st%st%st%st%s",listj.vno,listj.dname,listj.pname,listj.pno,listj.no,listj.date); fclose(fp2); printf("n删除成功!n"); printf("npress enter to return menun"); getchar(); getchar(); menu(); if(f<0) printf("n没有找到该学号的记录:n"); printf("npress enter to return menun"); getchar(); getchar(); menu(); void browse() int j; int num; FILE*fp; if(fp=fopen("list.txt","r")=NULL) printf("can not open filen"); printf("npress enter to return menun"); getchar(); getchar(); menu(); for(j=0;!feof(fp);j+) /读取文件 fscanf(fp,"%s%s%s%s%s%s",&listj.vno,&listj.dname,&listj.pname,&listj.pno,&listj.no,&listj.date); fclose(fp); num=j; printf("n已添加%d条记录nn",num); printf("车牌号 驾驶员姓名 交警姓名 交警编号 处罚单编号 处罚日期n"); for(j=0;j<num;j+) /输出 printf("n%st%st%st%st%st%s",listj.vno,listj.dname,listj.pname,listj.pno,listj.no,listj.date); printf("npress enter to return menun"); getchar(); getchar(); menu();void search() int n; int r; do system("cls"); printf("n请选择查询类型:nt1-按车牌号 2-按驾驶员姓名3:按开单交警姓名 4-返回主菜单n"); printf("n请输入数字选择:"); scanf("%d",&n); if(n<1|n>4) r=1; getchar(); else r=0;while(r=1);switch(n) case 1:vno_search();break;case 2:dna_search();break;case 3:pna_search();break;case 4:menu(); void vno_search() int f=-1; int num; int j; char no20; FILE*fp; if(fp=fopen("list.txt","r")=NULL) printf("文件打不开!n"); printf("npress enter to return menun"); getchar(); menu(); for(j=0;!feof(fp);j+) /读取文件 fscanf(fp,"%s%s%s%s%s%s",&listj.vno,&listj.dname,&listj.pname,&listj.pno,&listj.no,&listj.date); num=j; fclose(fp); printf("n请输入车牌号:"); scanf("%s",no); printf("n罚单的信息为:nn"); printf("车牌号 驾驶员姓名 交警姓名 交警编号 处罚单编号 处罚日期n"); for(j=0;j<num;j+) if(strcmp(no,listj.vno)=0) f=j; printf("n%st%st%st%st%st%s",listj.vno,listj.dname,listj.pname,listj.pno,listj.no,listj.date); if(f<0) printf("n没有找到该班号的记录!n"); printf("npress enter to return sub menun"); getchar(); getchar(); search();void dna_search() int f=-1; int num; int j; char name20; FILE*fp; if(fp=fopen("list.txt","r")=NULL) printf("文件打不开!n"); printf("npress enter to return menun"); getchar(); menu(); for(j=0;!feof(fp);j+) /读取文件 fscanf(fp,"%s%s%s%s%s%s",&listj.vno,&listj.dname,&listj.pname,&listj.pno,&listj.no,&listj.date); num=j; fclose(fp); printf("n请输入驾驶员的姓名:"); scanf("%s",name); printf("n罚单的信息为:nn"); printf("车牌号 驾驶员姓名 交警姓名 交警编号 处罚单编号 处罚日期n"); for(j=0;j<num;j+) if(strcmp(name,listj.dname)=0) f=j; printf("n%st%st%st%st%st%s",listj.vno,listj.dname,listj.pname,listj.pno,listj.no,listj.date); if(f<0) printf("n没有找到该班号的记录!n"); printf("npress enter to return sub menun"); getchar(); getchar(); search();void pna_search() int f=-1; int num; int j; char name20; FILE*fp; if(fp=fopen("list.txt","r")=NULL) printf("文件打不开!n"); printf("npress enter to return menun"); getchar(); menu(); for(j=0;!feof(fp);j+) /读取文件 fscanf(fp,"%s%s%s%s%s%s",&listj.vno,&listj.dname,&listj.pname,&listj.pno,&listj.no,&listj.date); num=j; fclose(fp); printf("n请输入开单交警的姓名:"); scanf("%s",name); printf("n罚单的信息为:nn"); printf("车牌号 驾驶员姓名 交警姓名 交警编号 处罚单编号 处罚日期n"); for(j=0;j<num;j+) if(strcmp(name,listj.pname)=0) f=j; printf("n%st%st%st%st%st%s",listj.vno,listj.dname,listj.pname,listj.pno,listj.no,listj.date); if(f<0) printf("n没有找到该班号的记录!n"); printf("npress enter to return sub menun"); getchar(); getchar(); search();void count() int f=-1; int num; /所有罚单单数 int j; int total=0; /某驾驶员的罚单数 char name20; char time120; char time220; FILE*fp; if(fp=fopen("list.txt","r")=NULL) printf("文件打不开!n"); printf("npress enter to return menun"); getchar(); menu(); for(j=0;!feof(fp);j+) /读取文件 fscanf(fp,"%s%s%s%s%s%s",&listj.vno,&listj.dname,&listj.pname,&listj.pno,&listj.no,&listj.date); num=j; fclose(fp); printf("n请根据提示输入驾驶员的姓名和一个时间段,统计某个驾驶员在某段时间内的处罚单数目和罚单号n"); printf("nn请输入驾驶员的姓名:"); scanf("%s",name); printf("n请输入一个较早的时间:"); scanf("%s",time1); printf("n请输入一个最近的时间:"); scanf("%s",time2); for(j=0;j<num;j+) if(strcmp(listj.date,time1)>=0)&&(strcmp(listj.date,time2)<=0) f=j; total+; printf("n罚单号:%sn",listj.no); if(f<0) printf("n没有找到记录!n"); printf("n罚单总数为:%dn",total); printf("npress enter to return menun"); getchar(); getchar(); menu();