一、可行性分析

面对影院在日常管理过程中出现的各种情况,电影院售票管理系统时,应能够达到以下目标:
电影院售票管理系统两个模块管理系统和售票系统。
1.管理系统具有如下功能:
(1)录入信息:且可不定时增加数据。并根据放映时间排序。
(2)浏览信息:可显示出某日期所有放映信息,如果当前系统时间超过了某电影的放映时间,则显示“此电影放映结束”的提示信息。
(3)查询电影:可按日期或电影名查询。并显示目标的详细信息。
(4)修改信息:可根据电影名修改该电影的各种信息(余票除外)并简单排序。
(5)删除电影:根据电影名找到该电影并删除。
2.售票系统功能如下:
(1)售票:售票即为影片预定。可根据输出的可预订信息选择订票,如果该影片已放映,则提示不能订票,如果售票成功,自动跟新座位数。
(2)退票:影片退订即退票。根据放映时间和系统时间来判断是否能进行退票,并自动更新座位数。

二、项目规划

本系统主要是实现电影院自助售票&管理,从而提高售票和管理效率。使用本系统,可以有效地管理和统计影票的基本信息和各类影院的相关信息,包括:影票基本信息、放映时间信息等,完成这些信息的增加、删除、 修改、查询统计功能,同时,还可以将这些信息打印输出,以方便整理和存档。也可以实现用户自由的进行购票,取票,退票操作。
具体功能模块如下:
(1) 销售管理(影票信息购买和购票信息的查询以及退票等)
(2) 查询管理(放映场次查询,售票情况查询等)
(3) 影片管理(影片信息的录入、修改影片信息和删除影片等)
(4) 系统管理(管理员初始密码的分配,以及系统的使用注意事项的告知等)

三、系统功能结构

本系统共分3大部分、12个完整的功能模块。系统结构图如下:

图3-1 电影院自助售票&管理系统

四、系统设计

1.设计资料及参数:
(1)录入放映信息,可不定时地增加放映数据,格式为:
表4-1  影片信息录入格式
(2)浏览放映信息,可显示出某日期所有放映信息,如果当前系统时间超过了某电影的放映时间,则显示“此电影放映结束”的提示信息。
(3)查询电影:可按日期或电影名查询。
(4)售票和退票功能
2.设计要求及成果
根据系统功能要求,可以将问题解决分为以下步骤:
(1)分析系统中的各个实体之间的关系及其属性和行为;
(2)根据问题描述,设计系统的类层次;
(3)完成类层次中各个类的描述(包括属性和力一法);
(4)完成类中各个成.员函数的定义;
(5)完成系统的应用模块;
(6)功能调试;

五、系统测试

1.主界面

运行截图:
图5-1  程序主界面运行结果

代码如下:

//主面板
void Menu::main_Menu()
{

	while (1)
	{
		system("cls");//清屏
		//cout << endl;
		cout << endl;
		cout << "\t\t\t┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n";
		cout << "\t\t\t┃                                      ┃\t\n";
		cout << "\t\t\t┃              1.用    户              ┃\t\n";
		cout << "\t\t\t┃                                      ┃\t\n";
		cout << "\t\t\t┃              2.管 理 员              ┃\t\n";
		cout << "\t\t\t┃                                      ┃\t\n";
		cout << "\t\t\t┃              3.系统帮助              ┃\t\n";
		cout << "\t\t\t┃                                      ┃\t\n";
		cout << "\t\t\t┃              0.退    出              ┃\t\n";
		cout << "\t\t\t┃                                      ┃\t\n";
		cout << "\t\t\t┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n";
		cout << endl;
		int choice = -1;
		cout << "\t\t\t【系统提示】请输入你的选择项(0-3):";
		cin >> choice;
		if (choice < -1 || choice>3)
		{
			cout << "\t\t\t【系统提示】输入格式错误,请重新输入:";
			cin >> choice;
		}
		switch (choice)
		{
		case 1:user_Menu(); break;//用户菜单调用
		case 2:manager_Menu(); break;//管理员菜单调用
		case 3:help_Menu(); break;//系统帮助调用
		case 0:exit_Menu(); break;//退出
		}
	}
}

2.用户购票

运行截图:
图5-2  用户购票界面运行结果

代码如下:

