挑战题二
来源:互联网 发布:纳米盒软件下载 编辑:程序博客网 时间:2024/06/06 23:10
#include<iostream>#include<stdlib.h>#include<iomanip>#include<cstring>struct train{ int num; char set[10]; char dest[10]; char time[20]; int rest;};typedef train ElemType;struct List{ ElemType list[10]; int size;};void InitList(List &L){ L.size = 0;}std::ostream &operator<<(std::ostream &out, ElemType listitem){ std::cout << listitem.num << " " << std::setw(3) << listitem.set << std::setw(3) << " " << listitem.dest << std::setw(3) << " " << listitem.time << std::setw(3) << " " << listitem.rest << std::endl; return out;}void TraverseList(List &L){ for (int i = 0; i < L.size; i++) std::cout << L.list[i] ; std::cout << std::endl;}bool operator <(ElemType item, ElemType listitem){ return item.num < listitem.num;}bool InsertList(List &L, ElemType item, int pos){ if (pos<-1 || pos> L.size+ 1) { std::cout << "pos值无效!" << std::endl; return false; } int i; if (pos == 0) { for (i = 0; i < L.size; i++) if (item< L.list[i]) break; pos = i + 1; } else if (pos == -1) pos = L.size + 1; if (L.size == 10) { std::cout << "表满,不能继续插入"; return false; } for (i = L.size - 1; i >= pos - 1; i--) L.list[i + 1] = L.list[i]; L.list[pos - 1] = item; L.size++; return true;}bool operator==(ElemType listitem, ElemType item){ return (strcmp(listitem.dest, item.dest) == 0||listitem.num==item.num);}bool FindList(List &L, ElemType& item){ for (int i = 0; i < L.size; i++) if (L.list[i] == item) { item = L.list[i]; return true; } return false;}void star(){ int i ; for (i = 0; i <= 35; i++) std::cout << " "; for (i = 1; i <= 36; i++) std::cout << "*"; std::cout << " " << std::endl;}void mainmenu(){ int a; star(); for (a = 0; a <= 47; a++) std::cout << " "; std::cout << "火车售票系统" << std::endl; std::cout << std::endl; std::cout << " 请选择你的操作:(按q退出)" << std::endl; std::cout << " 1.录入班车信息; " << std::endl; std::cout << " 2.浏览班车信息: " << std::endl; std::cout << " 3.查询行车路线: " << std::endl; std::cout << " 4.售票与退票系统: " << std::endl; std::cout << "请输入你需要的功能: " << std::endl; std::cout << std::endl;}void outline(){ std::cout << "班次" << " " << std::setw(3) << " " << "出发站" << std::setw(3) << " " << "终点站" << std::setw(3) << " " << "发车时间" << std::setw(3) << " " << "剩余票数" << std::endl;;}void submenu1(){ star(); std::cout << " 1.按班次号查询: " << std::endl; std::cout << " 2.按终点站查询: " << std::endl; std::cout << " 3.返回主菜单: " << std::endl; std::cout << "请输入你需要的功能: ";}void submenu2(){ star(); std::cout << " 1.订票: " << std::endl; std::cout << " 2.退票: " << std::endl; std::cout << " 3.返回主菜单: " << std::endl; std::cout << "请选择你需要的功能:";}std::istream &operator>>(std::istream &in, ElemType listitem){ std::cin >> listitem.num >> listitem.set >> listitem.dest >> listitem.time >> listitem.rest; return in;}void bookticket(int number,List &L,int ticketnum){ int i; for (i = 0; i < L.size; i++) if (L.list[i].num == number) { L.list[i].rest-=ticketnum; std::cout << "订票成功!请按时上车!" << std::endl; outline(); std::cout << L.list[i]; }}void returnticket(int number,List &L,int ticketnum){ int i; for (i = 0; i < L.size; i++) if (L.list[i].num == number) { L.list[i].rest+=ticketnum; std::cout << "退票成功!欢迎下次乘搭!" << std::endl; outline(); std::cout << L.list[i]; }}int main(){ int i, key, search, fun, trainnum, tickets; train number, destination; train b[10] = { {01,"广州","北京","6:00",69},{02,"香港","上海","8:00",77}, { 03,"珠海","成都","19:00",89 } }; List L; InitList(L); for (i = 0; i < 3; i++) InsertList(L, b[i], i + 1); mainmenu(); while (std::cin >> key) { switch (key) { case 1: outline(); std::cin >> b[i]; i++; std::cout << "录入成功!" << std::endl; mainmenu(); break; case 2: outline(); TraverseList(L); std::cout << std::endl; break; case 3: submenu1(); while (std::cin >> search) { switch (search) { case 1: std::cout << "输入班次号:"; std::cin >> number.num; if (FindList(L, number)) { std::cout << "查找成功!" << std::endl; outline(); std::cout << number; } else std::cout << "查找失败!表中无此数据!" << std::endl; break; case 2: std::cout << "输入终点站: " << std::endl; std::cin >> destination.dest; if (FindList(L, destination)) { std::cout << "查找成功!" << std::endl; outline(); std::cout << destination; } else std::cout << "查找失败!表中无此数据!" << std::endl; break; case 3: std::cout << "返回主菜单!" << std::endl; break; } break; } mainmenu(); break; case 4: submenu2(); std::cin >> fun; switch (fun) { case 1: std::cout << "请输入你需要订票的班次:"; std::cin >> trainnum; std::cout << "请输入你需要订的票数:"; std::cin >> tickets; bookticket(trainnum,L,tickets); break; case 2: std::cout << "请输入你需要退票的班次:"; std::cin >> number; std::cout << "请输入你需要退的票数:"; std::cin >> tickets; returnticket(trainnum,L,tickets); break; case 3: break; } std::cout << "返回主菜单!" << std::endl; mainmenu(); break; } } system("pause"); return 0;}
最近做的比较大的一个作业,然后途中问了很多人。
他们的评价就是我的风格不如用C,很少C++风格,C++的优点很难体现得出来,
很是打击,看来输在起跑线上了
阅读全文
0 0
- 挑战题二
- 计蒜客 挑战难题 第20题:跳跃游戏二
- Sun & Oracle,严峻的挑战(二)
- 《挑战程序设计竞赛》笔记 初出茅庐之二
- 编程挑战(二)分配糖果
- 计蒜客 挑战难题 跳跃游戏二
- 挑战程序设计竞赛 4.4常用技巧(二)
- Python挑战第三题
- Python挑战第三题
- 第三关挑战题
- 挑战
- 挑战
- 挑战
- 挑战。
- 挑战题之排列生成
- 《挑战程序设计》第一章第一题
- nyoj 挑战密室 模拟题
- 挑战题一(1)
- CF-777C Alyona and Spreadsheet
- python seaborn 共享x轴画图 数据可视化
- OFBiz进阶--OFBiz开发之什么情况要重启OFBiz项目
- BZOJ3781: 小B的询问
- 无状态服务(stateless service)
- 挑战题二
- 解决perl: warning: Setting locale failed. perl: warning: Please check that your locale settings:
- eclipse的入门使用,项目的创建删除,项目的导入导出,eclipse的字体和颜色设置,控制台的字体设置,
- [二分+树状数组]51 Nod 1685——第K大区间2
- BMP图片格式处理
- viewPager+fragment
- MFC 程序怎么限制多开
- 与反素数有关的3个题目
- 关于servlet和servlet容器的图