#include<stdio.h> #include<stdlib.h> #include<string.h> struct vehicle { int num; char tpy[20]; char ppai[30]; char chepai[20]; char gongsi[30]; struct vehicle *next; }; int n; struct vehicle *w; int main() { struct vehicle *start(); //初始化信息 void print(struct vehicle *h); //输出函数 void log(); //登录界面 void user();//用户登录 void control();//管理员登录 struct vehicle *refers(struct vehicle *h);//按编码查询 struct vehicle *VEH(struct vehicle *h);//按车型查询 void adds();//插入全操作 void dels();//删除全操作 struct vehicle *change(struct vehicle *h);//更改操作 struct vehicle *head; //定义结构体类型变量 int inp1,inp2,inp3; head=start(); //暂存初始信息 A: log(); scanf("%d",&inp1); if(inp1==1) { user(); scanf("%d",&inp2); switch(inp2) { case 1:print(head);goto A;break; case 2:refers(w);goto A;break; case 3:VEH(w);goto A;break; default:break; } } if(inp1==2) { control(); scanf("%d",&inp3); switch(inp3) { case 1:adds();goto A;break; case 2:dels();goto A;break; case 3:change(w);goto A;break; default:break; } } if(inp1==3) { printf("\n\n你已退出!欢迎使用!"); } return 0; } struct vehicle *start() //初始化信息函数 { struct vehicle *a1,*a2,*b1,*b2,*c1,*c2; a1=(struct vehicle *)malloc(sizeof(struct vehicle)); a1->num = 10201;strcpy(a1->tpy,"轿车");strcpy(a1->ppai,"宝马sss"); strcpy(a1->chepai,"川B28393");strcpy(a1->gongsi,"宝马有限公司"); a2=(struct vehicle *)malloc(sizeof(struct vehicle)); a2->num = 10203;strcpy(a2->tpy,"轿车");strcpy(a2->ppai,"奔驰s"); strcpy(a2->chepai,"川B23849");strcpy(a2->gongsi,"奔驰有限公司"); b1=(struct vehicle *)malloc(sizeof(struct vehicle)); b1->num = 10204;strcpy(b1->tpy,"客车");strcpy(b1->ppai,"金杯tpy"); strcpy(b1->chepai,"川B24799");strcpy(b1->gongsi,"金杯有限公司"); b2=(struct vehicle *)malloc(sizeof(struct vehicle)); b2->num = 10206;strcpy(b2->tpy,"客车");strcpy(b2->ppai,"宇通tpy"); strcpy(b2->chepai,"川B93889");strcpy(b2->gongsi,"宇通有限公司"); c1=(struct vehicle *)malloc(sizeof(struct vehicle)); c1->num = 10208;strcpy(c1->tpy,"货车");strcpy(c1->ppai,"东风t"); strcpy(c1->chepai,"川B62834");strcpy(c1->gongsi,"东风有限公司"); c2=(struct vehicle *)malloc(sizeof(struct vehicle)); c2->num = 10211;strcpy(c2->tpy,"货车");strcpy(c2->ppai,"解放t"); strcpy(c2->chepai,"川B24793");strcpy(c2->gongsi,"解放有限公司"); w=a1; a1->next = a2; a2->next = b1; b1->next = b2; b2->next = c1; c1->next = c2; c2->next = NULL; return w; } void log() //登录界面 { printf("\n\n\t******车辆信息管理系统*****"); printf("\n\t\t1、用户登录"); printf("\n\t\t2、管理员登录"); printf("\n\t\t3、退出登录"); printf("\n\n请输入你的操作:"); } void user() //用户登录 { printf("\n\n\t*********用户登录**********"); printf("\n\t\t1、显示信息库"); printf("\n\t\t2、按编号查询"); printf("\n\t\t3、按类别查询"); printf("\n\n请输入你的操作:"); } void control() //管理员登录 { printf("\n\n\t********管理员登录**********"); printf("\n\t\t1、添加车辆信息"); printf("\n\t\t2、删除车辆信息"); printf("\n\t\t3、更改车辆信息"); printf("\n\n请输入你的操作:"); } struct vehicle *refers(struct vehicle *h)//按编码查询 { struct vehicle *p1,*p2,*p0; p2=p1=h; int num; int ch; p0=NULL; while(1) { printf("\n是否需要查询(Y/N): "); do{ ch=getchar(); } while(ch!='Y' && ch!='N'); if(ch=='Y') { printf("\n请输入要查询的编号:"); scanf("%d",&num); while(p1->num!=num && p1->next!=NULL) { p2=p1; p1=p1->next; } if(p1->num == num) { p0=p1; printf("\n车辆信息为:"); printf("\n编码\t车型\t品牌\t\t车牌\t\t公司"); printf("\n%d\t%s\t%s\t\t%s\t%s",p0->num,p0->tpy,p0->ppai,p0->chepai,p0->gongsi); } else{ printf("\n未找到相关数据!"); } } else{ printf("\n查询完毕!你已退出!"); break; } } return h; } struct vehicle *VEH(struct vehicle *h)//按车型查询 { struct vehicle *p1,*p2; p2=p1=h; int retu,ch; while(1) { printf("\n是否需要查询(Y/N): "); do{ ch=getchar(); } while(ch!='Y' && ch!='N'); if(ch=='Y') { char a[30]; printf("\n请输入车型:"); scanf("%s",&a); printf("\n车辆信息为:"); printf("\n编码\t车型\t品牌\t\t车牌\t\t公司"); p1=p2; while(1) { retu=strcmp(a,p1->tpy); if(retu==0) { printf("\n%d\t%s\t%s\t\t%s\t%s",p1->num,p1->tpy,p1->ppai,p1->chepai,p1->gongsi); } if(p1->next==NULL) { break; } p1=p1->next; } } else{ printf("\n查询完毕!"); break; } } return h; } void adds()//插入全操作 { struct vehicle *add(struct vehicle *h,int num,char tpy[20],char ppai[30],char chepai[20],char gongsi[30]); void print(struct vehicle *h); int num; char tpy[20]; char ppai[30]; char chepai[20]; char gongsi[30]; int ch; while(1) { printf("\n是否需要添加(Y/N):"); do{ ch=getchar(); }while(ch!='Y' && ch!='N'); if(ch=='Y') { printf("\n请输入编码、车型、品牌、车牌、公司:"); scanf("\n%d%s%s%s%s",&num,&tpy,&ppai,&chepai,&gongsi); w=add(w,num,tpy,ppai,chepai,gongsi); }else{ printf("\n添加结束!"); break; } } printf("你已退出!"); print(w); } struct vehicle *add(struct vehicle *h,int num,char tpy[20],char ppai[30],char chepai[20],char gongsi[30])//插入关键 { struct vehicle *p1,*p2,*p0; p1=h; p2=NULL; while(p1!=NULL && p1->num<num) { p2=p1; p1=p1->next; } p0=(struct vehicle *)malloc(sizeof(struct vehicle)); p0->num = num; strcpy(p0->tpy,tpy); strcpy(p0->ppai,ppai); strcpy(p0->chepai,chepai); strcpy(p0->gongsi,gongsi); p0->next=p1; if(p2==NULL) { h=p0; }else{ p2->next=p0; } return h; } void dels()//删除全操作 { struct vehicle *del(struct vehicle *h,int num); void print(struct vehicle *h); int num; int ch; while(1) { printf("\n是否需要删除(Y/N): "); do{ ch=getchar(); } while(ch!='Y' && ch!='N'); if(ch=='Y') { printf("\n请输入要删除的编号:"); scanf("%d",&num); w=del(w,num); } else{ printf("\n删除完毕!"); break; } } printf("你已退出!"); print(w); } struct vehicle *del(struct vehicle *h,int num)//删除操作 { struct vehicle *p1,*p2; p1=p2=h; while(p1->next!=NULL && p1->num!=num) { p2=p1; p1=p1->next; } if(p1->num == num) { if(p1==h) { h=p1->next; } else{ p2->next=p1->next; } } else{ printf("\n未找到相关数据!"); } return h; } struct vehicle *change(struct vehicle *h)//更改操作 { struct vehicle *cas1(struct vehicle *h1); struct vehicle *cas2(struct vehicle *h1); struct vehicle *cas3(struct vehicle *h1); struct vehicle *cas4(struct vehicle *h1); struct vehicle *cas5(struct vehicle *h1); void print1(struct vehicle *h1); struct vehicle *p1,*p2,*p0; p2=p1=h; int num; int ch,input; p0=NULL; while(1) { printf("\n是否需要更改(Y/N): "); do{ ch=getchar(); } while(ch!='Y' && ch!='N'); if(ch=='Y') { printf("\n请输入要更改的编号:"); scanf("%d",&num); while(p1->num!=num && p1->next!=NULL) { p2=p1; p1=p1->next; } if(p1->num == num) { p0=p1; printf("\n编码\t车型\t品牌\t\t车牌\t\t公司"); printf("\n%d\t%s\t%s\t\t%s\t%s",p0->num,p0->tpy,p0->ppai,p0->chepai,p0->gongsi); printf("\n*************执行操作******************"); printf("\n1、编码 2、车型 3、品牌 4、车牌 5、公司"); printf("\n请输入你的操作:"); scanf("%d",&input); switch(input) { case 1:p0=cas1(p0);print1(p0); break; case 2:p0=cas2(p0);print1(p0); break; case 3:p0=cas3(p0);print1(p0); break; case 4:p0=cas4(p0);print1(p0); break; case 5:p0=cas5(p0);print1(p0); break; default:printf("输入错误!");break; } } else{ printf("\n未找到相关数据!"); } } else{ printf("\n更改完毕!你已退出!"); break; } } return h; } struct vehicle *cas1(struct vehicle *h1)//编码更改 { struct vehicle *p; p=h1; printf("请输入新的编号:"); scanf("%d",&p->num ); return p; } struct vehicle *cas2(struct vehicle *h1)//车型更改 { struct vehicle *p; p=h1; char a[30]; printf("请输入新的车型:"); scanf("%s",&a); strcpy(p->tpy,a); return p; } struct vehicle *cas3(struct vehicle *h1)//品牌更改 { struct vehicle *p; p=h1; char a[30]; printf("请输入新的品牌:"); scanf("%s",&a); strcpy(p->ppai,a); return p; } struct vehicle *cas4(struct vehicle *h1)//车牌更改 { struct vehicle *p; p=h1; char a[30]; printf("请输入新的车牌:"); scanf("%s",&a); strcpy(p->chepai,a); return p; } struct vehicle *cas5(struct vehicle *h1)//公司更改 { struct vehicle *p; p=h1; char a[30]; printf("请输入新的公司:"); scanf("%s",&a); strcpy(p->gongsi,a); return p; } void print1(struct vehicle *h1) //单个输出 { struct vehicle *p; p=h1; printf("\n已更改!信息为:"); printf("\n编码\t车型\t品牌\t\t车牌\t\t公司"); printf("\n%d\t%s\t%s\t\t%s\t%s",p->num,p->tpy,p->ppai,p->chepai,p->gongsi); } void print(struct vehicle *h) //输出函数 { struct vehicle *p; p=h; if(h!=NULL) { printf("\n车辆信息为:"); printf("\n编码\t车型\t品牌\t\t车牌\t\t公司"); do{ printf("\n%d\t%s\t%s\t\t%s\t%s",p->num,p->tpy,p->ppai,p->chepai,p->gongsi); p=p->next; }while(p!=NULL); } }