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

📄 ticketbook.cpp

📁 近日做C++课程设计时写的一个民航订票系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	Object *p;
	char sel;
	do{
		cout<<"请输入要预订的航班:";
		cin>>fltNo;
		if(!(p = FlightList.Find(fltNo)))
		{
			cout<<"输入的航班不存在!\n";
			cout<<"要继续订票吗?(Y / N):";
			cin>>sel;
			if(sel == 'y' || sel == 'Y')
				continue;
			if(sel == 'n' || sel == 'N')
				return;
		}
		else
		{
			flight = p->objPoint;
			if(((CFlight *)flight)->GetCount() >= ((CFlight *)flight)->GetPeopleNum())
			{
				cout<<"该航班座位已满!\n";
				cout<<"要继续订票吗?(Y / N):";
				cin>>sel;
				if(sel == 'y' || sel == 'Y')
					continue;
				if(sel == 'n' || sel == 'N')
					return;
			}
			else
				break;
		}
	}while(1);
	((CFlight *)flight)->Show();
	cout<<"要预订此航班吗?(Y / N):";
	cin>>sel;
	if(sel == 'y' || sel == 'Y')
	{
		((CFlight *)flight)->GetCount()++;	//占用座位数加一
		cout<<"请输入客户姓名:";
		cin>>name;
		cout<<"请输入客户身份证号:";
		cin>>identityCard;
		_getsystime(&bookTime);
		bookTime.tm_year += 1900;
		bookTime.tm_mon += 1;
		psg->SetFltNo(fltNo);
		psg->SetIdentity(identityCard);
		psg->SetName(name);
		psg->SetSeatNo(((CFlight *)flight)->GetCount());
		psg->SetBookTime(bookTime);
		PsgList.AddSort(psg);
		cout<<"已成功预订!\n"<<flush;
	}
	if(sel == 'n' || sel == 'N')
		cout<<"已取消预订!\n";
	cout<<flush;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	+--------------------------------------+
	|此函数负责客户的退票,要求			   |
	|要求输入身份证号,从客户链表删除之	   |	
	+--------------------------------------+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

