#include<stdio.h>#include<string.h>#define NUM 100typedef struct traininfor { char station[10][10]; char tnumber[20]; float price; int lnumber; char time[20];}pemp;struct ticket { char buyer[10]; char source[30]; char dest[30]; int bnumber;};void menu(pemp* pointtr, struct ticket* pointtk); //菜单 void buy(pemp* pointtr, struct ticket* pointtk);void returnt(pemp* pointtr, struct ticket* pointtk);void check(pemp* pointtr, struct ticket* pointtk);void show(pemp* pointtr, struct ticket* pointtk);void exit();void main(){ pemp traininformation[NUM]; struct ticket cheque[NUM]; pemp* pointtr; struct ticket* pointtk; pointtr = traininformation; pointtk = cheque; strcpy(pointtr->station[0], "1"); strcpy(pointtr->station[1], "2"); strcpy(pointtr->station[2], "3"); strcpy(pointtr->station[3], "4"); strcpy(pointtr->station[4], "5"); strcpy(pointtr->station[5], "6"); strcpy(pointtr->station[6], "7"); strcpy(pointtr->tnumber, "Train"); pointtr->price = 88.00; pointtr->lnumber = 50; strcpy(pointtr->time, "2012年12月21日11点22分"); pointtk->bnumber = 0; menu(pointtr, pointtk);}void menu(pemp* pointtr, struct ticket* pointtk) //菜单 { int a; //选项 printf("欢迎使用票务管理系统\n"); printf("1,查询车票 \n"); printf("2,购买车票 \n"); printf("3,退订车票\n"); printf("4,退出程序\n"); printf("请输入功能序号"); scanf("%d", &a); if (a == 1) { check(pointtr, pointtk); //按起始地目的地查找 menu(pointtr, pointtk); //显示菜单 } else if (a == 2) buy(pointtr, pointtk); //购买车票 else if (a == 3) returnt(pointtr, pointtk); //退订车票 else if (a == 4) { printf("谢谢使用"); exit(); }}void show(struct ticket pointtk, pemp pointtr) { printf("车次Train No.: "); printf("Spacecraft"); printf("起始地Source------>目的地Destination: "); printf("%s------>", pointtk->source); printf("%s\n", pointtk->dest); printf("到达时间 Arrival time: ", pointtk->source); printf("%s\n", pointtr->time); printf("票价Price: "); printf("%10.2f\n", pointtr->price); printf("车票数量Lnumber: "); printf("%d\n", pointtr->lnumber);}void check(pemp pointtr, struct ticket pointtk) { int i, j, count = 0; char sour[10]; char dest[10]; printf("请输入起始地: \n"); scanf("%s", sour); printf("请输入目的地:\n"); scanf("%s", dest); for (i = 0; i < NUM; i++) { if (strcmp(pointtr->station[i], sour) == 0) { //查找第一个车站 for (j = 0; j < NUM; j++); { if (strcmp(pointtr->station[j], dest) == 0) { //查找第二个车站 strcpy(pointtk->source, pointtr->station[i]); //将车站写入车票结构体 strcpy(pointtk->dest, pointtr->station[j]); show(pointtk, pointtr); count++; break; } } } } if (count == 0) { printf("无信息\n"); strcpy(pointtk->source, "0"); //没有找到,车站为空 strcpy(pointtk->dest, "0"); return; }}void buy(pemp* pointtr, struct ticket* pointtk) //购买车票{ char choice[10]; //记录选项 int buynumber; printf("请输入您的姓名:\n"); scanf("%s", pointtk->buyer); //输入名字 check(pointtr, pointtk); //查询是否有相应车票 if ((strcmp(pointtk->dest, "0")) == 0) //如果没有,给出提示信息 { printf("无此站!返回菜单\n"); menu(pointtr, pointtk); } else { printf("您确定购买此车票吗1.是YES 2.否NO"); scanf("%s", choice); if ((strcmp(choice, "1")) == 0) { printf("请输入您要购买的张数:\n"); {scanf("%d", &buynumber); if (buynumber < 0) return; } if (((pointtr->lnumber) - buynumber) >= 0) { printf("购买成功!返回菜单\n"); pointtk->bnumber = buynumber; (pointtr->lnumber) -= buynumber; menu(pointtr, pointtk); } else { printf("车票已售完或不足,不能购买!返回菜单\n"); menu(pointtr, pointtk); } } else if ((strcmp(choice, "2")) == 0) //放弃购买 { printf("放弃购买!返回菜单\n"); menu(pointtr, pointtk); } else { menu(pointtr, pointtk); printf("错误!返回菜单\n"); menu(pointtr, pointtk); } }}void returnt(pemp* pointtr, struct ticket* pointtk) { char choice[10]; //记录选项 printf("您确定要退票吗?1.是Yes 2.否No\n"); //确认是否退票 scanf("%s", choice); if ((strcmp(choice, "1")) == 0) { printf("退票成功\n"); pointtr->lnumber += pointtk->bnumber; menu(pointtr, pointtk); } else if ((strcmp(choice, "2")) == 0) { printf("放弃退票 \n"); menu(pointtr, pointtk); } else { menu(pointtr, pointtk); printf("错误返回菜单 \n"); menu(pointtr, pointtk); }}void exit(){ exit();}
1条回答 默认 最新
悬赏问题
- ¥20 需要帮我远程操控一下,运行一下我的那个代码,我觉得我无能为力了
- ¥20 有偿:在ubuntu上安装arduino以及其常用库文件。
- ¥15 请问用arcgis处理一些数据和图形,通常里面有一个根据点划泰森多边形的命令,直接划的弊端是只能执行一个完整的边界,但是我们有时候会用到需要在有很多边界内利用点来执行划泰森多边形的命令
- ¥30 在wave2foam中执行setWaveField时遇到了如下的浮点异常问题,请问该如何解决呢?
- ¥750 关于一道数论方面的问题,求解答!(关键词-数学方法)
- ¥200 csgo2的viewmatrix值是否还有别的获取方式
- ¥15 Stable Diffusion,用Ebsynth utility在视频选帧图重绘,第一步报错,蒙版和帧图没法生成,怎么处理啊
- ¥15 请把下列每一行代码完整地读懂并注释出来
- ¥15 寻找公式识别开发,自动识别整页文档、图像公式的软件
- ¥15 为什么eclipse不能再下载了?