//售票
void ticket::sell()
{
	tick.read();//影片信息读取
	tick.sort1();//排序调用
	//获取系统时间与已输入时间进行比较
	time_t timep;
	struct tm* p;
	int in_time[5];
	int now_time[5];
	int i;
	int k = 0;// 标记可供预定的影片数量 

	cout << "【系统提示】可预订的电影信息如下:" << endl;
	cout << " -------------------------------------------------------------------------------------------------- " << endl;
	cout << setw(22) << setiosflags(ios::left) << "|       影片名称"
		<< setw(9) << setiosflags(ios::left) << "|  类型"
		<< setw(10) << setiosflags(ios::left) << "|   时长"
		<< setw(13) << setiosflags(ios::left) << "|  放映日期"
		<< setw(11) << setiosflags(ios::left) << "| 放映时间"
		<< setw(11) << setiosflags(ios::left) << "| 放映影厅"
		<< setw(7) << setiosflags(ios::left) << "| 票价"
		<< setw(9) << setiosflags(ios::left) << "| 会员价"
		<< setw(7) << setiosflags(ios::left) << "| 余票" << "|" << endl;
	
	for (i = 0; i < tick.len; i++)
	{
		//将输入时间依次赋值给输入时间数组
		in_time[0] = tick.tic[i].year;//输入时间-年
		in_time[1] = tick.tic[i].month;//输入时间-月
		in_time[2] = tick.tic[i].day;//输入时间-日
		in_time[3] = tick.tic[i].hour;//输入时间-时
		in_time[4] = tick.tic[i].minute;//输入时间-分

		time(&timep);
		p = gmtime(&timep);

		//将系统时间依次赋值给系统时间数组
		now_time[0] = 1900 + p->tm_year;//系统时间-年
		now_time[1] = 1 + p->tm_mon;//系统时间-月
		now_time[2] = p->tm_mday;//系统时间-日
		now_time[3] = 8 + p->tm_hour;//系统时间-时
		now_time[4] = p->tm_min;//系统时间-分

		//依次比较五项数据
		for (int x = 0; x < 5; x++)
		{
			if (in_time[x] > now_time[x])
			{
				k++;
				cout << "|--------------------------------------------------------------------------------------------------|" << endl;
				cout << "|" << setw(21) << setiosflags(ios::left) << tick.tic[i].name << "|"
					<< " " << setw(7) << setiosflags(ios::left) << tick.tic[i].type << "|"
					<< " " << setw(3) << setiosflags(ios::left) << tick.tic[i].min << setw(5) << setiosflags(ios::left) << "分钟" << "|"
					<< " " << setw(4) << setiosflags(ios::left) << tick.tic[i].year << "-" << setw(2) << setiosflags(ios::left) << tick.tic[i].month << "-" << setw(3) << setiosflags(ios::left) << tick.tic[i].day << "|"
					<< "   " << setw(2) << setiosflags(ios::left) << tick.tic[i].hour << ":" << setw(4) << setiosflags(ios::left) << tick.tic[i].minute << "|"
					<< "   " << setw(1) << setiosflags(ios::left) << tick.tic[i].num << setw(6) << setiosflags(ios::left) << "号厅" << "|"
					<< " " << setw(5) << setiosflags(ios::left) << tick.tic[i].price << "|"
					<< " " << setw(7) << setiosflags(ios::left) << tick.tic[i].discount << "|"
					<< " " << setw(5) << setiosflags(ios::left) << tick.tic[i].rest << "|" << endl;
				
				break;
				cout << " -------------------------------------------------------------------------------------------------- " << endl;
			}
			
			if (in_time[x] < now_time[x])
			{
				break;
			}
		}
		
	}
	cout << " -------------------------------------------------------------------------------------------------- " << endl;
	if (tick.len == 0 || k == 0)
	{
		cout << "【系统提示】暂无可供预定的影片!" << endl;
		return;
		system("pause");// 任意键继续
	}
	system("pause");// 任意键继续

	string na;
	cout << endl << "【系统提示】请输入要预订的影片名:";
	cin >> na;
	k = 0;// 再次做标记
	for (i = 0; i < tick.len; i++)
	{
		if (tick.tic[i].name == na)// 找到  
		{
			k++;// 找到的记录数  
			int j = 1;
			if (j == 1)
			{
				cout << "【系统提示】查找结果如下:" << endl;
				cout << " -------------------------------------------------------------------------------------------------- " << endl;
				cout << setw(22) << setiosflags(ios::left) << "|       影片名称"
					<< setw(9) << setiosflags(ios::left) << "|  类型"
					<< setw(10) << setiosflags(ios::left) << "|   时长"
					<< setw(13) << setiosflags(ios::left) << "|  放映日期"
					<< setw(11) << setiosflags(ios::left) << "| 放映时间"
					<< setw(11) << setiosflags(ios::left) << "| 放映影厅"
					<< setw(7) << setiosflags(ios::left) << "| 票价"
					<< setw(9) << setiosflags(ios::left) << "| 会员价"
					<< setw(7) << setiosflags(ios::left) << "| 余票" << "|" << endl;
			}
			j++;
			cout << "|--------------------------------------------------------------------------------------------------|" << endl;
			cout << "|" << setw(21) << setiosflags(ios::left) << tick.tic[i].name << "|"
				<< " " << setw(7) << setiosflags(ios::left) << tick.tic[i].type << "|"
				<< " " << setw(3) << setiosflags(ios::left) << tick.tic[i].min << setw(5) << setiosflags(ios::left) << "分钟" << "|"
				<< " " << setw(4) << setiosflags(ios::left) << tick.tic[i].year << "-" << setw(2) << setiosflags(ios::left) << tick.tic[i].month << "-" << setw(3) << setiosflags(ios::left) << tick.tic[i].day << "|"
				<< "   " << setw(2) << setiosflags(ios::left) << tick.tic[i].hour << ":" << setw(4) << setiosflags(ios::left) << tick.tic[i].minute << "|"
				<< "   " << setw(1) << setiosflags(ios::left) << tick.tic[i].num << setw(6) << setiosflags(ios::left) << "号厅" << "|"
				<< " " << setw(5) << setiosflags(ios::left) << tick.tic[i].price << "|"
				<< " " << setw(7) << setiosflags(ios::left) << tick.tic[i].discount << "|"
				<< " " << setw(5) << setiosflags(ios::left) << tick.tic[i].rest << "|" << endl;
			cout << " -------------------------------------------------------------------------------------------------- " << endl;

			cout << endl;
			cout << "【系统提示】影片《" << na << "》当前预订情况(■表示已预定,□表示未预定)" << endl;
			cout << "【系统提示】" << tick.tic[i].num << "号厅座位示意图";
			cout << endl;
			for (int m = 0; m < 10; m++)
			{
				cout << endl;
				for (int n = 0; n < 10; n++)
				{
					if (tick.tic[i].seat[m][n] != 0)
					{

						cout << " ■";
					}
					else
					{
						cout << " □";
					}
				}
			}
			cout << endl;
			cout << endl;
			cout << "【系统提示】请输入预订的座位号(1-100):";
			int seatnum;
			cin >> seatnum;
			if (seatnum > 100 || seatnum < 1)
			{
				cout << endl << "【系统提示】对不起,无此座位!";
				system("pause");// 任意键继续  
				return;
			}
			int m, n;
			m = (seatnum - 1) / 10;//座位号取个位-1
			n = (seatnum - 1) % 10;//座位号取十位-1
			if (tick.tic[i].seat[m][n] == 0 && tick.tic[i].rest != 0)
			{
				cout << "【系统提示】是否以会员权限购买(Y/N):";
				char a;
				int price;
				cin >> a;
				if (a != 'N' && a != 'n')
				{
					//原价购买
					tick.tic[i].seat[m][n] = tick.tic[i].price;
				}
				else
				{
					//会员价购买
					tick.tic[i].seat[m][n] = tick.tic[i].discount;
				}
				tick.tic[i].rest--;//余位减一

				string ph;
				cout << "【系统提示】请输入预定手机号:";
				cin >> ph;
				//将订单信息保存至文件

				ud.read();//订单信息读取
				//将订单数据保存
				for (int x = scount1; x < scount1 + 1; x++)
				{
					userdata[x].phone = ph;
					userdata[x].name = na;
					userdata[x].type = tick.tic[i].type;
					userdata[x].min = tick.tic[i].min;
					userdata[x].year = tick.tic[i].year;
					userdata[x].month = tick.tic[i].month;
					userdata[x].day = tick.tic[i].day;
					userdata[x].hour = tick.tic[i].hour;
					userdata[x].minute = tick.tic[i].minute;
					userdata[x].num = tick.tic[i].num;
					userdata[x].seat = seatnum;
					userdata[x].price = tick.tic[i].seat[m][n];
					scount1++;
					ud.save();//订单信息保存
					break;
				}

				cout << endl;
				cout << "【系统提示】订单信息确认: " << endl;
				cout << " ---------------------------------------------------------------------------------------------- " << endl;
				cout << setw(22) << setiosflags(ios::left) << "|       影片名称"
					<< setw(9) << setiosflags(ios::left) << "|  类型"
					<< setw(10) << setiosflags(ios::left) << "|   时长"
					<< setw(13) << setiosflags(ios::left) << "|  放映日期"
					<< setw(11) << setiosflags(ios::left) << "| 放映时间"
					<< setw(11) << setiosflags(ios::left) << "| 放映影厅"
					<< setw(10) << setiosflags(ios::left) << "|  座位号"
					<< setw(9) << setiosflags(ios::left) << "| 需支付" << "|" << endl;
				cout << "|----------------------------------------------------------------------------------------------|" << endl;
				cout << "|" << setw(21) << setiosflags(ios::left) << tick.tic[i].name << "|"
					<< " " << setw(7) << setiosflags(ios::left) << tick.tic[i].type << "|"
					<< " " << setw(3) << setiosflags(ios::left) << tick.tic[i].min << setw(5) << setiosflags(ios::left) << "分钟" << "|"
					<< " " << setw(4) << setiosflags(ios::left) << tick.tic[i].year << "-" << setw(2) << setiosflags(ios::left) << tick.tic[i].month << "-" << setw(3) << setiosflags(ios::left) << tick.tic[i].day << "|"
					<< "   " << setw(2) << setiosflags(ios::left) << tick.tic[i].hour << ":" << setw(4) << setiosflags(ios::left) << tick.tic[i].minute << "|"
					<< "   " << setw(1) << setiosflags(ios::left) << tick.tic[i].num << setw(6) << setiosflags(ios::left) << "号厅" << "|"
					<< " " << setw(2) << setiosflags(ios::left) << seatnum / 10 + 1 << "排" << setw(2) << setiosflags(ios::left) << seatnum % 10 << "号" << "|"
					<< " " << setw(7) << setiosflags(ios::left) << tick.tic[i].seat[m][n] << "|" << endl;
				cout << " ---------------------------------------------------------------------------------------------- " << endl;
				cout << endl;
				cout << "【系统提示】" << tick.tic[i].num << "号厅座位示意图";
				cout << endl;
				for (int m = 0; m < 10; m++)
				{
					cout << endl;
					for (int n = 0; n < 10; n++)
					{
						if (tick.tic[i].seat[m][n] != 0)
						{

							cout << " ■";
						}
						else
						{
							cout << " □";
						}
					}
				}
				cout << endl;
				cout << endl;
				cout << "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n";
				cout << "┃     1.确  认     2.取  消   ┃\t\n";
				cout << "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n";
				int choose = 0;
				cout << "【系统提示】请输入你的选择:";
				cin >> choose;
				switch (choose)
				{
				case 1:cout << endl << "【系统提示】预订成功!" << endl;;
					tick.save();
					cout << "【系统提示】用户" << ph << "订单信息: " << endl;
					cout << " ------------------------------------------------------------------------------------- " << endl;
					cout << setw(22) << setiosflags(ios::left) << "|       影片名称"
						<< setw(9) << setiosflags(ios::left) << "|  类型"
						<< setw(10) << setiosflags(ios::left) << "|   时长"
						<< setw(13) << setiosflags(ios::left) << "|  放映日期"
						<< setw(11) << setiosflags(ios::left) << "| 放映时间"
						<< setw(11) << setiosflags(ios::left) << "| 放映影厅"
						<< setw(10) << setiosflags(ios::left) << "|  座位号" << "|" << endl;
					cout << "|-------------------------------------------------------------------------------------|" << endl;
					cout << "|" << setw(21) << setiosflags(ios::left) << tick.tic[i].name << "|"
						<< " " << setw(7) << setiosflags(ios::left) << tick.tic[i].type << "|"
						<< " " << setw(3) << setiosflags(ios::left) << tick.tic[i].min << setw(5) << setiosflags(ios::left) << "分钟" << "|"
						<< " " << setw(4) << setiosflags(ios::left) << tick.tic[i].year << "-" << setw(2) << setiosflags(ios::left) << tick.tic[i].month << "-" << setw(3) << setiosflags(ios::left) << tick.tic[i].day << "|"
						<< "   " << setw(2) << setiosflags(ios::left) << tick.tic[i].hour << ":" << setw(4) << setiosflags(ios::left) << tick.tic[i].minute << "|"
						<< "   " << setw(1) << setiosflags(ios::left) << tick.tic[i].num << setw(6) << setiosflags(ios::left) << "号厅" << "|"
						<< " " << setw(2) << setiosflags(ios::left) << seatnum / 10 + 1 << "排" << setw(2) << setiosflags(ios::left) << seatnum % 10 << "号" << "|" << endl;
					cout << " ------------------------------------------------------------------------------------- " << endl;
					system("pause");// 任意键继续 
					break;
				case 2:tick.sell(); break;
				}
				return;
			}
			else
			{
				if (tick.tic[i].rest == 0)
				{
					cout << endl << "【系统提示】余票不足,已售罄!";
					cout << endl;
					system("pause");// 任意键继续  
					return;
				}
				else if (tick.tic[i].seat[m][n] != 0)
				{
					cout << endl << "【系统提示】此座位已被预订!";
					cout << endl;
					system("pause");// 任意键继续  
					return;
				}
			}
		}
	}
	if (i == tick.len && k == 0)
	{
		cout << "【系统提示】没有找到您要预定的电影!" << endl;
		system("pause");// 任意键继续  
		return;
	}
}