void Cancel()
{
	char iCard[19];
	char fltNo[10];
	char sel;
	Object *p;
	CBaseObj *psg;
	CBaseObj *flight;
	do{
		cout<<"请输入客户身份证号:";
		cin>>iCard;
		if(!(p = PsgList.Find(iCard)))
		{
			cout<<"该客户没有预订!\n";
			cout<<"要继续退票吗?(Y / N):";
			cin>>sel;
			if(sel == 'y' || sel == 'Y')
				continue;
			if(sel == 'n' || sel == 'N')
				return;
		}
		else
			break;
	}while(1);
	psg = p->objPoint;
	((CPassenger *)psg)->Show();
	cout<<"真的要退票吗?(y / N):";
	cin>>sel;
	if(sel == 'y' || sel == 'Y')
	{
		strcpy(fltNo,((CPassenger *)psg)->GetFltNo());
		flight = FlightList.Find(fltNo)->objPoint;
		((CFlight *)flight)->GetCount()--;
		PsgList.Delete(iCard);
		cout<<"已成功退票!\n"<<flush;
	}
	if(sel == 'n' || sel == 'N')
		cout<<"已取消退票!\n";
	cout<<flush;

}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	+----------------------------------------------+
	|航班查询函数,分两种查询方式:				   |
	|1. 按航班查询	2. 按终始港或途径港查询		   |
	|要求输入航班号, 或两个途径港				   |
	+----------------------------------------------+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void QueryFlight()
{
	CBaseObj *flight;
	char fltNo[10];
	char from[20];
	char to[20];
	char sel;
	bool bfind = false;
	do{
		cout<<"您要以哪种方式查询?\n";
		cout<<"1. 按航班查询	2. 按终始港或途径港查询\n";
		cout<<"输入1 或 2:";
		cin>>sel;
		if(sel == '1')
		{
			cout<<"请输入航班号:";
			cin>>fltNo;
			if(!FlightList.Find(fltNo))
			{
				cout<<"输入的航班不存在!\n";
				cout<<"要继续查询吗?(Y / N):";
				cin>>sel;
				if(sel == 'y' || sel == 'Y')
					continue;
				if(sel == 'n' || sel == 'N')
					return;
			}
			else
			{
				flight = FlightList.Find(fltNo)->objPoint;
				((CFlight *)flight)->Show();
			}
		}	//if(sel == '1')结束
		if(sel == '2')
		{
			Object *p = FlightList.GetHead().nextObj;
			cout<<"请输入起始地:";
			cin>>from;
			cout<<"请输入到达地:";
			cin>>to;
			while(p)
			{
				PASS *ps1 = ((CFlight *)(p->objPoint))->GetPass().nextStation;
				while(ps1->nextStation)
				{
					if(strcmp(ps1->stationName, from) == 0)
						break;
					ps1 = ps1->nextStation;
				}
				PASS *ps2;

				if(ps1->nextStation)
				{
					ps2 = ps1->nextStation;
					while(ps2)
					{
						if(strcmp(to, ps2->stationName) == 0)
							break;
						ps2 = ps2->nextStation;
					}
					if(ps2)
					{
						bfind = true;
						((CFlight *)(p->objPoint))->Show();
						cout<<"航班的信息如下:\n";
						((CFlight *)(p->objPoint))->ShowPass();
					}	
					cout<<"按任意键继续查找下一个信息...\n"<<flush;
					getch();
					
				}		//if(ps1)结束
				p = p->nextObj;
			}	//while(p)结束
			if(bfind)
				cout<<"查找结束!\n";
			else
				cout<<"查找结束,未找到任何信息!\n";
		}	//if(sel == '2')结束
		cout<<"要继续查询吗?(Y / N):";
		cin>>sel;
		if(sel == 'y' || sel == 'Y')
			continue;
		if(sel == 'n' || sel == 'N')
			return;
	}while(1);
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	+-----------------------------------------+
	|要求输入客户身份证号,获得客户的订票信息 |
	+-----------------------------------------+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void QueryPsg()
{
	char iCard[19];
	Object *p;
	CBaseObj *psg;
	char sel;
	do{
		cout<<"请输入乘客的身份证号:\n";
		cin>>iCard;
		if(p = PsgList.Find(iCard))
		{
			psg = p->objPoint;
			((CPassenger *)psg)->Show();
			cout<<"要继续查询吗?(Y / N):";
			cin>>sel;
			if(sel == 'y' || sel == 'Y')
				continue;
			if(sel == 'n' || sel == 'N')
				return;
		}
		else
		{
			cout<<"该客户没有任何预订!\n";
			cout<<"要继续查询吗?(Y / N):";
			cin>>sel;
			if(sel == 'y' || sel == 'Y')
				continue;
			if(sel == 'n' || sel == 'N')
				return;
		}
	}while(1);
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	+-----------------------------------------+
	|修改某一个航班的信息					  |
	+-----------------------------------------+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

void FlightModify(CFlight *flight);
void ModifyFlight()
{
	char fltNo[10];
	CBaseObj *flight;
	Object *p;
	char sel;
	do{
		cout<<"请输入要修改的航班号:";
		cin>>fltNo;
		p = FlightList.Find(fltNo);
		if(!p)
			cout<<"要修改的航班不存在!\n";
		else
		{
			flight = p->objPoint;
			((CFlight *)flight)->Show();
			FlightModify((CFlight *)flight);
		}
		cout<<"要继续修改其他航班吗?(Y / N):";
		cin>>sel;
		if(sel == 'y' || sel == 'Y')
			continue;
		if(sel == 'n' || sel == 'N')
			return;
	}while(1);
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	+-----------------------------------------+
	|选择修改某一个航班的哪部分信息			  |
	+-----------------------------------------+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

void FlightModify(CFlight *flight)
{
	char from[20];								//起飞港
	char to[20];								//到达港
	tm start;									//起飞时间
	tm arrive;									//到达时间
	int peopleNum;								//乘客限额
	char station[20];
	char sel;
	do{
		cout<<"要修改那部分信息?\n";
		cout<<"1. 起始港及起飞时间		2. 到达港及到达时间\n";
		cout<<"3. 乘客限额		4. 添加途径港	5. 删除途径港\n";
		cout<<"请选择(1 ~ 5):";
		cin>>sel;
		switch(sel)
		{
		case '1':
			cout<<"输入新的起始港:";
			cin>>from;
			cout<<"输入新的起飞时间(hh mm):";
			cin>>start.tm_hour>>start.tm_min;
			flight->SetFrom(from);
			flight->SetStart(start);
			break;
		case '2':
			cout<<"输入新的到达港:";
			cin>>to;
			cout<<"输入新的到达时间(hh mm):";
			cin>>arrive.tm_hour>>arrive.tm_min;
			flight->SetTo(to);
			flight->SetArrive(arrive);
			break;
		case '3':
			cout<<"输入新的乘客限额:";
			cin>>peopleNum;
			flight->SetPeopleNo(peopleNum);
			break;
		case '4':
			flight->SetPass();
			break;
		case '5':
			cout<<"输入要删除的航空港(起始,到达港除外):";
			cin>>station;
			if(!(flight->DelPass(station)))
				cout<<"输入信息错误!\n";
			break;
		}
		cout<<"要继续修改其他信息吗?(Y / N):";
		cin>>sel;
		if(sel == 'y' || sel == 'Y')
			continue;
		if(sel == 'n' || sel == 'N')
			return;
	}while(1);
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	+-----------------------------------------+
	|添加一个航班							  |
	+-----------------------------------------+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

void AddFlight()
{
	CFlight *flight;
	flight = new CFlight();
	char fltNo[10] = "";								//航班号
	char from[20] = "";								//起飞港
	char to[20] = "";								//到达港
	tm start;									//起飞时间
	tm arrive;									//到达时间
	int peopleNum;								//乘客限额
	cout<<"请输入航班号:";
	cin>>fltNo;
	cout<<"请输入起飞港:";
	cin>>from;
	cout<<"请输入起飞时间(hh mm):";
	cin>>start.tm_hour>>start.tm_min;
	cout<<"请输入到达港:";
	cin>>to;
	cout<<"请输入到达时间(hh mm):";
	cin>>arrive.tm_hour>>arrive.tm_min;
	cout<<"请输入乘客限额:";
	cin>>peopleNum;
	flight->InitPass();
	flight->SetFltNo(fltNo);
	flight->SetFrom(from);
	flight->SetStart(start);
	flight->SetTo(to);
	flight->SetArrive(arrive);
	flight->SetPeopleNo(peopleNum);
//	flight->InitPass();
	FlightList.AddSort(flight);
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	+-----------------------------------------+
	|删除一个航班							  |
	+-----------------------------------------+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

void DelFlight()
{
	char fltNo[10];
	cout<<"请输入要删除的航班号:";
	cin>>fltNo;
	if(!FlightList.Delete(fltNo))
		cout<<"输入的航班不存在!\n";
	else
		cout<<"已成功取消航班!\n";
	cout<<flush;
}


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	+-------------------------------------------+
	|修改某一个用户的信息,如果用户不是超级用户	|
	|则只能修改自己的信息						|
	+-------------------------------------------+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

void ModifyUser(CUser LoginUser)
{
	char userID[20];
	char password[20];
	int popedom, i;
	CBaseObj *user;
	Object *p;
	char sel;
	if(LoginUser.GetPopedom() == 0)
	{
		cout<<"请输入要修改的用户名:";
		cin>>userID;
		p = UserList.Find(userID);
		if(!p)
			cout<<"要修改的用户不存在!\n"<<flush;
		else
		{
			user = p->objPoint;
			cout<<"该用户信息如下:\n";
			((CUser *)user)->Show();
			cout<<"要修改那一部分?\n";
			cout<<"1. 用户名	2. 密码		3. 用户权限\n";
			cin>>sel;
			switch(sel)
			{
			case '1':
				cout<<"请输入新用户名:";
				cin>>userID;
				((CUser *)user)->SetUserID(userID);
				break;
			case '2':
				cout<<"请输入新密码:"<<flush;
				for( i = 0;i < 20; i++)
				{
					password[i] = getch();
					if(password[i] == '\r')
					{	
						password[i] = '\0';
						break;
					}
					cout<<"*"<<flush;
				}
				((CUser *)user)->SetPassword(password);
				break;
			case '3':
				cout<<"请输入新权限(0 :超级用户  1: 普通用户):";
				cin>>popedom;
				((CUser *)user)->SetPopedom(popedom);
				break;
			}
		}
	}
	else
	{
		cout<<LoginUser.GetUserID()<<" 你不是超级用户,只能修改自己的信息!\n";
		p = UserList.Find(userID);
		user = p->objPoint;
		cout<<"要修改那一部分?\n";
		cout<<"1. 用户名	2. 密码\n";
		cin>>sel;
		switch(sel)
		{
		case '1':
			cout<<"请输入新用户名:";
			cin>>userID;
			((CUser *)user)->SetUserID(userID);
			LoginUser.SetUserID(userID);
			break;
		case '2':
			cout<<"请输入新密码:"<<flush;
			for( i = 0;i < 20; i++)
			{
				password[i] = getch();
				if(password[i] == '\r')
				{	
					password[i] = '\0';
					break;
				}
				cout<<"*"<<flush;
			}
			((CUser *)user)->SetPassword(password);
			LoginUser.SetPassword(password);
			break;
		}
	}
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	+-----------------------------------------+
	|添加一个航班,只有超级用户有此权限		  |
	+-----------------------------------------+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void AddUser()
{
	CUser *user;
	user = new CUser;
	char userID[20];
	char password[20];
	int popedom, i;
	cout<<"请输入新用户名:";
	cin>>userID;
	user->SetUserID(userID);
	cout<<"请输入新密码:"<<flush;
	for( i = 0;i < 20; i++)
	{
		password[i] = getch();
		if(password[i] == '\r')
		{	
			password[i] = '\0';
			break;
		}
		cout<<"*"<<flush;
	}
	user->SetPassword(password);
	cout<<endl;
	cout<<"请输入新权限(0 :超级用户  1: 普通用户):";
	cin>>popedom;
	user->SetPopedom(popedom);
	UserList.AddSort(user);
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	+-----------------------------------------+
	|删除某个用户,只有超级用户有此权限		  |
	+-----------------------------------------+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

void DelUser()
{
	char userID[20];
	cout<<"请输入要删除的用户名:";
	cin>>userID;
	if(!UserList.Delete(userID))
		cout<<"输入的用户不存在!\n";
	else
		cout<<"已成功删除用户!\n";
	cout<<flush;

}

⌨️ 快捷键说明

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