永发信息网

用C语言编写汽车租赁系统

答案:2  悬赏:60  手机版
解决时间 2021-02-15 05:26
  • 提问者网友:你独家记忆
  • 2021-02-14 19:18
求课设作业 要求如下
生产厂家,品牌,型号,出厂时间,租赁人,租赁时间,租赁还金,总费用,备注。
系统以菜单方式工作
汽车基本信息的录入功能
查询和排序功能;按汽车品牌查询,按租赁人等查询
租赁信息的删除与修改
最佳答案
  • 五星知识达人网友:行路难
  • 2021-02-14 19:40
考察点就是结构体,用数组或者链表都可以搞定。
我也可以帮你哈
全部回答
  • 1楼网友:低音帝王
  • 2021-02-14 20:32
刚写完,好累.还有很多bug,你看看会不会改,不行的话我有时间再帮你改.各位有什么意见的也可以告诉我 编译器是vc6 #include<stdio.h> #include<stdlib.h> #include<string.h> #define maxnum 20 typedef struct a{ int no; char type; int payment; int fine; struct a *next; } car; typedef struct b{ int no; char name[20]; char license; int carno; int day; int delayday; struct b *next; } client; struct c{ char type; int avl; car *head; } headnode[3]={{'a',maxnum,null},{'b',maxnum,null},{'c',maxnum,null}} ; client *allclien=null; int pay[3]={400,300,200},fine[3]={600,500,400}; void init(); int menu(); void search(); void carsc(); void clientsc(); void rent(); void giveback(); void addcli(client *cli); client* delcli(int clientno); void addcar(); car* delcar(); void exit(); void main() { init(); while(1) { switch(menu()) { case 1:search();break; case 2:rent();break; case 3:giveback();break; case 4:exit(); default:; } } } void init() { int i; car *ptr,*pa=headnode[0].head,*pb=headnode[1].head,*pc=headnode[2].head; for(i=1;i<=maxnum;i++) { ptr=(car *)malloc(sizeof(car)); ptr->no=100+i; ptr->type='a'; ptr->payment=400; ptr->fine=600; pa=ptr; pa=ptr->next; ptr=ptr=(car *)malloc(sizeof(car)); ptr->no=200+i; ptr->type='b'; ptr->payment=300; ptr->fine=500; pb=ptr; pb=ptr->next; ptr=(car *)malloc(sizeof(car)); ptr->no=300+i; ptr->type='c'; ptr->payment=200; ptr->fine=400; pc=ptr; pc=ptr->next; } pa=null;pb=null;pc=null; } int menu() { int choice; printf("\n\n\n选择服务:1.查询 2.租车 3.归还 4.退出\n"); scanf("%d",&choice); while(choice!=1&&choice!=2&&choice!=3&&choice!=4) { printf("\n输入有误,重新输入:"); scanf("%d",&choice); } return choice; } void search() { int choice; printf("\n你想查询:1.汽车 2.顾客 3.返回 \n"); scanf("%d",&choice); while(choice!=1&&choice!=2&&choice!=3) { printf("\n输入有误,重新输入:"); scanf("%d",&choice); } switch(choice) { case 1:carsc(); break; case 2:clientsc(); break; case 3: ; default:; } } void carsc() { printf("\n\n所有汽车信息:\n"); printf("\na类汽车还剩%d辆.\nb类汽车还剩%d辆.\nc类汽车还剩%d辆.", headnode[0].avl,headnode[1].avl,headnode[2].avl); } void clientsc() { client *ptr=allclien; printf("\n\n所有顾客信息:\n"); while(ptr!=null) { printf("\n\n顾客编号:%d",ptr->no); printf("\n顾客姓名:%s",ptr->name); printf("\n驾照类型:%c",ptr->license); printf("\n租赁车号:%d",ptr->carno); printf("\n租赁天数:%d",ptr->day); printf("\n延迟天数:%d",ptr->delayday); ptr=ptr->next; } } void addcli(client *cli) { if(allclien) allclien=cli; else { cli->next=allclien->next; allclien=cli; } } client* delcli(int clientno) { client *ptr,*preptr;; ptr=allclien; while(ptr!=null&&ptr->no!=clientno) { preptr=ptr; ptr=ptr->next; } if(ptr!=null) { if(ptr==allclien) { allclien=null; } else { preptr->next=ptr->next; } } return ptr; } void rent() { char name[20],type,yes_no; int num,day,no; car *carptr; client *cli; printf("\n\n输入执照类型(a/b/c):"); scanf("%c",&type); while(type!='a'&&type!='b'&&type!='c') { printf("输入有误,重新输入:"); scanf("%c",&type); } if(type=='a') num=headnode[0].avl; else if(type=='b') num=headnode[1].avl; else num=headnode[2].avl; printf("\n%c类汽车还剩%d辆,是否要租凭(y/n):",type,num); scanf("%c",&yes_no); while(yes_no!='y'&&yes_no!='n'&&yes_no!='y'&&yes_no!='n') { printf("y或n:"); scanf("%c",&yes_no); } if(yes_no=='y'||yes_no=='y') { printf("\n输入你的名字:"); scanf("%s",name); printf("\n输入你的租赁天数:"); scanf("%d",&day); } no=rand()%60+200; carptr=delcar(type); cli=(client *)malloc(sizeof(client)); cli->no=no; strcpy(cli->name,name); cli->license=type; cli->carno=carptr->no; cli->day=day; cli->delayday=0; cli->next=null; addcli(cli); printf("\n你的顾客编号是:%d",no); printf("\n你所租赁的汽车是%c类车,车号是:%d",type,carptr->no); printf("\n你的租赁天数是%d天.",day); } void giveback() { int no; long int payment; client *ptr; printf("\n\n顾客编号:"); scanf("%d",&no); if((ptr=delcli(no))==null) printf("\n该顾客不存在,无法归还!"); else { switch(ptr->license) { case 1:payment=ptr->day*400+ptr->delayday*600;break; case 2:payment=ptr->day*300+ptr->delayday*500;break; case 3:payment=ptr->day*200+ptr->delayday*400;break; default:; } printf("\n\n顾客姓名:%s",ptr->name); printf("\n驾照类型:%c",ptr->license); printf("\n租赁车号:%d",ptr->carno); printf("\n租赁天数:%d",ptr->day); printf("\n延迟天数:%d",ptr->delayday); printf("\n\n所需费用:%ld",payment); addcar(ptr->license,ptr->carno); free(ptr); } } void addcar(char cartype,int carno) { car *ptr; int index=cartype-65; ptr=headnode[index].head; if(ptr==null) {ptr=(car *)malloc(sizeof(car)); headnode[index].head=ptr; } else {while(ptr->next) ptr=ptr->next; ptr->next=(car *)malloc(sizeof(car)); ptr=ptr->next; } ptr->no=carno; ptr->type=cartype; ptr->payment= pay[index]; ptr->fine=fine[index]; ptr->next=null; } car* delcar(char type) { car *rentcar; switch(type) { case 'a':rentcar=headnode[0].head; headnode[0].head=rentcar->next; break; case 'b':rentcar=headnode[1].head; headnode[1].head=rentcar->next; break; case 'c':rentcar=headnode[2].head; headnode[2].head=rentcar->next; break; default:; } return rentcar; } void exit() { printf("\n欢迎使用.....888888888886666...."); exit(0); }
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