飞机订票系统程序设计c++代码
时间: 2024-06-19 08:02:45 浏览: 18
飞机订票系统的C++代码设计需要考虑以下几个方面:
1. 用户管理:设计用户信息类,包括用户ID、密码、姓名、联系方式等信息,实现用户注册、登录、修改密码等功能。
2. 航班信息管理:设计航班信息类,包括航班号、起点、终点、出发时间、到达时间、价格等信息,实现添加航班、删除航班、查询航班等功能。
3. 订单管理:设计订单类,包括订单号、用户ID、航班号、起点、终点、出发时间、到达时间、价格等信息,实现用户下单、查询订单等功能。
4. 界面设计:设计界面类,包括用户登录界面、主菜单界面、航班信息管理界面、订单管理界面等,实现用户友好的操作界面。
下面是一个简单的飞机订票系统程序设计C++代码示例:
```
#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
class User
{
private:
string UserID; //用户ID
string Password; //密码
string Name; //姓名
string Tel; //联系电话
public:
void Register(); //用户注册
bool Login(); //用户登录
void ChangePwd(); //修改密码
};
void User::Register()
{
cout<<"请输入您的姓名:";
cin>>Name;
cout<<"请输入您的联系电话:";
cin>>Tel;
cout<<"请输入您的ID:";
cin>>UserID;
cout<<"请输入您的密码:";
cin>>Password;
cout<<"注册成功!"<<endl;
}
bool User::Login()
{
string userid, pwd;
cout<<"请输入您的ID:";
cin>>userid;
cout<<"请输入您的密码:";
cin>>pwd;
if(userid==UserID && pwd==Password)
return true;
else
return false;
}
void User::ChangePwd()
{
string oldpwd, newpwd;
cout<<"请输入旧密码:";
cin>>oldpwd;
if(oldpwd!=Password)
{
cout<<"旧密码输入错误!"<<endl;
return;
}
cout<<"请输入新密码:";
cin>>newpwd;
Password=newpwd;
cout<<"修改成功!"<<endl;
}
class Flight
{
private:
string FlightNo; //航班号
string Start; //起点
string Destination; //终点
string DepartTime; //出发时间
string ArriveTime; //到达时间
float Price; //价格
public:
void AddFlight(); //添加航班
void DeleteFlight(); //删除航班
void QueryFlight(); //查询航班
};
void Flight::AddFlight()
{
cout<<"请输入航班号:";
cin>>FlightNo;
cout<<"请输入起点:";
cin>>Start;
cout<<"请输入终点:";
cin>>Destination;
cout<<"请输入出发时间(格式为hh:mm):";
cin>>DepartTime;
cout<<"请输入到达时间(格式为hh:mm):";
cin>>ArriveTime;
cout<<"请输入价格:";
cin>>Price;
}
void Flight::DeleteFlight()
{
FlightNo="";
}
void Flight::QueryFlight()
{
cout<<"航班号:"<<FlightNo<<"\t起点:"<<Start<<"\t终点:"<<Destination<<"\t出发时间:"<<DepartTime<<"\t到达时间:"<<ArriveTime<<"\t价格:"<<Price<<endl;
}
class Order
{
private:
string OrderNo; //订单号
string UserID; //用户ID
string FlightNo; //航班号
string Start; //起点
string Destination; //终点
string DepartTime; //出发时间
string ArriveTime; //到达时间
float Price; //价格
public:
void BookTicket(); //订票
void QueryOrder(); //查询订单
};
void Order::BookTicket()
{
cout<<"请输入航班号:";
cin>>FlightNo;
cout<<"请输入起点:";
cin>>Start;
cout<<"请输入终点:";
cin>>Destination;
cout<<"请输入出发时间(格式为hh:mm):";
cin>>DepartTime;
cout<<"请输入到达时间(格式为hh:mm):";
cin>>ArriveTime;
cout<<"请输入价格:";
cin>>Price;
}
void Order::QueryOrder()
{
cout<<"订单号:"<<OrderNo<<"\t用户ID:"<<UserID<<"\t航班号:"<<FlightNo<<"\t起点:"<<Start<<"\t终点:"<<Destination<<"\t出发时间:"<<DepartTime<<"\t到达时间:"<<ArriveTime<<"\t价格:"<<Price<<endl;
}
class Menu
{
public:
void ShowMenu(); //显示主菜单
void ShowUserMenu(); //显示用户菜单
void ShowAdminMenu(); //显示管理员菜单
void Run(); //程序运行
};
void Menu::ShowMenu()
{
cout<<"***************************"<<endl;
cout<<"* 1. 用户登录 "<<endl;
cout<<"* 2. 用户注册 "<<endl;
cout<<"* 3. 退出系统 "<<endl;
cout<<"***************************"<<endl;
}
void Menu::ShowUserMenu()
{
cout<<"***************************"<<endl;
cout<<"* 1. 查询航班信息 "<<endl;
cout<<"* 2. 订票 "<<endl;
cout<<"* 3. 查询订单 "<<endl;
cout<<"* 4. 修改密码 "<<endl;
cout<<"* 5. 退出登录 "<<endl;
cout<<"***************************"<<endl;
}
void Menu::ShowAdminMenu()
{
cout<<"***************************"<<endl;
cout<<"* 1. 添加航班信息 "<<endl;
cout<<"* 2. 删除航班信息 "<<endl;
cout<<"* 3. 查询航班信息 "<<endl;
cout<<"* 4. 查询订单信息 "<<endl;
cout<<"* 5. 修改密码 "<<endl;
cout<<"* 6. 退出登录 "<<endl;
cout<<"***************************"<<endl;
}
void Menu::Run()
{
while(true)
{
ShowMenu();
int choice1=0, choice2=0, choice3=0;
cin>>choice1;
if(choice1==1)
{
User u1;
if(u1.Login())
{
cout<<"登录成功!"<<endl;
if(u1.IsAdmin()) //管理员菜单
{
while(true)
{
ShowAdminMenu();
cin>>choice3;
if(choice3==1)
{
Flight f1;
f1.AddFlight();
}
else if(choice3==2)
{
Flight f1;
f1.DeleteFlight();
}
else if(choice3==3)
{
Flight f1;
f1.QueryFlight();
}
else if(choice3==4)
{
Order o1;
o1.QueryOrder();
}
else if(choice3==5)
u1.ChangePwd();
else if(choice3==6)
break;
else
cout<<"无效的输入,请重新输入!"<<endl;
}
}
else //用户菜单
{
while(true)
{
ShowUserMenu();
cin>>choice2;
if(choice2==1)
{
Flight f1;
f1.QueryFlight();
}
else if(choice2==2)
{
Order o1;
o1.BookTicket();
}
else if(choice2==3)
{
Order o1;
o1.QueryOrder();
}
else if(choice2==4)
u1.ChangePwd();
else if(choice2==5)
break;
else
cout<<"无效的输入,请重新输入!"<<endl;
}
}
}
else
cout<<"登录失败,请检查用户名和密码!"<<endl;
}
else if(choice1==2)
{
User u1;
u1.Register();
}
else if(choice1==3)
break;
else
cout<<"无效的输入,请重新输入!"<<endl;
}
}
int main()
{
Menu m1;
m1.Run();
return 0;
}
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)