當前位置:編程學習大全網 - 編程語言 - 汽車租賃系統的c語言,數據結構的語言程序

汽車租賃系統的c語言,數據結構的語言程序

剛寫完,好累.還有很多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{/*這個結構體是車輛鏈表的頭結點,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;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);

}

  • 上一篇:MAYA怎麽建模渲染及燈光調整?MAYA建模渲染及燈光調整教程
  • 下一篇:狙擊手榴彈中國研制的最新武器外國購買
  • copyright 2024編程學習大全網