汽车租赁管理系统———c语言课程设计
发布时间:2024-11-06
发布时间:2024-11-06
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
struct member
{
int cardnum;
char lendcar[10];
}member[5];
struct car
{
int carnum;
char carname[20];
float carprice;
char carcreat[20];
int turefalse;
}car[5];
struct card
{
int cardnum;
char sex[5];
char membersname[20];
long int memberstel;
}card[5];
findcar()
{
char carname[10];
int i;
printf("\n\n请输入你要查找的车型:\n");
scanf("%s",carname);
for(i=0;i<5;i++)
{
while(strcmp(carname,car[i].carname)==0)
{
if(car[i].turefalse==1)
{
printf(" 编号 车型牌 品
\n %d %s %s \n",car[i].carnum,car[i].carname,car[i].carcreat);
printf("\n\n");
printf("---------------此车现在无人租用\n.");
printf("---------------按任意键返回\n"); break;
}
else {printf("\n\n---------------这辆车已经有人借出\n");break;}
}
}
return 0;
}
findcar1()
{
char carcreat[10];
int i;
printf("\n\n请输入你要查找的品牌:\n");
scanf("%s",carcreat);
for(i=0;i<5;i++)
{
while(strcmp(carcreat,car[i].carcreat)==0)
{
if(car[i].turefalse==1)
{
printf(" 编号 车型 品牌\n %d %s %s \n",car[i].carnum,car[i].carname,car[i].carcreat);
printf("\n\n");
printf("---------------此车现在无人租用\n."); printf("---------------按任意键返回\n\n"); break; }
辆车已经有人借 else {printf("\n\n---------------这
出!\n");printf("---------------按任意键返回\n\n"); break; }
}
}
return 0;
}
chacar()
{
char ch5;
do
{
printf("\n\n 1: 按车型查找 \n");
printf(" 2: 按品牌查找 \n");
printf(" 0: 返回 \n");
printf(" 请输入0━2:\n");
ch5=getch();
switch(ch5)
{
case '1':findcar();getch();break;
case '2':findcar1();getch();break;
case '0':break;
default:printf("---------------无此操作!\n");getch();break;
}
}while(ch5!='0');
return 0;
}
lendcar()
{
int i,n;
int cardnum;
printf("\n\n请输入卡号 :\n");
scanf("%d",&cardnum);
for(i=0;i<5;i++)
{
if(card[i].cardnum==cardnum)
{
n=i;
printf("\n车型:");
scanf("%s",member[n].lendcar);
for(i=0;i<5;i++)
{ if(strcmp(car[i].carname,member[n].lendcar)==0)
{
if(car[i].turefalse==0)
{printf("---------------对不起,此车已被租出,请重新选择\n");
getch();return 0;
}
else
member[n].cardnum=cardnum;
for(i=0;i<5;i++)
{
if(strcmp(car[i].carname,member[n].lendcar)==0)
{
car[i].turefalse=0;
continue;
}
}
printf("\n\n---------------操作成功,请及时提车.");
printf("\n---------------按任意键返回...\n");
getch();
return 0;
}
}
printf("\n\n---------------错误操作.");
printf("\n---------------按任意键返回...\n");
getch();
return 0;
}
}
printf("\n\n---------------你的卡号不存在,请申请新卡.\n");
printf("\n---------------按任意键返回...\n");
getch();
return 0;}
huancar()
{
int i,n;
int cardnum;
char lendcar[10];
printf("\n\n\n");
printf(" --- 欢迎进入还车界面 ---");
printf("\n\n请你输入你的卡号 :");
scanf("%d",&cardnum);
for(i=0;i<5;i++)
{
if(card[i].cardnum==cardnum)
{
n=i;
printf("\n请输入你要归还的车型:");
scanf("%s",lendcar);
for(i=0;i<5;i++)
{
while(strcmp(member[i].lendcar,lendcar)==0)
{ car[i].turefalse=1;
break;
}
printf("\n\n---------------还车完毕.");
printf("\n---------------按任意键返回...\n");
getch();
return 1;
}
printf("\n\n---------------租赁记录不存在.");
printf("\n---------------按任意键返回...\n");
getch();
return 0;
}
else{
printf("\n\n---------------卡号不存在,请与管理员联系.\n");
printf("\n---------------按任意键返回...\n");
getch();
return 0;}}}
void addcard()
{
int i=0;
char choice;
for(i=0,choice='y';choice=='y'||choice=='Y';i++)
{
printf("\n\n卡号:");
scanf("%d",&card[i].cardnum);
printf("\n性别:");
scanf("%s",card[i].sex);
printf("\n姓名:");
scanf("%s",card[i].membersname);
printf("\n电话:");
scanf("%ld",&card[i].memberstel);
printf("\n\n是否要输入下一个人===============(y \\ n)\n\n");
scanf("%s",&choice);
}
printf("\n\n-----------------输入完毕.");
printf("\n---------------任意键返回...\n");
getch();
}
delcard()
{
int i;
int cardnum;
char choice;
printf("\n\n要删除的卡号:");
scanf("%d",&cardnum);
for(i=0;i<5;i++)
{
while(card[i].cardnum==cardnum)
{
printf("\n\n确认删除? (Y / N)\n");
scanf("%s",&choice);
if(choice=='y'||choice=='Y')
{
{ for(;i<5;i++)
card[i]=card[i+1];
}
printf("\n\n---------------已删除成功!\n---------------按任意键返回...\n");
getch();
return 0;
}
else
{ printf("---------------已取消删除\n\n"); getch(); return 0; }
}}}
void cardcount()
{
int i,n=0;
for(i=0;i<5;i++)
{ if(card[i].cardnum!=0)
{ printf("第%d张卡 \n",i+1);
printf(" 卡号 性别 姓名 电话\n");
printf("\t\t\n");
printf(" %d %6s %10s %ld \n\n",card[i].cardnum,card[i].sex,card[i].membersname,card[i].memberstel);
n++;
printf("\n");
} }
printf("---------------目前共有%d个会员.\n",n);
printf("---------------按任意键返回...\n");
getch();
}
void addcar()
{ char choice;
int i;
for(i=0,choice='y';choice=='y'||choice=='Y';i++)
{ printf("\n\n\n编号:");
scanf("%d",&car[i].carnum);
printf("\n\n车型:");
scanf("%s",car[i].carname);
printf("\n\n品牌:");
scanf("%s",car[i].carcreat);
printf("\n\n租金:");
scanf("%f",&car[i].carprice);
printf("\n\n请你设定车的状态===============(0-不在 \\ 1-在):");
scanf("%d",&car[i].turefalse);
printf("\n\n是否要输入下一辆车===============(y \\ n)\n\n");
scanf("%s",&choice);
}
printf("\n\n-----------------输入完毕.");
printf("\n---------------任意键返回...\n");
getch();
}
delcar()
{
int i,carnum;
char choice;
printf("\n\n");
printf("编号:\n");
scanf("%d",&carnum);
for(i=0;i<5;i++)
{ while(carnum==car[i].carnum)
{ printf("确认删除-----(y / n)?\n");
scanf("%s",&choice);
if(choice=='y'||choice=='Y')
{ {for(;i<5;i++) car[i]=car[i+1];}
printf("\n\n---------------已删除成功!\n---------------按任意键返回...\n");
getch();
return 0;
}
else
{ printf("---------------已取消删除\n\n"); } } }
printf("--------------------按任意键返回...\n");
getch();
return 0; }
void carcount()
{
int i,n=0;
for(i=0;i<5;i++)
{ if(car[i].carnum!=0&&car[i].carname!=0)
{
printf("\n\n第%d辆车\n编号 车型 品牌 租金 状态\n",i+1);
printf("\t\t\n");
printf(" %d %10s ",car[i].carnum,car[i].carname);
printf("%15s %4.2f %d=====(1在\\0不在)\n\n",car[i].carcreat,car[i].carprice,car[i].turefalse);
n=n+1;
} }
printf("\n\n---------------目前共有%d辆车.\n",n);
printf("---------------按任意键返回...\n");
}
void end()
{ printf("\n\n\n-------------------------------------------------------------------------------\n");
printf("\n");
printf(" --- 谢谢使用本系统, 再见! ---\n"); printf("\n\n\n\n");
}
void main()
{
char ch1,ch2,ch4;
do
{
printf("\n");
printf(" --- 制作: 学号: 班级: --- \n\n");
printf("\n --- 欢迎使用系统 ---"); printf("\n\n");
printf(" 请选择需要的服务:\n");
printf(" 1:查询汽车\n");
printf(" 2:办理租赁\n");
printf(" 3:管理系统 \n");
printf(" 4:归还登记\n");
printf(" 0:退出系统 \n");
printf("请输入数字0━4:\n");
ch1=getch();
switch(ch1)
{
case '1':chacar();break;
case '2':lendcar();;break;
case '3':{
do
{printf("\n\n 1:增加汽车\n");
printf(" 2:删除汽车 \n");
printf(" 3:汽车统计 \n");
printf(" 4:会员管理系统\n");
printf(" 0:返回首页 \n");
printf("请输入0━4:\n");
ch2=getch();
switch(ch2)
{
case '1':addcar(); break;
case '2':delcar();break;
case '3':carcount();getch();break;
case '4':{
do
{
printf("\n\n 1: 申请新卡 \n");
printf(" 2: 删除卡号 \n");
printf(" 3: 卡号统计\n");
printf(" 0: 返回\n");
printf("请输入0━3:\n");
ch4=getch();
switch(ch4)
{
case '1':addcard();break;
case '2':delcard();break;
case '3':cardcount();break;
case '0':break;
default:printf("无此操作!\n");getch();break; }
}while(ch4!='0');}break;
case '0':end();break;
default:printf("无此操作!\n");getch();break;
}
} while(ch2!='0');}break;
case '4':huancar();break;
case '0':end();break;
default:printf("无此操作!\n");getch();break;
}
}while(ch1!='0');
}