diff --git a/function.cpp b/function.cpp new file mode 100644 index 0000000..a276ba8 --- /dev/null +++ b/function.cpp @@ -0,0 +1,609 @@ +#include "head.h" +void ModeFlightMenu(void)//显示航班菜单 +{ + printf("***********航班菜单***********\n"); + printf("1.显示所有航班\n" + "2.增加航班\n" + "3.取消航班\n" + "4.返回首页\n" + "0.退出程序\n" + "请输入模式:"); +} + +void ModeShowAllFlight(void)//显示所有航班 +{ + FlightList* p; + if(FlightNum == 0) + { + printf("当前航班数为0,请添加后进行操作!\n"); + system("pause"); + return ; + } + system("CLS"); //清除窗口 + printf("********当前当前航班数:%d**********\n",FlightNum); + for (p = FlightHead->next; p!=FlightHead; p = p->next) + { + printf(">>>>>>当前航班号:%d<<<<<<\n",p->FlightNum); + printf("最大载客数:%d\n起飞地点:%s\n降落地点:%s\n起飞时间%s\n降落时间:%s\n单价:%.2f\n当前乘客数:%d\n", + p->MaxFare,p->StartPlace,p->EndPlace,p->StartDate,p->EndDate,p->price,p->currentFareNum); + } + system("pause"); + return ; +} + +void ModeAddFlight(void)//增加航班 +{ + FlightList* NewFlight = FlightCreateNewNode(); + FlightList* p; + printf("*************添加航班信息*****************\n"); + + while(1) + { + int Numder = 0; + printf("航班号:"); + if (!(scanf("%d",&Numder))) + { + printf("请输入整型数!\n"); + while(getchar() != '\n'); //清除缓冲区 + system("pause"); + continue; + } + for (p = FlightHead->next; p != FlightHead; p = p->next) + { + if (p->FlightNum == Numder) + break; + } + if (p != FlightHead) + { + printf("该航班已存在,请确认后输入!\n"); + system("pause"); + return ; + } + else + NewFlight->FlightNum = Numder; + break; + } + while(1) + { + printf("最大载客数:"); + if (!(scanf("%d",&(NewFlight->MaxFare)))) + { + printf("请输入整型数!\n"); + while(getchar() != '\n'); //清除缓冲区 + system("pause"); + continue; + } + break; + } + while(1) + { + printf("起飞地点:"); + if (!(scanf("%s",NewFlight->StartPlace))) + { + printf("输入错误,请重新输入!\n"); + while(getchar() != '\n'); //清除缓冲区 + system("pause"); + continue; + } + break; + } + while(1) + { + printf("降落地点:"); + if (!(scanf("%s",NewFlight->EndPlace))) + { + printf("输入错误,请重新输入!\n"); + while(getchar() != '\n'); //清除缓冲区 + system("pause"); + continue; + } + break; + } + while(1) + { + printf("起飞时间:"); + if (!(scanf("%s",NewFlight->StartDate))) + { + printf("输入错误,请重新输入!\n"); + while(getchar() != '\n'); //清除缓冲区 + system("pause"); + continue; + } + break; + } + while(1) + { + printf("降落时间:"); + if (!(scanf("%s",NewFlight->EndDate))) + { + printf("输入错误,请重新输入!\n"); + while(getchar() != '\n'); //清除缓冲区 + system("pause"); + continue; + } + break; + } + while (1) + { + printf("单价:"); + if (!(scanf("%f",&(NewFlight->price)))) + { + printf("输入错误,请重新输入!\n"); + while(getchar() != '\n'); //清除缓冲区 + system("pause"); + continue; + } + break; + } + printf("增加成功!\n"); + system("pause"); +} + +void ModeCancelFlight(void)//取消航班 +{ + FlightList* p; + FareList* q; + int Num =0; + printf("*************取消航班*****************\n"); + while(1) + { + printf("请输入要取消的航班号:"); + if (!(scanf("%d",&Num))) + { + printf("请输入整型数!\n"); + while(getchar() != '\n'); //清除缓冲区 + system("pause"); + continue; + } + for (p = FlightHead->next; p != FlightHead; p = p->next) + { + if (p->FlightNum == Num) + break; + } + if (p == FlightHead) + { + printf("没有该航班,请确认后输入!\n"); + system("pause"); + return ; + } + if ((p->MaxFare*0.1) < p->currentFareNum) + { + printf("该航班已超过10%的乘客购买,不可取消!\n"); + system("pause"); + continue; + } + else + { + while(1) + { + int mode = 0; + printf("当前航班乘客有:%d\n", p->currentFareNum); + printf("是否取消 1.是 2.否:"); + scanf("%d",&mode); + if (mode != 1 && mode != 2) + { + printf("请输入正确指令!\n"); + while(getchar() != '\n'); //清除缓冲区 + system("pause"); + continue; + } + if (mode == 1) + { + p->currentFareNum = 0; + for (q = FareHead->next; q != FareHead; q = q->next) + { + if (q->FlightNum == p->FlightNum) + q->SeatNumber = 0; + } + + printf("已取消%d航班,购买该航班的乘客已退票\n", p->FlightNum); + system("pause"); + } + else + { + printf("返还乘客首页!\n"); + system("pause"); + } + break; + } + } + break; + } + +} + +void ModeFareMenu(void)//显示乘客菜单 +{ + printf("***********乘客菜单***********\n"); + printf("1.显示所有乘客\n" + "2.新增乘客\n" + "3.删除乘客\n" + "4.航班订票\n" + "5.返回首页\n" + "0.退出程序\n" + "请输入模式:"); +} + +void ModeShowAllFare(void)//显示所有乘客 +{ + FareList* p; + if(FareNum == 0) + { + printf("当前乘客人数为0,请添加后进行操作!\n"); + system("pause"); + return ; + } + system("CLS"); //清除窗口 + printf("********当前乘客人数:%d**********\n",FareNum); + for (p = FareHead->next; p!=FareHead; p = p->next) + { + printf(">>>>>>当前乘客姓名:%s<<<<<<\n",p->name); + printf("航班号:%d\n身份证号:%s\n性别:%s\n出生年月%s\n座位号:%d\n",p->FlightNum,p->IDnumber,p->gender,p->birthDate,p->SeatNumber); + } + system("pause"); + return ; +} + +void ModeAddFare(void)//新增乘客 +{ + FareList* node = FareCreateNewNode(); + printf("******请输入乘客信息*******\n"); + while(1) + { + printf("姓名:"); + if (!(scanf("%s",node->name))) + { + printf("输入错误,请重新输入!\n"); + while(getchar() != '\n'); //清除缓冲区 + system("pause"); + continue; + } + break; + } + while(1) + { + printf("身份证号:"); + if (!(scanf("%s",node->IDnumber))) + { + printf("输入错误,请重新输入!\n"); + while(getchar() != '\n'); //清除缓冲区 + system("pause"); + continue; + } + break; + } + while(1) + { + int gender = 0,input = 0; + printf("性别1.男 2.女:"); + input = scanf("%d",&gender); + if (input != 1 && input != 2) + { + printf("输入错误,请重新输入!\n"); + while(getchar() != '\n'); //清除缓冲区 + system("pause"); + continue; + } + if (gender == 1) + strcpy(node->gender,"男"); + else + strcpy(node->gender,"女"); + break; + } + while(1) + { + int year = 0,month = 0,input = 0; + char date[10],str[10]; + memset(date, 0, sizeof(date)); + memset(str, 0, sizeof(str)); + printf("出生年份:"); + input = scanf("%d",&year); + printf("出生月份:"); + input = scanf("%d",&month); + if (input && (year < 1900 || year > 2019) && (month > 12 || month <= 0)) + { + printf("输入错误,请输入正确年份和月份!\n"); + while(getchar() != '\n'); //清除缓冲区 + system("pause"); + continue; + } + + strcpy(date,strcat(itoa(year,str,10),"/")); + memset(str, 0, sizeof(str)); + strcat(date,itoa(month,str,10)); + memset(str, 0, sizeof(str)); + strcpy(node->birthDate,date); + break; + } + printf("添加成功!\n"); + system("pause"); +} + +void ModeDeleteFare(void)//删除乘客 +{ + FareList* p; + char name[10]; + memset(name, 0, sizeof(name)); + printf("***********删除乘客**************\n"); + printf("请输入需要删除的乘客姓名:"); + scanf("%s", name); + for (p = FareHead->next; p != FareHead; p = p->next) + { + if (!(strcmp(p->name,name))) + { + p->prev->next = p->next; + p->next->prev = p->prev; + free(p); + FareNum--; + break; + } + } + if (p == FareHead) + { + printf("未找到该乘客,请确认后进行操作!\n"); + system("pause"); + return ; + } + printf("删除成功!\n"); + system("pause"); +} + +void ModeFlightReserve(void)//航班订票 +{ + FlightList* p; + FareList* q; + char FindName[10]; + memset(FindName,0,sizeof(FindName)); + printf("***************航班订票***************\n"); + while(1) + { + printf("请输入要购票的乘客姓名:"); + if (!(scanf("%s",FindName))) + { + printf("输入错误,请重新输入!\n"); + while(getchar() != '\n'); //清除缓冲区 + system("pause"); + continue; + } + for (q = FareHead->next; q != FareHead; q= q->next) + { + if(!strcmp(q->name,FindName)) + break; + } + if (q == FareHead) + { + printf("没有该乘客,请确认后输入!\n"); + system("pause"); + continue; + } + else + break; + } + system("CLS"); + ModeShowAllFlight(); + while(1) + { + int mode = 0; + printf("请输入你要查询的航班要求1.航班号 2.起飞地点 3.降落地点 4.起飞时间 5.降落时间:"); + scanf("%d",&mode); + switch (mode) + { + case 1: + while(1) + { + printf("航班号:"); + if (!(scanf("%d",&(q->FlightNum)))) + { + printf("请输入整型数!\n"); + while(getchar() != '\n'); //清除缓冲区 + system("pause"); + continue; + } + for (p = FlightHead->next; p != FlightHead; p = p->next) + { + if (p->FlightNum == q->FlightNum) + break; + } + if (p == FlightHead) + { + printf("没有该航班,请确认后输入!\n"); + system("pause"); + continue; + } + break; + } + break; + case 2: + while(1) + { + char StartPlace[10]; + memset(StartPlace, 0, sizeof(StartPlace)); + printf("起飞地点:"); + if (!(scanf("%s",StartPlace))) + { + printf("输入错误,请重新输入!\n"); + while(getchar() != '\n'); //清除缓冲区 + system("pause"); + continue; + } + for (p = FlightHead->next; p != FlightHead; p = p->next) + { + if (!strcmp(p->StartPlace,StartPlace)) + break; + } + if (p == FlightHead) + { + printf("没有该航班,请确认后输入!\n"); + system("pause"); + continue; + } + break; + } + break; + case 3: + while(1) + { + char EndPlace[10]; + memset(EndPlace, 0, sizeof(EndPlace)); + printf("降落地点:"); + if (!(scanf("%s",EndPlace))) + { + printf("输入错误,请重新输入!\n"); + while(getchar() != '\n'); //清除缓冲区 + system("pause"); + continue; + } + for (p = FlightHead->next; p != FlightHead; p = p->next) + { + if (!strcmp(p->EndPlace,EndPlace)) + break; + } + if (p == FlightHead) + { + printf("没有该航班,请确认后输入!\n"); + system("pause"); + continue; + } + break; + } + break; + case 4: + while(1) + { + char StartDate[10]; + memset(StartDate, 0, sizeof(StartDate)); + printf("起飞时间:"); + if (!(scanf("%s",StartDate))) + { + printf("输入错误,请重新输入!\n"); + while(getchar() != '\n'); //清除缓冲区 + system("pause"); + continue; + } + for (p = FlightHead->next; p != FlightHead; p = p->next) + { + if (!strcmp(p->StartDate,StartDate)) + break; + } + if (p == FlightHead) + { + printf("没有该航班,请确认后输入!\n"); + system("pause"); + continue; + } + break; + } + break; + case 5: + while(1) + { + char EndDate[10]; + memset(EndDate, 0, sizeof(EndDate)); + printf("降落时间:"); + if (!(scanf("%s",EndDate))) + { + printf("输入错误,请重新输入!\n"); + while(getchar() != '\n'); //清除缓冲区 + system("pause"); + continue; + } + for (p = FlightHead->next; p != FlightHead; p = p->next) + { + if (!strcmp(p->EndDate,EndDate)) + break; + } + if (p == FlightHead) + { + printf("没有该航班,请确认后输入!\n"); + system("pause"); + continue; + } + break; + } + break; + default: + printf("输入错误,请重新输入!\n"); + while(getchar() != '\n'); //清除缓冲区 + system("pause"); + continue; + } + break; + } + printf("航班号 最大载客数 起飞地点 降落地点 起飞时间 降落时间 单价 当前乘客数\n"); + printf(" %d\t %d\t %s\t %s %s %s %.2f\t%d\n", + p->FlightNum,p->MaxFare,p->StartPlace,p->EndPlace,p->StartDate,p->EndDate,p->price,p->currentFareNum); + + while(1) + { + int mode = 0,num = 0; + printf("是否购买当前航班1.是 2.否:"); + scanf("%d",&mode); + if (mode != 1 && mode != 2) + { + printf("输入错误,请重新输入!\n"); + while(getchar() != '\n'); //清除缓冲区 + system("pause"); + continue; + } + if (mode == 1) + { + int num = 0; + if (p->currentFareNum == p->MaxFare) + { + printf("当初乘客已满,请选择其他航班!\n"); + system("pause"); + break; + } + printf("请输入需要购买的票数:"); + if (!(scanf("%d",&num))) + { + printf("请输入整型数!\n"); + while(getchar() != '\n'); //清除缓冲区 + system("pause"); + continue; + } + if (num > (p->MaxFare-p->currentFareNum)) + { + printf("当前购买票数大于最大载客数,请重新购买!\n"); + system("pause"); + continue; + } + printf("票价:%d 是否购买?1.是 2.否\n",p->price*num); + scanf("%d",&mode); + if (mode != 1 && mode != 2) + { + printf("输入错误,请重新输入!\n"); + while(getchar() != '\n'); //清除缓冲区 + system("pause"); + continue; + } + printf("购买成功,祝您旅途愉快!\n"); + q->SeatNumber = num; + p->currentFareNum +=num; + } + else + break; + } +} + +void ModeExitSystem(void) +{ + FILE* FlightFp = fopen(".\\FlightInfo.txt","w"); + FILE* pareFp = fopen(".\\PareInfo.txt","w"); + if(FlightFp == NULL || pareFp == NULL) + { + printf("open file failed!\n"); + system("pause"); + return ; + } + WriteFlightInfo(FlightFp); + WritePareInfo(pareFp); + + fclose(FlightFp); + fclose(pareFp); + FlightDeleteAllNode(); //删除航班所有节点 + FareDeleteAllNode(); //删除乘客所有节点 + printf("欢迎下次光临!\n"); + system("pause"); + return ; +} \ No newline at end of file diff --git a/鏈懡鍚1.cpp b/鏈懡鍚1.cpp deleted file mode 100644 index 1079357..0000000 --- a/鏈懡鍚1.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include -int main() -{ - printf("hello word\n"); -} diff --git a/鏈懡鍚1.exe b/鏈懡鍚1.exe deleted file mode 100644 index 2f733c2..0000000 Binary files a/鏈懡鍚1.exe and /dev/null differ