学习c++的首次尝试,代码里还有很多不足,大神勿喷,希望路过的大佬们可以多多指教。
#include #include #include #include #include #include #include #include #include class infor_flight; class User; class Airport; class Air_time; class supervisor; class airport_integration; using std::string; using port_info = std::multimap; //键值对 到达机场 航班信息; using zhanghu = std::map; time_t current_time = time(nullptr); tm *p = localtime(¤t_time); //键值对输出模版函数; template inline void show_map(std::pair pa) { std::cout << pa.first << " : " << pa.second << std::endl; } //管理员登陆 class backstage { public: std::map supervisor_integration; //登陆函数; bool login_super(void) { string key; std::cout << "请输入管理员密码" << std::endl; while (std::cin >> key) { if (key == "guess") { std::cout << "登陆成功" << std::endl; break; } } return true; } }; //管理员(添加信息的人员) class supervisor { public: void add_airport(airport_integration &t); void add_flight(airport_integration &); }; //机场信息集合; class airport_integration { public: friend User; std::map integration; void add_airport_infor(void); void mark_special_infor(void); //待定 void add_flight_information(void); void add_flight_information_implicit(Airport &x); friend void add_flight(airport_integration &); friend void supervisor::add_airport(airport_integration &); }; // air_time 航班时间信息 class air_time { public: static const int year = 2022; int month; int date; int hour; int min; air_time(int m, int d, int g, int s) : month(m), date(d), hour(g), min(s) {} ~air_time(){}; friend std::ostream &operator<<(std::ostream &, const air_time &); }; // infor_flight 航班基本信息; class infor_flight { private: public: string airport_go, airport_off; string firm; air_time time_infor; //机型信息机构体(包含座位信息); using aircraft = struct plane_type { string type; int max_capacity; int remain; }; string flight_number; aircraft plane; infor_flight(string num, string port_go, string port_off, aircraft air, string company, int month, int day, int h, int minute) : flight_number(num), airport_go(port_go), airport_off(port_off), plane(air), firm(company), time_infor(month, day, h, minute) {} virtual ~infor_flight() {} friend std::ostream &operator<<(std::ostream &, const infor_flight &); }; // User乘客; class User { private: public: //订单信息单元 using order_infor = struct orderinformation { string go; string off; string air_num; air_time air_tm; // string seat; }; string name; double ID; string count_name; string key; std::vector purchase_infor; User(string mingzi, double id, string count, string mima) : name(mingzi), ID(id), count_name(count), key(mima) {} void purchase(airport_integration &p); //订票单元 ; void purchase_Airport(Airport &); void show_purchse_infor(void); void return_ticket(airport_integration &p); //退票单元; }; // airport 机场信息; class Airport { public: string port_name; port_info port_air; explicit Airport(string str) : port_name(str) {} void insert_air(void); //仅管理员使用。向机场内添加航班信息; infor_flight *enquire(string &); //查询 infor_flight *book(string &off, string num); void user_return(string &off, string num); friend void User::purchase_Airport(Airport &); }; //登陆管理类; class log { public: std::multimap users; void addusers(void); //注册; User *login(void); void forget(void); //找回密码; void change_password(void); friend std::ostream &operator<<(std::ostream &os, const std::map &); }; std::ostream &operator<<(std::ostream &os, std::map &users) { for (auto x = users.begin(); x != users.end(); ++x) { os << x->first << std::endl; } return os; } // air_time 时间输出友元函数; std::ostream &operator<<(std::ostream &os, const air_time &air_tm) { os << "2022年 " << air_tm.month << "月 " << air_tm.date << "日" << air_tm.hour << ":" << air_tm.min << std::endl; return os; } // infor_flight 航班信息输出友元函数; std::ostream &operator<<(std::ostream &oos, const infor_flight &infor_air) { oos << "flight number :" << std::setw(15) << infor_air.flight_number << std::endl; oos << "leave : " << infor_air.airport_off << "destination : " << infor_air.airport_go << std::endl; oos << "执飞机型 : " << infor_air.plane.type << std::endl; oos << "剩余座位 : " << infor_air.plane.remain << std::endl; oos << "起飞时间 : " << infor_air.time_infor << std::endl; return oos; } void Airport::user_return(string &off, string num) { std::multimap::iterator x; for (x = port_air.lower_bound(off); x != port_air.upper_bound(off); x++) { if ((*x).second.flight_number == num) { (*x).second.plane.remain++; } } return; } void log::addusers(void) { string name, Countname, key, key_1; double id; std::cout << "请先进行实名认证" << " " << "请输入姓名 " << std::endl; std::cin >> name; for (auto x = users.begin(); x != users.end(); ++x) { if ((*x).second.name == name) { std::cout << "该用户已经注册过" << std::endl; return; } } std::cout << "请输入身份证)" << std::endl; std::cin >> id; std::cout << "请输入用户名" << std::endl; std::cin >> Countname; for (auto x = users.begin(); x != users.end(); ++x) { if ((*x).second.count_name == name) { std::cout << "该用户已经注册过" << std::endl; } } //设置密码; std::cout << "请输入密码" << std::endl; while (std::cin >> key) { if (key.size() <= 6) { std::cout << "这密码过于简单" << std::endl; std::cout << "请重新输入" << std::endl; continue; } else if (key.size() > 12) { std::cout << "密码过长" << std::endl; std::cout << "请重新输入" << std::endl; continue; } std::cout << "请再次输入" << std::endl; std::cin >> key_1; while (key_1 != key) { std::cout << "两次密码不一致,请重新输入" << std::endl; std::cin >> key_1; } std::cout << "密码为:" << key << std::endl; break; } //加入map内; User newuser(name, id, Countname, key); users.insert(std::pair(key, newuser)); // std::cout << users; } //登陆; User *log::login(void) { string countname; string truemima, mima; User *p; bool flag = false; std::cout << "请输入用户名" << std::endl; while (std::cin >> countname) { //判断用户名是否有效; std::multimap::iterator x; for (x = users.begin(); x != users.end(); ++x) { if (countname != x->second.count_name) { continue; } flag = true; truemima = x->first; p = &((*x).second); } if (flag == false) /// { std::cout << "该用户名无效,尚未注册,请重新输入" << std::endl; std::cout << "是否继续输入" << std::endl; std::cout << "注册------1 退出-------2 继续输入-----3" << std::endl; int choose; std::cin >> choose; if (choose == 1) { string name, Countname, key, key_1; double id; std::cout << "请先进行实名认证" << " " << "请输入姓名 " << std::endl; std::cin >> name; for (auto x = users.begin(); x != users.end(); ++x) { if ((*x).second.name == name) { std::cout << "该用户已经注册过" << std::endl; return nullptr; } } std::cout << "请输入身份证号(请开始瞎编)" << std::endl; std::cin >> id; std::cout << "请输入用户名" << std::endl; std::cin >> Countname; for (auto x = users.begin(); x != users.end(); ++x) { if ((*x).second.count_name == name) { std::cout << "该用户已经注册过" << std::endl; } } //设置密码; std::cout << "请输入密码" << std::endl; while (std::cin >> key) { if (key.size() <= 6) { std::cout << "这密码太简单" << std::endl; std::cout << "请重新输入" << std::endl; continue; } else if (key.size() > 12) { std::cout << "这么长的密码我就不信你能记住" << std::endl; std::cout << "请重新输入" << std::endl; continue; } std::cout << "请再次输入" << std::endl; std::cin >> key_1; while (key_1 != key) { std::cout << "两次密码不一致,请重新输入" << std::endl; std::cin >> key_1; } std::cout << "密码为:" << key << std::endl; break; } User newuser(name, id, Countname, key); users.insert(std::pair(key, newuser)); return &((*(users.find(key))).second); } else if (choose == 2) { return nullptr; } else if (choose == 3) { continue; } continue; } if(flag == true) { break; } } //判断密码是否正确; std::cout << "请输入密码" << std::endl; int flagg = 6; while (std::cin >> mima) { if (mima == truemima) { std::cout << "登陆成功" << std::endl; return p; } flagg--; std::cout << "密码错误,请重新输入" << std::endl; std::cout << "你还有 " << flagg << "次机会" << std::endl; if (flagg == 0) { std::cout << "是否选择找回密码" << std::endl; std::cout << "yes----1 no----2" << std::endl; int choose; while (std::cin >> choose) { if (choose == 1) { std::cout << "请输入用户名" << std::endl; string name, truename; double id; std::cin >> name; for (auto x = users.begin(); x != users.end(); ++x) { if (x->second.count_name == name) { bool flaggg = false; while (!flaggg) { std::cout << "进行身份验证" << std::endl; std::cout << "请输入您的真实姓名" << std::endl; std::cin >> truename; std::cout << "请输入身份证号" << std::endl; std::cin >> id; if (truename == x->second.name && id == x->second.ID) { std::cout << "您的密码为" << x->first << std::endl; return &(x->second); } else { std::cout << "姓名或身份证号输入错误" << std::endl; std::cout << "退出 or 重新输入" << std::endl; std::cout << "yes----1 no----2" << std::endl; int choooose; if (choooose == 1) { return nullptr; } else { continue; } } } } } std::cout << "抱歉,该用户名无效" << std::endl; break; } else { break; } } } } return nullptr; } //在机场对象port_air内添加航班信息; void Airport::insert_air(void) / { string go, off, company, type; int capacity; string num; std::cout << "清添加航班信息——————————————————" << std::endl; std::cout << "请输入航班号" << std::endl; std::cin >> num; std::cout << "请输入 起飞机场 和 降落机场 " << std::endl; std::cin >> go >> off; std::cout << "请输入航空公司名称" << std::endl; std::cin >> company; std::cout << "请输入执飞机型" << std::endl; std::cin >> type; std::cout << "请输入该执飞机型最大载客量" << std::endl; std::cin >> capacity; infor_flight::aircraft craft = {type, capacity, capacity}; int month, date, hour, minute; std::cout << "请输入起飞日期 格式(月份 日期 小时 分钟)" << std::endl; /// std::cin >> month >> date >> hour >> minute; // infor_flight flight_information_add(num, go, off, craft, company, month, date, hour, minute); port_air.insert(std::pair(off, infor_flight(num, go, off, craft, company, month, date, hour, minute))); } //管理员加入机场信息 void airport_integration::add_airport_infor(void) //等待加入航班; { //创建机场对象 string portname; std::cout << "请输入机场名称" << std::endl; std::cin >> portname; Airport newport(portname); add_flight_information_implicit(newport); integration.insert(std::pair(portname, newport)); } void supervisor::add_airport(airport_integration &t) { t.add_airport_infor(); } void supervisor::add_flight(airport_integration &x) { x.add_flight_information(); } //添加航班信息; void airport_integration::add_flight_information(void) //单独添加版本; { string portname; bool if_find = false; std::cout << "请输入起飞机场" << std::endl; std::cin >> portname; std::map::iterator x; for (auto pt = integration.begin(); pt != integration.end(); ++pt) { if (pt->first == portname) { if_find = true; bool flag = true; while (flag) { pt->second.insert_air(); int choose; std::cout << "是否继续输入" << std::endl; std::cout << "yes----1 no----2" << std::endl; while (std::cin >> choose) { if (choose == 1) { } else { flag = false; return; } } } } } if (!if_find) { std::cout << "系统尚未录入机场信息,请返回并录入机场信息" << std::endl; } } void airport_integration::add_flight_information_implicit(Airport &x) { bool flag = true; while (flag) { x.insert_air(); int choose; std::cout << "是否继续输入" << std::endl; std::cout << "yes----1 no----2" << std::endl; while (std::cin >> choose) { if (choose == 1) { break; } else { flag = false; break; } } } } //在用户类(User)中进行订票,并且储存购票信息。/// void User::purchase_Airport(Airport &x) { string destination; std::cout << "请输入降落机场" << std::endl; std::cin >> destination; infor_flight *ptr = x.enquire(destination); if (ptr == nullptr) { return; } for (auto random = purchase_infor.begin(); random != purchase_infor.end(); ++random) { if (random->air_num == ptr->flight_number) { std::cout << "该航班已经购买过,使用该账号不允许重复购买" << std::endl; ptr->plane.remain++; return; } } std::cout << "订票成功" << std::endl; order_infor order = {ptr->airport_go, ptr->airport_off, ptr->flight_number, ptr->time_infor}; purchase_infor.push_back(order); } //重复购买时自动退票(航班信息里的remain增加) //应用于enquire函数内,用于预定航班; infor_flight *Airport::book(string &off, string num) { infor_flight *p; bool whether = false; std::multimap::iterator x; for (x = port_air.lower_bound(off); x != port_air.upper_bound(off); x++) { if ((*x).second.flight_number == num) { (*x).second.plane.remain--; whether = true; p = &(x->second); } } if (whether == false) { return nullptr; } return p; } //通过destination查询航班; infor_flight *Airport::enquire(string &off) { std::cout << "为您找到 " << port_air.count(off) << " 条信息" << std::endl; if (!port_air.count(off)) { std::cout << "抱歉,暂无航班信息" << std::endl; return nullptr; } for_each(port_air.lower_bound(off), port_air.upper_bound(off), show_map); //订票单元; std::cout << "please enter the flight number you want to book" << std::endl; string num; std::cin >> num; return book(off, num); } void User::show_purchse_infor(void) { for (auto x = purchase_infor.begin(); x != purchase_infor.end(); ++x) { std::cout << (*x).air_num << std::endl; std::cout << (*x).air_tm; } } void User::purchase(airport_integration &p) { string terminal; std::cout << "请输入起飞机场" << std::endl; std::cin >> terminal; std::map::iterator x = p.integration.find(terminal); purchase_Airport((*x).second); } //退票单元; void User::return_ticket(airport_integration &p) { if (purchase_infor.size() == 0) { std::cout << "尚无购买信息" << std::endl; return; } show_purchse_infor(); string num, off; std::cout << "请输入航班号" << std::endl; std::cin >> num; std::vector::iterator x; for (x = purchase_infor.begin(); x != purchase_infor.end(); x++) { if (x->air_num == num) { off = x->off; purchase_infor.erase(x); break; } } std::map::iterator iter = p.integration.find(off); iter->second.user_return(off, num); std::cout << "退票成功" << std::endl; } void log::forget(void) //找回密码; { std::cout << "请输入用户名" << std::endl; string name, truename; double id; std::cin >> name; for (auto x = users.begin(); x != users.end(); ++x) { if (x->second.count_name == name) { std::cout << "进行身份验证" << std::endl; std::cout << "请输入您的真实姓名" << std::endl; std::cin >> truename; std::cout << "请输入身份证号" << std::endl; std::cin >> id; if (truename == x->second.name && id == x->second.ID) { std::cout << "您的密码为" << x->first << std::endl; } return; } } std::cout << "抱歉,该用户名无效" << std::endl; } void log::change_password(void) { string countname, name, mima; double id; std::cout << "请输入用户名" << std::endl; while (std::cin >> countname) { for (auto x = users.begin(); x != users.end(); ++x) { if (x->second.count_name == countname) { std::cout << "请输入密码" << std::endl; while (std::cin >> mima) { if (x->first == mima) { std::cout << "请输入真实性名" << std::endl; while (std::cin >> name) { std::cout << "请输入身份证号" << std::endl; std::cin >> id; if (name == x->second.name && id == x->second.ID) { string newkey, newkey_2; std::cout << "请输入新密码" << std::endl; std::cin >> newkey; std::cout << "请再次输入新密码" << std::endl; while (std::cin >> newkey_2) { if (newkey_2 == newkey) { std::cout << "修改成功" << std::endl; users.erase(x); User newuser(name, id, countname, newkey); users.insert(std::pair(newkey, newuser)); return; } else { std::cout << "两次密码不一致" << std::endl; std::cout << "是否退出" << std::endl; std::cout << "yes----1 no----2" << std::endl; int choooose; if (choooose == 1) { return; } else { std::cout << "请再次输入新密码" << std::endl; continue; } } } } else { std::cout << "姓名或身份证号输入错误,二者不匹配" << std::endl; std::cout << "是否退出" << std::endl; std::cout << "yes----1 no----2" << std::endl; int choooose; std::cin >> choooose; if (choooose == 1) { return; } else { std::cout << "请输入真实性名" << std::endl; continue; } } } // } // mima else { std::cout << "密码错误" << std::endl; std::cout << "是否退出" << std::endl; std::cout << "yes----1 no----2" << std::endl; int choooose; std::cin >> choooose; if (choooose == 1) { return; } else { std::cout << "请输入密码" << std::endl; continue; } } } } / } std::cout << "该用户名不存在" << std::endl; std::cout << "是否退出" << std::endl; std::cout << "yes----1 no----2" << std::endl; int choose; std::cin >> choose; if (choose == 1) { return; } else { std::cout << "请输入用户名" << std::endl; continue; } } } inline void show_menu(void) { std::cout << "-----------enter the syetem------------" << std::endl; std::cout << "游客---------1" << std::endl << "管理员-------2" << std::endl << "quit--------3" << std::endl; } inline void show_menu_user_log(void) { std::cout << "欢迎进入机场票务系统,祝您使用愉快" << std::endl; std::cout << "登陆-------1" << std::endl; std::cout << "------没有账户?点击注册----" << std::endl; std::cout << "注册-------2" << std::endl; std::cout << "------忘记密码?点击找回----" << std::endl; std::cout << "找回密码----3" << std::endl; std::cout << "修改密码----4" << std::endl; std::cout << "退出-------5" << std::endl; } inline void show_menu_user_operation(void) { std::cout << "以下为可选择的服务" << std::endl; std::cout << "购票------1" << std::endl; std::cout << "退票------2" << std::endl; std::cout << "退出------3" << std::endl; } inline void show_menu_super_operation(void) { std::cout << "以下为可选择的操作" << std::endl; std::cout << "添加机场信息------1" << std::endl; std::cout << "添加航班信息------2" << std::endl; std::cout << "退出-------------3" << std::endl; } int main() { log Users; airport_integration infor_of_airports; //创建对象 ; backstage regulate; supervisor regu; int choose_identification; show_menu(); std::cout << "请输入您的身份" << std::endl; while (std::cin >> choose_identification) { if (choose_identification == 1) { std::cout << "使用者你好" << std::endl; int choose_user_log; show_menu_user_log(); std::cout << "请输入你的需求" << std::endl; while (std::cin >> choose_user_log) // user登陆界面 { if (choose_user_log == 1) { std::cout << "欢迎登陆" << std::endl; User *user_operation = Users.login(); // user::log in if(user_operation == nullptr) { std::cout << "请输入你的需求" << std::endl; break; } int choose_user; show_menu_user_operation(); std::cout << "请选择您需要的服务 " << std::endl; while (std::cin >> choose_user) // user操作 购票 退票 查看已购信息; { if (choose_user == 1) { (*user_operation).purchase(infor_of_airports); show_menu_user_operation(); std::cout << "请选择您需要的服务 " << std::endl; } else if (choose_user == 2) { (*user_operation).return_ticket(infor_of_airports); show_menu_user_operation(); std::cout << "请选择您需要的服务" << std::endl; } else { break; } } // show_menu_user_log(); std::cout << "请选择您的需求" << std::endl; } else if (choose_user_log == 2) { std::cout << "欢迎加入我们" << std::endl; Users.addusers(); // User::addusers std::cout << "注册成功" << std::endl; // show_menu_user_log(); std::cout << "请选择您的需求" << std::endl; } else if(choose_user_log == 3) { Users.forget(); show_menu_user_log(); std::cout << "请选择您的需求" << std::endl; } else if(choose_user_log == 4) { Users.change_password(); show_menu_user_log(); std::cout << "请选择您的需求" << std::endl; } else if (choose_user_log == 5) { break; } } show_menu(); std::cout << "请输入您的身份" << std::endl; } //管理员行为; else if (choose_identification == 2) { std::cout << "管理员登陆" << std::endl; if (regulate.login_super()) { std::cout << "管理员你好" << std::endl; int choose_super; std::cout << "请选择操作" << std::endl; show_menu_super_operation(); while (std::cin >> choose_super) { if (choose_super == 1) { regu.add_airport(infor_of_airports); std::cout << "请选择操作" << std::endl; show_menu_super_operation(); } if (choose_super == 2) { regu.add_flight(infor_of_airports); std::cout << "请选择操作" << std::endl; show_menu_super_operation(); } if (choose_super == 3) { break; } } } show_menu(); std::cout << "请输入您的身份" << std::endl; } //退出程序 else if (choose_identification == 3) { std::cout << "bye" << std::endl; break; } } }
上一篇 数据结构(C语言版) 线性表 算法设计Demo25
下一篇 20年ICPC澳门站L - Random Permutation
版权所有 (c)2021-2022 MSHXW.COM
ICP备案号:晋ICP备2021003244-6号