汽车租赁系统c语言 网上的我改了下里面的链表

来源:互联网 发布:java colt 编辑:程序博客网 时间:2024/04/28 00:39

可以运行 只是里面的计算有问题自己改下就行了 适合大家做课程设计的小小从语言程序 代码如下第一次发布的版本有些错误 望谅解

#include<stdio.h>#include<stdlib.h>#include<string.h>#define MaxNum  20typedef 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{/*这个结构体是车辆链表的头结点,A,B,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(char carType,int carNo);car* delCar(char type);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=0;  car *ptr,*pa,*pb,*pc;  headNode[0].head=NULL,headNode[1].head=NULL,headNode[2].head=NULL; ptr=(car *)malloc(sizeof(car));ptr->No=100;ptr->Type='A';ptr->Payment=400;ptr->fine=600;headNode[0].head=ptr;pa=ptr;pa->next=NULL;for( i=1;i<20;i++){ptr=(car *)malloc(sizeof(car));ptr->No=100+i;ptr->Type='A';ptr->Payment=400;ptr->fine=600;pa->next=ptr;pa=ptr;pa->next=NULL;  }free(ptr);ptr=(car *)malloc(sizeof(car));ptr->No=200;ptr->Type='B';ptr->Payment=300;ptr->fine=500;headNode[1].head=ptr;pb=ptr;pb->next=NULL;for( i=1;i<20;i++){ptr=(car *)malloc(sizeof(car));ptr->No=200+i;ptr->Type='A';ptr->Payment=400;ptr->fine=600;pb->next=ptr;pb=ptr;pb->next=NULL;  }free(ptr);ptr=(car *)malloc(sizeof(car));ptr->No=300;ptr->Type='C';ptr->Payment=200;ptr->fine=400;headNode[2].head=ptr;pc=ptr;pc->next=NULL;for( i=1;i<20;i++){ptr=(car *)malloc(sizeof(car));ptr->No=300+i;ptr->Type='A';ptr->Payment=400;ptr->fine=600;pc->next=ptr;pc=ptr;pc->next=NULL;  }free(ptr);}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==NULL)  allClien=cli;else{  cli->next=allClien;  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;   headNode[index].avl++;      }    else       {while(ptr->next)          ptr=ptr->next;         ptr->next=(car *)malloc(sizeof(car));         ptr=ptr->next; headNode[index].avl++;        }    ptr->No=carNo;    ptr->Type=carType;    ptr->Payment= pay[index];    ptr->fine=fine[index];    ptr->next=NULL;}car* delCar(char type){  car *rentcar;  car *pp;  switch(type)  {  case 'A':        rentcar=headNode[0].head;             headNode[0].head=rentcar->next; headNode[0].avl--;             break;    case 'B':rentcar=headNode[1].head;             headNode[1].head=rentcar->next; headNode[1].avl--;             break;    case 'C':rentcar=headNode[2].head;             headNode[2].head=rentcar->next; headNode[2].avl--;             break;    default:;  }  return rentcar;}void Exit(){   printf("\n欢迎使用.....888888888886666....");   exit(0);}