3.用户取票

运行截图:
图5-3  用户取票界面运行结果

代码如下:

//取票
void ticket::ticketout()
{
	p1.read();//订单信息读取
	string ph;
	int k = 0;//标记匹配次数
	cout << "【系统提示】请输入预定手机号:";
	cin >> ph;
	
	for (int i = 0; i < scount1+1; i++)
	{
		
		if (ph == userdata[i].phone)
		{
			k++;
			int seat = userdata[i].seat;
			cout << endl;
			cout << "【系统提示】用户" << ph << "的订单信息: " << endl;
			cout << " ------------------------------------------------------------------------------------- " << endl;
			cout << setw(22) << setiosflags(ios::left) << "|       影片名称"
				<< setw(9) << setiosflags(ios::left) << "|  类型"
				<< setw(10) << setiosflags(ios::left) << "|   时长"
				<< setw(13) << setiosflags(ios::left) << "|  放映日期"
				<< setw(11) << setiosflags(ios::left) << "| 放映时间"
				<< setw(11) << setiosflags(ios::left) << "| 放映影厅"
				<< setw(10) << setiosflags(ios::left) << "|  座位号" << "|" << endl;
			cout << "|-------------------------------------------------------------------------------------|" << endl;
			cout << "|" << setw(21) << setiosflags(ios::left) << userdata[i].name << "|"
				<< " " << setw(7) << setiosflags(ios::left) << userdata[i].type << "|"
				<< " " << setw(3) << setiosflags(ios::left) << userdata[i].min << setw(5) << setiosflags(ios::left) << "分钟" << "|"
				<< " " << setw(4) << setiosflags(ios::left) << userdata[i].year << "-" << setw(2) << setiosflags(ios::left) << userdata[i].month << "-" << setw(3) << setiosflags(ios::left) << userdata[i].day << "|"
				<< "   " << setw(2) << setiosflags(ios::left) << userdata[i].hour << ":" << setw(4) << setiosflags(ios::left) << userdata[i].minute << "|"
				<< "   " << setw(1) << setiosflags(ios::left) << userdata[i].num << setw(6) << setiosflags(ios::left) << "号厅" << "|"
				<< " " << setw(2) << setiosflags(ios::left) << seat / 10 + 1 << "排" << setw(2) << setiosflags(ios::left) << seat % 10 << "号" << "|" << endl;
			cout << " ------------------------------------------------------------------------------------- " << endl;

			cout << endl;
			cout << "【系统提示】是否打印订单信息 " << endl;
			cout << "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n";
			cout << "┃     1.确  认     2.取  消   ┃\t\n";
			cout << "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n";
			int choose = 0;
			cout << "【系统提示】请输入你的选择:";
			cin >> choose;
			switch (choose)
			{
			case 1:cout << "【系统提示】打印成功! " << endl;
				system("pause");// 任意键继续 
				break;
			case 2:tick.ticketout(); break;
			}
		}
	}
	if (k == 0)
	{
		cout << "【系统提示】未查询到订单信息" << endl;
		system("pause");// 任意键继续 
	}
}

