⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 airinfo.cpp

📁 一个简单的机票预订系统 个人觉得还好了
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*
开发日志:
        2005年25日构思
(开始)2005年26日晚上7:30分到关电
        2005年27日,唔唔~~宿舍没电做不了,这一天心情很难过,到晚上7:25分才有时间继续做到关电
		2005年28日,早上从8:15分做起到中午吃饭,下午做一个下午......
*/
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;

class Customer        //客户类
{
public:
	string m_strID;   //客户ID号
	string m_strName; //客户姓名
	int    m_nWant;   //客户要订的票数
};

///////////////////////////////////////////////////////////
class AirInfo//航班信息
{
	string m_strNum;       //航班号
	string m_strStart;     //航班起点站
	string m_strEnd;       //航班终点站
	string m_strTime;      //航班起飞时间日期
	string m_strFlyTime;   //飞行时间

	int m_nCount;          //航班票数
	int m_nLeftCount;      //剩余票数

public:
	vector<Customer> m_wPerson;//等待订票的顾客队列,其中m_wPerson.size()即为排队的客户数
    vector<Customer> m_haveBook;//已订票客户

	AirInfo();
	void SetNum(string &n);          //设计航班号
	void SetStart(string &start);    //设计航班起飞点
	void SetEnd(string &end);        //设计航班终点地
	void SetTime(string &time);      //设计航班起飞时间
	void SetCount(int count);        //设计航班票数
	void SetLeftCount(int left);     //设计航班剩余票数
	void SetFlyTime(string &time);   //设计航班飞行总时间
	void SetWait(Customer &p);     //设计航班的等候订票队列,每次进一个人
	void SetHavingBookCustomer(Customer &p);//设计已订票的客户
	string        GetFlyTime();      //获取航班飞行总时间
	string        GetTime();         //获取航班起飞时间日期
    int           GetWaitCount();    //获取等侯订票队列人数
	int           GetLeftCount();    //航班剩余票数
	string        GetStart();        //获取该航班起飞地
	string        GetEnd();          //获取该航班终点地
	string        GetNum();          //获取该航班号
	int           GetCount();        //获取该航班总票数
	void          PrintInfo();       //打印该航班的信息
	~AirInfo(){}

};
void AirInfo::SetHavingBookCustomer(Customer &p)//
{
	m_haveBook.push_back(p);//记录已订票的客户

}
int AirInfo::GetLeftCount()
{
	return m_nLeftCount;
}
int AirInfo::GetWaitCount()
{
	return m_wPerson.size();
}
string AirInfo::GetTime()
{
	return m_strTime;
}
string AirInfo::GetFlyTime()
{
	return m_strFlyTime;
}
void AirInfo::SetWait(Customer &p)//每次进入一个等侯订票的客户
{
	m_wPerson.push_back(p);         //让客户排在队列后面
}
void AirInfo::SetFlyTime(string &time)
{
	m_strFlyTime=time;
}
void AirInfo::SetLeftCount(int left)
{
	m_nLeftCount=left;
}
AirInfo::AirInfo()
{
	//初始化为空
	m_strNum="";       //航班号
	m_strStart="";     //航班起点站
	m_strEnd="";       //航班终点站
	m_strTime="";      //航班起飞时间
	m_strFlyTime="";   //飞行时间
	m_nCount=0;        //航班票数
    m_nLeftCount=0;    //剩余票数

}
int AirInfo::GetCount()
{
	return m_nCount;
}
string AirInfo::GetNum()
{
	return m_strNum;
}
string AirInfo::GetEnd()
{
	return m_strEnd;
}
string AirInfo::GetStart()
{
	return m_strStart;
}
void AirInfo::SetCount(int count)
{
	m_nCount=count;
}
void AirInfo::SetTime(string &time)
{
	m_strTime=time;
}
void AirInfo::SetEnd(string &end)
{
	m_strEnd=end;
}
void AirInfo::SetStart(string &start)
{
    m_strStart=start;
}
void AirInfo::SetNum(string &n)
{
    m_strNum=n;
}
void AirInfo::PrintInfo()//打印本航班信息
{
	cout<<endl;
	cout<<"\t************************航班信息********************"<<endl;
	cout<<"\t航班号:"<<m_strNum<<"\t"<<"起飞站:"<<m_strStart<<"\t终点站:"<<m_strEnd<<endl;
	cout<<"\t起飞时间:"<<m_strTime<<"\t飞行总时间(小时):"<<m_strFlyTime<<endl;
	cout<<"\t航班总票数:"<<m_nCount<<"\t剩余票数:"<<m_nLeftCount<<endl;

    if(m_haveBook.size()!=0)
	{
		cout<<"\t该航班有"<<m_haveBook.size()<<"个客户已订票,其信息如下:"<<endl;
    	cout<<"\t\t";
    	for(int i=0;i<m_haveBook.size();i++)
		{
	    	cout<<"客户ID号:"<<m_haveBook[i].m_strID<<"  "
				<<"客户姓名:"<<m_haveBook[i].m_strName<<"  "
		    	<<"订票数量:"<<m_haveBook[i].m_nWant;
			cout<<endl<<"\t\t";
		}
		cout<<endl;
	}
	cout<<"\t\t**********"<<endl;
    if(m_wPerson.size()!=0)
	{
		cout<<"\t该航班有"<<m_wPerson.size()<<"个客户等待订票,其信息如下:"<<endl;
    	cout<<"\t\t";
    	for(int i=0;i<m_wPerson.size();i++)
		{
	    	cout<<"客户ID号:"<<m_wPerson[i].m_strID<<"  "
				<<"客户姓名:"<<m_wPerson[i].m_strName<<"  "
		    	<<"订票数量:"<<m_wPerson[i].m_nWant;
			cout<<endl<<"\t\t";
		}
		cout<<endl;
	}
	cout<<"\t*****************************************************"<<endl;
}
void LoadData(vector<AirInfo*> *vec_Air)//从文件导入数据
{
	AirInfo* pA;          //航班信息指针
	fstream dateFile;
	dateFile.open("AirInfo.txt",ios::in);//打开航班信息数据文件
    
	string tem;           //临时变量
	int wait=0;           //等待订票的客户数
	int date=0;
	int havedBook=0;        //已订票和客户数
	while(dateFile>>tem)  //从文件里导入数据
	{
		//处理一条航班记录
		{//动态创建
			pA=new AirInfo();//在内存申请一块空间
			pA->SetNum(tem); //设计航班编号
	        //正在对一条记录处理,不能跳到另外一条记录
		}
	    //对字符串的处理
		{
			dateFile>>tem;
			pA->SetStart(tem);   //起飞点站

			dateFile>>tem;
			pA->SetEnd(tem);     //终点站

			dateFile>>tem;
			pA->SetTime(tem);    //起飞时间(日期)

			dateFile>>tem;
			pA->SetFlyTime(tem); //飞行总时间

		}
	    //对数字处理
		{
			dateFile>>tem;
			date=atoi(tem.c_str());  //把字符串转换成整形int
			pA->SetCount(date);      //设计航班票数

			dateFile>>tem;
			date=atoi(tem.c_str());
			pA->SetLeftCount(date);  //设计航班剩余票数
            //////对已订票的客户处理
			dateFile>>tem;
			havedBook=atoi(tem.c_str());
			for(int j=0;j<havedBook;j++)
			{
				Customer havedPerson;
				dateFile>>tem;
				havedPerson.m_strID=tem;  //客户ID
				dateFile>>tem;
				havedPerson.m_strName=tem;//客户名字
				dateFile>>tem;
				havedPerson.m_nWant=atoi(tem.c_str());//客户要订票的数目
				pA->SetHavingBookCustomer(havedPerson);
			}
			///////对等候客户的数据导入
			dateFile>>tem;
			wait=atoi(tem.c_str());  //本航班有wait个客户等候排队订票

            for(int i=0;i<wait;i++)  //有wait个客户等待订票,每个客户订票数不同
			{
				Customer person;
				dateFile>>tem;
				person.m_strID=tem;  //客户ID
				dateFile>>tem;
				person.m_strName=tem;//客户名字
				dateFile>>tem;
				person.m_nWant=atoi(tem.c_str());//客户要订票的数目
				pA->SetWait(person);
			}
		}
		vec_Air->push_back(pA);//把本航班的整条信息记录放入模板里(用作航班信息暂存器)

	}
	dateFile.close();         //关闭文件
}
//////////////////////////////////
void NewAirInfo(vector<AirInfo*> *vec_Air)//输入新的航班信息
{
	AirInfo* pA;
	char yes='n';
	cout<<"您确定要录入新的航班信息吗?(y/n):";
	cin>>yes;
	if(yes=='n'||yes=='N')return ;
	cout<<endl;

	string num,start,end,time,flytime;
    int count;
	/****************开始录入航班信息*****************/
	cout<<"请输入新航班的编号:";
	cin>>num;
	cout<<endl;
	cout<<"请输入新航班的的起点站:";
	cin>>start;
	cout<<endl;
	cout<<"请输入新航班的的终点站:";
	cin>>end;
	cout<<"请输入新航班的的起飞时间:";
	cin>>time;
    cout<<endl;
	cout<<"请输入新航班的的总飞行时间:";
	cin>>flytime;
	cout<<"请输入新航班的的总票数:";
	cin>>count;
	cout<<endl;
	//申请新航班内存空间
	pA=new AirInfo();
	pA->SetNum(num);          //新航班编号
	pA->SetStart(start);      //新航班起点站
	pA->SetEnd(end);          //新航班终点站
	pA->SetTime(time);        //新航班起飞日期
	pA->SetFlyTime(flytime);  //新航班总飞行时间(小时)
	pA->SetCount(count);      //新航班总票数
	pA->SetLeftCount(count);  //新航班剩余票数

	vec_Air->push_back(pA);
	cout<<endl;
	cout<<"\t录入新航班信息成功,请查看!"<<endl;
	cout<<"\t按任意键返回主界面!";
	cin.get();
	cin.get();
	/****************结束录入航班信息*****************/
}
////////////////////////////
void FindAirInfo(vector<AirInfo*> vec_Air)//查询航班信息
{

	system("cls");
	cout<<endl;
	char choice='p';

	while(choice!='y')
	{
         system("cls");
		 cout<<endl;
     	 cout<<"\t\t1按航班编号查询"<<"\t\t2.按起点站查询"<<endl;
	     cout<<"\t\t3.按终点站查询"<<"\t\t4.按起飞时间(日期)"<<endl;
	     cout<<"\t\t5.按飞行总时间查询"<<"\t0.返回主界面"<<endl<<endl;
	     cout<<"\t\t请选择(0-5):";
	     cin>>choice;
	     switch(choice)
		 {
	      case '1'://按航班编号查询
			  {
			      string num;
			      cout<<"\t请输入要查询的航班编号:";
			      cin>>num;
			      for(int i=0;i<vec_Air.size();i++)
				  {
				     if(vec_Air[i]->GetNum()==num)//是否有相应的航班编号
					 {
					     vec_Air[i]->PrintInfo();//打印输出相应航班的所有信息
					     break;
					 }
				  }
			      if(i==vec_Air.size())	  
				  {//如果找到所有记录最后还没有找到要找的航班编号,则表示没有此航班
				      cout<<"\t对不起,没有找到该编号的航班信息!";
				  }
			      cin.get();
			      cin.get();
			      break;
			  }
	     case '2'://按起点站查询
			 {
			      int flag=0;
			      string start;
		       	  cout<<"\t请输入要查询起点站:";
			      cin>>start;
			      for(int i=0;i<vec_Air.size();i++)//把所有起点站相同的航班找出来
				  {
				      if(vec_Air[i]->GetStart()==start)
					  {
					      vec_Air[i]->PrintInfo();
					      flag=1;      //说明起码找到一条相应的记录

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -