首页 / 汽车知识 / 正文
汽车租赁系统的c语言,数据结构的语言程序

Time:2024年06月12日 Read:88 评论:0 作者:访客

刚写完,好累.还有很多bug,你看看会不会改,不行的话我有时间再帮你改.各位有什么意见的也可以告诉我

编译器是VC6

#include
#include
#include
#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{/*这个结构体是车辆链表的头结点,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();/*向车辆链表归还车辆*/
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;iNo=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(nnn选择服务: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(nn所有汽车信息:n);
printf(nA类汽车还剩%d辆.nB类汽车还剩%d辆.nC类汽车还剩%d辆.,
headNode[0].avl,headNode[1].avl,headNode[2].avl);

}

void clientSc()
{
client *ptr=allClien;
printf(nn所有顾客信息:n);

while(ptr!=NULL)
{ printf(nn顾客编号:%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(nn输入执照类型(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(nn顾客编号:);
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(nn顾客姓名:%s,ptr->Name);
printf(n驾照类型:%c,ptr->License);
printf(n租赁车号:%d,ptr->carNo);
printf(n租赁天数:%d,ptr->Day);
printf(n延迟天数:%d,ptr->DelayDay);
printf(nn所需费用:%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欢迎使用.........);
exit(0);
}

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们
以汽车主要产地,集散地建立的批发市场为龙头,带动周边汽车零售市场,以市场价格机制为纽带形成的网络市场。组建中国汽车连锁市场是为了促进横向经济联合和协作,并向纵深层次发展,以加速开发短线资源,实现保供促销,提高企业经济效益和管理水平,促进汽车工业和汽车市场健康发展
联系我们
369169688
业务合作
www.eshc168.com
走进168二手车
www.eshc168.com
扫码关注
公司致力于汽车二手交易信息,如有侵权行为,我们会立即删除
1123