4.用户退票

运行截图:
图5-4  用户退票界面运行结果

代码如下:

//退票
void ticket::refund()
{
	p1.read();//订单信息读取
	string ph;
	int k = 0;//标记匹配次数
	int j = 0;
	int choice = 0;
	cout << "【系统提示】请输入预定手机号:";
	cin >> ph;
	cout << endl;
	for (int i = 0; i < scount1; i++)
	{
		if (ph == userdata[i].phone)
		{
			k++;
			int seat = userdata[i].seat;
			cout << "【系统提示】用户" << ph << "订单信息: " << endl;
			cout << " ------------------------------------------------------------------------------------- " << endl;
			cout << setw(22) << setiosflags(ios::left) << "|       影片名称"
				<< setw(9) << setiosflags(ios::left) << "|  类型"
				<< setw(10) << setiosflags(ios::left) << "|   时长"
				<< setw(13) << setiosflags(ios::left) << "|  放映日期"
				<< setw(11) << setiosflags(ios::left) << "| 放映时间"
				<< setw(11) << setiosflags(ios::left) << "| 放映影厅"
				<< setw(10) << setiosflags(ios::left) << "|  座位号" << "|" << endl;
			cout << "|-------------------------------------------------------------------------------------|" << endl;
			cout << "|" << setw(21) << setiosflags(ios::left) << userdata[i].name << "|"
				<< " " << setw(7) << setiosflags(ios::left) << userdata[i].type << "|"
				<< " " << setw(3) << setiosflags(ios::left) << userdata[i].min << setw(5) << setiosflags(ios::left) << "分钟" << "|"
				<< " " << setw(4) << setiosflags(ios::left) << userdata[i].year << "-" << setw(2) << setiosflags(ios::left) << userdata[i].month << "-" << setw(3) << setiosflags(ios::left) << userdata[i].day << "|"
				<< "   " << setw(2) << setiosflags(ios::left) << userdata[i].hour << ":" << setw(4) << setiosflags(ios::left) << userdata[i].minute << "|"
				<< "   " << setw(1) << setiosflags(ios::left) << userdata[i].num << setw(6) << setiosflags(ios::left) << "号厅" << "|"
				<< " " << setw(2) << setiosflags(ios::left) << seat / 10 + 1 << "排" << setw(2) << setiosflags(ios::left) << seat % 10 << "号" << "|" << endl;
			cout << " ------------------------------------------------------------------------------------- " << endl;

			cout << endl;
			cout << "【系统提示】是否退订当前影票 " << endl;
			cout << "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n";
			cout << "┃     1.确  认     2.取  消   ┃\t\n";
			cout << "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n";
			int choose = 0;
			cout << "【系统提示】请输入你的选择:";
			cin >> choose;
			switch (choose)
			{
			case 1://获取系统时间与已输入时间进行比较
				time_t timep;
				struct tm* p;
				int in_time[5];
				int now_time[5];

				//将输入时间依次赋值给输入时间数组
				in_time[0] = userdata[i].year;//输入时间-年
				in_time[1] = userdata[i].month;//输入时间-月
				in_time[2] = userdata[i].day;//输入时间-日
				in_time[3] = userdata[i].hour;//输入时间-时
				in_time[4] = userdata[i].minute;//输入时间-分

				time(&timep);
				p = gmtime(&timep);

				//将系统时间依次赋值给系统时间数组
				now_time[0] = 1900 + p->tm_year;//系统时间-年
				now_time[1] = 1 + p->tm_mon;//系统时间-月
				now_time[2] = p->tm_mday;//系统时间-日
				now_time[3] = 8 + p->tm_hour;//系统时间-时
				now_time[4] = p->tm_min;//系统时间-分

				//依次比较五项数据

				for (int x = 0; x < 5; x++)
				{
					if (in_time[x] > now_time[x])
					{
						j++;
						cout << endl;
						cout << "【系统提示】订单信息确认: " << endl;
						cout << " ---------------------------------------------------------------------------------------------- " << endl;
						cout << setw(22) << setiosflags(ios::left) << "|       影片名称"
							<< setw(9) << setiosflags(ios::left) << "|  类型"
							<< setw(10) << setiosflags(ios::left) << "|   时长"
							<< setw(13) << setiosflags(ios::left) << "|  放映日期"
							<< setw(11) << setiosflags(ios::left) << "| 放映时间"
							<< setw(11) << setiosflags(ios::left) << "| 放映影厅"
							<< setw(10) << setiosflags(ios::left) << "|  座位号"
							<< setw(9) << setiosflags(ios::left) << "| 返 还" << "|" << endl;
						cout << "|----------------------------------------------------------------------------------------------|" << endl;
						cout << "|" << setw(21) << setiosflags(ios::left) << userdata[i].name << "|"
							<< " " << setw(7) << setiosflags(ios::left) << userdata[i].type << "|"
							<< " " << setw(3) << setiosflags(ios::left) << userdata[i].min << setw(5) << setiosflags(ios::left) << "分钟" << "|"
							<< " " << setw(4) << setiosflags(ios::left) << userdata[i].year << "-" << setw(2) << setiosflags(ios::left) << userdata[i].month << "-" << setw(3) << setiosflags(ios::left) << userdata[i].day << "|"
							<< "   " << setw(2) << setiosflags(ios::left) << userdata[i].hour << ":" << setw(4) << setiosflags(ios::left) << userdata[i].minute << "|"
							<< "   " << setw(1) << setiosflags(ios::left) << userdata[i].num << setw(6) << setiosflags(ios::left) << "号厅" << "|"
							<< " " << setw(2) << setiosflags(ios::left) << seat / 10 + 1 << "排" << setw(2) << setiosflags(ios::left) << seat % 10 << "号" << "|"
							<< " " << setw(7) << setiosflags(ios::left) << userdata[i].price << "|" << endl;
						cout << " ---------------------------------------------------------------------------------------------- " << endl;
						cout << endl;
						break;
					}
					if (in_time[x] < now_time[x])
					{
						break;
					}
				}
				cout << "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n";
				cout << "┃     1.确  认     2.取  消   ┃\t\n";
				cout << "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n";
				cout << "【系统提示】请输入你的选择:";
				cin >> choice;
				switch (choice)
				{
				case 1:for (i = 0; i < scount1; i++)
				{
					if (userdata[i].phone == ph)// 找到
					{
						j++;
						for (int j = i + 1; j < scount1; j++)
						{
							userdata[j - 1] = userdata[j];
						}
						int m, n;
						m = (seat - 1) / 10;//座位号取个位-1
						n = (seat - 1) % 10;//座位号取十位-1
						/*int m = seat / 10;
						int n = seat % 10;*/
						
						tick.tic[i].seat[m][n] = 0;
						tick.tic[i].rest++;
						tick.save();
						cout << "【系统提示】退票成功!" << endl;
						system("pause");//清屏
						scount1--;
						ud.save();
					}
				}
			    break;
				case 2:tick.refund(); break;
				}
				if (j == 0)
				{
					cout << "【系统提示】影片已播放,无法退票! " << endl;
				}
				break;
			case 2:tick.refund(); break;
			}
		}
	}
	if (k == 0)
	{
		cout << "【系统提示】未查询到相关信息 " << endl;
		system("pause");//清屏
	}
}

5.影片录入

运行截图:
图5-5  影片录入运行结果

代码如下:

//录入信息(管理员)
void ticket::input()
{
	tick.read();
	char ch;// 接受日期中的字符": " 
	for (int i = tick.len; i < N; i++)
	{
		cout << "\n【系统提示】影片名称:";
		cin >> tick.tic[i].name;

		cout << "\n【系统提示】影片类型(国语2D):";
		cin >> tick.tic[i].type;

		cout << "\n【系统提示】影片时长(150):";
		cin >> tick.tic[i].min;

		cout << "\n【系统提示】放映日期 (2011-11-11) :";
		cin >> tick.tic[i].year >> ch >> tick.tic[i].month >> ch >> tick.tic[i].day;

		cout << "\n【系统提示】放映时间 (12:30) :";
		cin >> tick.tic[i].hour;
		cin >> ch;
		cin >> tick.tic[i].minute;

		tick.tic[i].datetime[0] = tick.tic[i].year;
		tick.tic[i].datetime[1] = tick.tic[i].month;
		tick.tic[i].datetime[2] = tick.tic[i].day;
		tick.tic[i].datetime[3] = tick.tic[i].hour;
		tick.tic[i].datetime[4] = tick.tic[i].minute;

		cout << "\n【系统提示】放映影厅:";
		cin >> tick.tic[i].num;

		cout << "\n【系统提示】电影票价:";
		cin >> tick.tic[i].price;
		cout << "\n【系统提示】会员价:";
		cin >> tick.tic[i].discount;

		tick.tic[i].rest = 100;

		for (int m = 0; m < 10; m++)
		{
			for (int n = 0; n < 10; n++)
				tick.tic[i].seat[m][n] = 0;
		}

		tick.len++;// 个数加1
		if (i != 0)// 按时间 , 插入排序  
		{
			int j = sort(i);
		}

		tick.save();
		cout << endl;
		cout << "【系统提示】是否继续录入(Y/N):";
		while (1)
		{
			cin >> ch;
			if (ch == 'y' || ch == 'Y' || ch == 'n' || ch == 'N')
				break;
			else
				cout << "【系统提示】输入格式错误,请重新输入:";
		}
		if (ch == 'n' || ch == 'N')
		{
			break;
		}
	}
}

6.影片修改

运行截图:
图5-6  影片修改运行结果

代码如下:

//影片信息修改(管理员)
void ticket::change()
{
	tick.read();//影片信息读取
	string name;
	int i;
	int j = 0;// 标记修改数量  

	cout << "【系统提示】请输入影片名称:";
	cin >> name;
	cout << endl;
	cout << "【系统提示】查询结果如下:" << endl;
	cout << " ----------------------------------------------------------------------------------------------------------- " << endl;
	cout << setw(22) << setiosflags(ios::left) << "|       影片名称"
		<< setw(9) << setiosflags(ios::left) << "|  类型"
		<< setw(10) << setiosflags(ios::left) << "|   时长"
		<< setw(13) << setiosflags(ios::left) << "|  放映日期"
		<< setw(11) << setiosflags(ios::left) << "| 放映时间"
		<< setw(11) << setiosflags(ios::left) << "| 放映影厅"
		<< setw(7) << setiosflags(ios::left) << "| 票价"
		<< setw(9) << setiosflags(ios::left) << "| 会员价"
		<< setw(7) << setiosflags(ios::left) << "| 余票"
		<< setw(9) << setiosflags(ios::left) << "|  状态" << "|" << endl;
	cout << "|-----------------------------------------------------------------------------------------------------------|" << endl;
	for (i = 0; i < tick.len; i++)
	{
		if (tick.tic[i].name == name)// 找到  
		{
			j++;
			cout << "|" << setw(21) << setiosflags(ios::left) << tick.tic[i].name << "|"
				<< " " << setw(7) << setiosflags(ios::left) << tick.tic[i].type << "|"
				<< " " << setw(3) << setiosflags(ios::left) << tick.tic[i].min << setw(5) << setiosflags(ios::left) << "分钟" << "|"
				<< " " << setw(4) << setiosflags(ios::left) << tick.tic[i].year << "-" << setw(2) << setiosflags(ios::left) << tick.tic[i].month << "-" << setw(3) << setiosflags(ios::left) << tick.tic[i].day << "|"
				<< "   " << setw(2) << setiosflags(ios::left) << tick.tic[i].hour << ":" << setw(4) << setiosflags(ios::left) << tick.tic[i].minute << "|"
				<< "   " << setw(1) << setiosflags(ios::left) << tick.tic[i].num << setw(6) << setiosflags(ios::left) << "号厅" << "|"
				<< " " << setw(5) << setiosflags(ios::left) << tick.tic[i].price << "|"
				<< " " << setw(7) << setiosflags(ios::left) << tick.tic[i].discount << "|"
				<< " " << setw(5) << setiosflags(ios::left) << tick.tic[i].rest << "|"
				<< " " << setw(7) << setiosflags(ios::left) << tick.tic[i].action << "|" << endl;
			cout << " ----------------------------------------------------------------------------------------------------------- " << endl;
			char a;
			int choice = -1;

			cout << endl;
			cout << "\t\t\t┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n";
			cout << "\t\t\t┃                                      ┃\t\n";
			cout << "\t\t\t┃   1.修改影片名称   2.修改影片类型    ┃\t\n";
			cout << "\t\t\t┃   3.修改影片时长   4.修改放映日期    ┃\t\n";
			cout << "\t\t\t┃   5.修改放映时间   6.修改放映影厅    ┃\t\n";
			cout << "\t\t\t┃   7.修改影片票价   8.修改会员票价    ┃\t\n";
			cout << "\t\t\t┃                                      ┃\t\n";
			cout << "\t\t\t┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n";
			cout << endl;
			cout << "\t\t\t【系统提示】请输入你的选择(0-7):";
			cin >> choice;

			if (choice < 0 || choice>7)
			{
				cout << "\t\t\t【系统提示】输入格式错误,请重新输入:" << endl;
				cin >> choice;
			}
			char ch;
			switch (choice)
			{
			case 1:cout << "\n【系统提示】影片名称:";
				cin >> tick.tic[i].name;
				break;
			case 2:cout << "\n【系统提示】影片类型(国语2D):";
				cin >> tick.tic[i].type;
				break;
			case 3:cout << "\n【系统提示】影片时长:";
				cin >> tick.tic[i].min;
				break;
			case 4:cout << "\n【系统提示】放映日期(2020-11-11):";
				cin >> tick.tic[i].year >> ch >> tick.tic[i].month >> ch >> tick.tic[i].day;
				tick.tic[i].datetime[0] = tick.tic[i].year;
				tick.tic[i].datetime[1] = tick.tic[i].month;
				tick.tic[i].datetime[2] = tick.tic[i].day; i = sort(i);
				break;
			case 5:cout << "\n【系统提示】放映时间(12:15):";
				cin >> tick.tic[i].hour >> ch >> tick.tic[i].minute;
				tick.tic[i].datetime[3] = tick.tic[i].hour;
				tick.tic[i].datetime[4] = tick.tic[i].minute; i = sort(i);
				break;
			case 6:cout << "\n【系统提示】放映影厅:";
				cin >> tick.tic[i].num;
				break;
			case 7:cout << "\n【系统提示】票价:";
				cin >> tick.tic[i].price;
				break;
			case 8:cout << "\n【系统提示】会员价:";
				cin >> tick.tic[i].discount;
				break;
			case 0:break;
			}
			tick.save();//影片信息保存调用
			cout << endl << "【系统提示】是否继续修改此影片(Y/N): ";
			cin >> a;

			if (a != 'N' && a != 'n');
			{
				cout << endl;
				cout << "【系统提示】影片信息修改成功!" << endl;
				cout << " -------------------------------------------------------------------------------------------------- " << endl;
				cout << setw(22) << setiosflags(ios::left) << "|       影片名称"
					<< setw(9) << setiosflags(ios::left) << "|  类型"
					<< setw(10) << setiosflags(ios::left) << "|   时长"
					<< setw(13) << setiosflags(ios::left) << "|  放映日期"
					<< setw(11) << setiosflags(ios::left) << "| 放映时间"
					<< setw(11) << setiosflags(ios::left) << "| 放映影厅"
					<< setw(7) << setiosflags(ios::left) << "| 票价"
					<< setw(9) << setiosflags(ios::left) << "| 会员价"
					<< setw(7) << setiosflags(ios::left) << "| 余票" << "|" << endl;
				cout << "|--------------------------------------------------------------------------------------------------|" << endl;
				cout << "|" << setw(21) << setiosflags(ios::left) << tick.tic[i].name << "|"
					<< " " << setw(7) << setiosflags(ios::left) << tick.tic[i].type << "|"
					<< " " << setw(3) << setiosflags(ios::left) << tick.tic[i].min << setw(5) << setiosflags(ios::left) << "分钟" << "|"
					<< " " << setw(4) << setiosflags(ios::left) << tick.tic[i].year << "-" << setw(2) << setiosflags(ios::left) << tick.tic[i].month << "-" << setw(3) << setiosflags(ios::left) << tick.tic[i].day << "|"
					<< "   " << setw(2) << setiosflags(ios::left) << tick.tic[i].hour << ":" << setw(4) << setiosflags(ios::left) << tick.tic[i].minute << "|"
					<< "   " << setw(1) << setiosflags(ios::left) << tick.tic[i].num << setw(6) << setiosflags(ios::left) << "号厅" << "|"
					<< " " << setw(5) << setiosflags(ios::left) << tick.tic[i].price << "|"
					<< " " << setw(7) << setiosflags(ios::left) << tick.tic[i].discount << "|"
					<< " " << setw(5) << setiosflags(ios::left) << tick.tic[i].rest << "|" << endl;
				cout << " -------------------------------------------------------------------------------------------------- " << endl;
			}
		}
	}
	if (i == tick.len && j == 0)
	{
		cout << "【系统提示】未查询到相关信息,查询失败!" << endl;
	}
	system("pause");// 任意键继续
}

完整工程文件:
链接:https://pan.baidu.com/s/1vcf2rz3kGYHjjtXn-e0BFg
提取码:ognm
代码小白,仅作学习记录📝

Logo

快速构建 Web 应用程序

更多推荐