飞机票管理系统

飞机票管理系统

功能展示

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

源代码

#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<string.h>
#define max 100
struct ticket {			//票
	char StartPoint[10];//起点
	char Terminus[10];  //终点
	char Time[20];	   //花费的时间
	double money;      //票价
};
//系统
struct System {
	struct ticket ticketinfo[max];//最大个数
	int cursize;				  //当前系统元素个数
};
//初始化数据
struct System* Createtable()
{
	struct System* psystem = (struct System*)malloc(sizeof(struct System));//动态内存申请
	assert(psystem);//断言处理
	psystem->cursize = 0;
	return psystem;
}
//主菜单
void menu()
{
	printf("--------------------【飞机票管理系统】-------------\n");
	printf("\t\t\t0:退出功能\n");
	printf("\t\t\t1:录入信息\n");
	printf("\t\t\t2:浏览信息\n");
	printf("\t\t\t3:查找信息\n");
	printf("\t\t\t4:修改信息\n");
	printf("\t\t\t5:删除信息\n");
	printf("\t\t\t6:排序显示\n");
	printf("------------------------------------------------------\n");
	printf("请输入(0-6):");

}
//录入信息
void Insertdata(struct System* psystem)
{
	int userkey = 0;
	while (1)
	{
		printf("请输入飞机票的信息(StartPoint,Terminus,Time,money):\n");
		printf("--------------例如:北京 广州 7:00-10:00 520\n");
		scanf_s("%s%s%s%lf", psystem->ticketinfo[psystem->cursize].StartPoint,10,
							psystem->ticketinfo[psystem->cursize].Terminus,10,
							psystem->ticketinfo[psystem->cursize].Time,20,
							&psystem->ticketinfo[psystem->cursize].money);
		psystem->cursize++;
		printf("是否继续录入?y继续n不继续:\n");
		while (getchar() != '\n');
		userkey = getchar();
		if (userkey == 'n' || userkey == 'N')
		{
			break;
		}
		while (getchar() != '\n');
	}
	printf("录入成功!\n");
}
//打印数据
void printdata(struct System* psystem)
{
	//打印数组
	printf("起始点\t\t终点站\t\t时间\t\t\t票价/元\n");
	for (int i = 0; i < psystem->cursize; i++)
	{
		printf("%s\t\t%s\t\t%s\t\t%.2lf\n",psystem->ticketinfo[i].StartPoint,
								  psystem->ticketinfo[i].Terminus,
								  psystem->ticketinfo[i].Time,
								  psystem->ticketinfo[i].money);
	}
}
//查找菜单
void searchmenu()
{
	printf("------------------【查找模式】-------\n");
	printf("\t\t0:按初始点查找\n");
	printf("\t\t1:按终点站查找\n");
	printf("\t\t2:按时间查找\n");
	printf("\t\t3:按钱查找\n");
	printf("-------------------------------------\n");
	printf("请输入(0-3):");
}
//查找模块
void searchByStartpoint(struct System* psystem)
{
	char start[10]="";
	printf("请输入要查找的起始点:\n");
	scanf_s("%s", &start,10);
	printf("起始点\t\t终点站\t\t时间\t\t\t票价/元\n");
	int flag = 0;
	for (int i = 0; i < psystem->cursize; i++)
	{
		if (strcmp(start, psystem->ticketinfo[i].StartPoint) == 0)
		{
			printf("%s\t\t%s\t\t%s\t\t%.2lf\n", psystem->ticketinfo[i].StartPoint,
				psystem->ticketinfo[i].Terminus,
				psystem->ticketinfo[i].Time,
				psystem->ticketinfo[i].money);
			flag = 1;
		}
	}
	if (flag == 1)
	{
		printf("查找成功!\n");
	}
	else
		printf("查找失败!\n");
}
void searchByTerminus(struct System* psystem)
{
	char terminus[10]="";
	printf("请输入要查找的终点站:\n");
	scanf_s("%s", &terminus,10);
	printf("起始点\t\t终点站\t\t时间\t\t\t票价/元\n");
	int flag = 0;
	for (int i = 0; i < psystem->cursize; i++)
	{
		if (strcmp(terminus, psystem->ticketinfo[i].Terminus) == 0)
		{
			printf("%s\t\t%s\t\t%s\t\t%.2lf\n", psystem->ticketinfo[i].Terminus,
				psystem->ticketinfo[i].Terminus,
				psystem->ticketinfo[i].Time,
				psystem->ticketinfo[i].money);
			flag = 1;
		}
	}
	if (flag == 1)
	{
		printf("查找成功!\n");
	}
	else
		printf("查找失败!\n");
}
void searchByTime(struct System* psystem)
{
	char time[20]="";
	printf("请输入要查找的时间点:\n");
	scanf_s("%s", &time,20);
	printf("起始点\t\t终点站\t\t时间\t\t\t票价/元\n");
	int flag = 0;
	for (int i = 0; i < psystem->cursize; i++)
	{
		if (strcmp(time, psystem->ticketinfo[i].Time) == 0)
		{
			printf("%s\t\t%s\t\t%s\t\t\t%.2lf\n", psystem->ticketinfo[i].StartPoint,
				psystem->ticketinfo[i].Terminus,
				psystem->ticketinfo[i].Time,
				psystem->ticketinfo[i].money);
			flag = 1;
		}
	}
	if (flag == 1)
	{
		printf("查找成功!\n");
	}
	else
		printf("查找失败!\n");
}
void searchByMoney(struct System* psystem)
{
	double money;
	printf("请输入要查找的钱:\n");
	scanf_s("%lf", &money);
	printf("起始点\t\t终点站\t\t时间\t\t\t票价/元\n");
	int flag = 0;
	for (int i = 0; i < psystem->cursize; i++)
	{
		if (money == psystem->ticketinfo[i].money)
		{
			printf("%s\t\t%s\t\t%s\t\t%.2lf\n", psystem->ticketinfo[i].StartPoint,
				psystem->ticketinfo[i].Terminus,
				psystem->ticketinfo[i].Time,
				psystem->ticketinfo[i].money);
			flag = 1;
		}
	}
	if (flag == 1)
	{
		printf("查找成功!\n");
	}
	else
		printf("查找失败!\n");
}
//查找信息
void serchdata(struct System* psystem)
{
	int userkey = 0;
	while (1)
	{
		searchmenu();
		scanf_s("%d", &userkey);
		switch (userkey)
		{
		case 0:
			searchByStartpoint(psystem);
			break;
		case 1:
			searchByTerminus(psystem);
			break;
		case 2:
			searchByTime(psystem);
			break;
		case 3:
			searchByMoney(psystem);
			break;
		}
		printf("是否继续查找?(n退出y继续)\n");
		while (getchar() != '\n');
		userkey = getchar();
		if (userkey == 'n' || userkey == 'N')
		{
			break;
		}
		system("cls");
	}
}
//修改菜单
void amendmenu()
{
	printf("------------------【修改模式】-------\n");
	printf("\t\t0:按初始点修改\n");
	printf("\t\t1:按终点站修改\n");
	printf("\t\t2:按时间修改\n");
	printf("\t\t3:按钱修改\n");
	printf("-------------------------------------\n");
	printf("请输入(0-3):");
}
//修改模块
void amenddataBystart(struct System* psystem)
{
	int pos = -1;
	char start[10] = "";
	printf("请输入要修改的原起始地点所对应的票的起始地:\n");
	scanf_s("%s", &start, 10);
	for (int i = 0; i < psystem->cursize; i++)
	{
		if (strcmp(start, psystem->ticketinfo[i].StartPoint) == 0)
		{
			pos = i;
			continue;
		}
	}
	if (pos == -1)
	{
		printf("未找到,修改失败!\n");
	}
	else
	{
		printf("请输入飞机票的新信息(StartPoint,Terminus,Time,money):\n");
		printf("--------------例如:北京 广州 7:00-10:00 520\n");
		scanf_s("%s%s%s%lf", 
			psystem->ticketinfo[pos].StartPoint, 10,
			psystem->ticketinfo[pos].Terminus, 10,
			psystem->ticketinfo[pos].Time, 20,
		   &psystem->ticketinfo[pos].money);
		printf("修改成功!\n");
	}
}
void amenddataByTerminus(struct System* psystem)
{
	int pos = -1;
	char Terminus[10] = "";
	printf("请输入要修改的原终点所对应的票的终点城市:\n");
	scanf_s("%s", &Terminus, 10);
	for (int i = 0; i < psystem->cursize; i++)
	{
		if (strcmp(Terminus, psystem->ticketinfo[i].Terminus) == 0)
		{
			pos = i;
			continue;
		}
	}
	if (pos == -1)
	{
		printf("未找到,修改失败!\n");
	}
	else
	{
		printf("请输入飞机票的新信息(StartPoint,Terminus,Time,money):\n");
		printf("--------------例如:北京 广州 7:00-10:00 520\n");
		scanf_s("%s%s%s%lf",
			psystem->ticketinfo[pos].StartPoint, 10,
			psystem->ticketinfo[pos].Terminus, 10,
			psystem->ticketinfo[pos].Time, 20,
			&psystem->ticketinfo[pos].money);
		printf("修改成功!\n");
	}
}
void amenddataBytime(struct System* psystem)
{
	int pos = -1;
	char time[10] = "";
	printf("请输入要修改的原时间点所对应的票的时间:\n");
	scanf_s("%s", &time, 10);
	for (int i = 0; i < psystem->cursize; i++)
	{
		if (strcmp(time, psystem->ticketinfo[i].Time) == 0)
		{
			pos = i;
			continue;
		}
	}
	if (pos == -1)
	{
		printf("未找到,修改失败!\n");
	}
	else
	{
		printf("请输入飞机票的新信息(StartPoint,Terminus,Time,money):\n");
		printf("--------------例如:北京 广州 7:00-10:00 520\n");
		scanf_s("%s%s%s%lf",
			psystem->ticketinfo[pos].StartPoint, 10,
			psystem->ticketinfo[pos].Terminus, 10,
			psystem->ticketinfo[pos].Time, 20,
			&psystem->ticketinfo[pos].money);
		printf("修改成功!\n");
	}
}
void amenddataBymoney(struct System* psystem)
{
	int pos = -1;
	double money=0;
	printf("请输入要修改的原费用所对应的票的费用:\n");
	scanf_s("%lf", &money);
	for (int i = 0; i < psystem->cursize; i++)
	{
		if (money== psystem->ticketinfo[i].money)
		{
			pos = i;
			continue;
		}
	}
	if (pos == -1)
	{
		printf("未找到,修改失败!\n");
	}
	else
	{
		printf("请输入飞机票的新信息(StartPoint,Terminus,Time,money):\n");
		printf("--------------例如:北京 广州 7:00-10:00 520\n");
		scanf_s("%s%s%s%lf",
			psystem->ticketinfo[pos].StartPoint, 10,
			psystem->ticketinfo[pos].Terminus, 10,
			psystem->ticketinfo[pos].Time, 20,
			&psystem->ticketinfo[pos].money);
		printf("修改成功!\n");
	}
}
//修改信息
void amenddata(struct System* psystem)
{
	int userkey = 0;
	while (1)
	{
		amendmenu();
		scanf_s("%d", &userkey);
		switch (userkey)
		{
		case 0:
			amenddataBystart(psystem);
			break;
		case 1:
			amenddataByTerminus(psystem);
			break;
		case 2:
			amenddataBytime(psystem);
			break;
		case 3:
			amenddataBymoney(psystem);
			break;
		}
		printf("是否继续修改?(n退出y继续)\n");
		while (getchar() != '\n');
		userkey = getchar();
		if (userkey == 'n' || userkey == 'N')
		{
			break;
		}
		system("cls");
	}
}
//删除菜单
void deltemenu()
{
	printf("------------------【删除模式】-------\n");
	printf("\t\t0:按初始点删除\n");
	printf("\t\t1:按终点站删除\n");
	printf("\t\t2:按时间删除\n");
	printf("\t\t3:按费用删除\n");
	printf("-------------------------------------\n");
	printf("请输入(0-3):");
}
//删除模块
void deltedataBystart(struct System* psystem)
{
	int pos = -1;
	char start[10] = "";
	printf("请输入要删除的起始地点:\n");
	scanf_s("%s", &start, 10);
	for (int i = 0; i < psystem->cursize; i++)
	{
		if (strcmp(start, psystem->ticketinfo[i].StartPoint) == 0)
		{
			pos = i;
			continue;
		}
	}
	if (pos == -1)
	{
		printf("未找到,删除失败!\n");
	}
	else
	{
		for (int k = 0; k < psystem->cursize; k++)
		{
			psystem->ticketinfo[k] = psystem->ticketinfo[k + 1];
		}
		psystem->cursize--;
		printf("删除成功!\n");
	}
}
void deltedataByTerminus(struct System* psystem)
{
	int pos = -1;
	char Terminus[10] = "";
	printf("请输入要删除的终点:\n");
	scanf_s("%s", &Terminus, 10);
	for (int i = 0; i < psystem->cursize; i++)
	{
		if (strcmp(Terminus, psystem->ticketinfo[i].Terminus) == 0)
		{
			pos = i;
			continue;
		}
	}
	if (pos == -1)
	{
		printf("未找到,删除失败!\n");
	}
	else
	{
		for (int k = 0; k < psystem->cursize; k++)
		{
			psystem->ticketinfo[k] = psystem->ticketinfo[k + 1];
		}
		psystem->cursize--;
		printf("删除成功!\n");
	}
}
void deltedataBytime(struct System* psystem)
{
	int pos = -1;
	char time[20] = "";
	printf("请输入要删除的时间点:\n");
	scanf_s("%s", &time, 10);
	for (int i = 0; i < psystem->cursize; i++)
	{
		if (strcmp(time, psystem->ticketinfo[i].Time) == 0)
		{
			pos = i;
			continue;
		}
	}
	if (pos == -1)
	{
		printf("未找到,删除失败!\n");
	}
	else
	{
		for (int k = 0; k < psystem->cursize; k++)
		{
			psystem->ticketinfo[k] = psystem->ticketinfo[k + 1];
		}
		psystem->cursize--;
		printf("删除成功!\n");
	}
}
void deltedataBymoney(struct System* psystem)
{
	int pos = -1;
	double money=0;
	printf("请输入要删除的费用:\n");
	scanf_s("%lf", &money);
	for (int i = 0; i < psystem->cursize; i++)
	{
		if (money == psystem->ticketinfo[i].money)
		{
			pos = i;
			continue;
		}
	}
	if (pos == -1)
	{
		printf("未找到,删除失败!\n");
	}
	else
	{
		for (int k = 0; k < psystem->cursize; k++)
		{
			psystem->ticketinfo[k] = psystem->ticketinfo[k + 1];
		}
		psystem->cursize--;
		printf("删除成功!\n");
	}
}
//删除信息
void deltedata(struct System* psystem)
{
	int userkey = 0;
	while (1)
	{
		deltemenu();
		scanf_s("%d", &userkey);
		switch (userkey)
		{
		case 0:
			deltedataBystart(psystem);
			break;
		case 1:
			deltedataByTerminus(psystem);
			break;
		case 2:
			deltedataBytime(psystem);
			break;
		case 3:
			deltedataBymoney(psystem);
			break;
		}
		printf("是否继续删除?(n退出y继续)\n");
		while (getchar() != '\n');
		userkey = getchar();
		if (userkey == 'n' || userkey == 'N')
		{
			break;
		}
		system("cls");
	}
}
//排序
void datasortBymoney(struct System* psystem)
{
	for (int i = 0; i < psystem->cursize; i++)
	{
		for (int j = 0; j < psystem->cursize - i - 1; j++)
		{
			if (psystem->ticketinfo[j].money > psystem->ticketinfo[j + 1].money)
			{
				struct ticket temp = psystem->ticketinfo[j];
				psystem->ticketinfo[j] = psystem->ticketinfo[j + 1];
				psystem->ticketinfo[j + 1] = temp;
			}
		}
	}
	printdata(psystem);
}
void Keydown(struct System* psystem)
{
	int userkey;
	scanf_s("%d", &userkey);
	switch (userkey)
	{
	case 0:
		printf("退出成功!\n");
		
		exit(0);
		break;
	case 1:
		//printf("录入信息\n");
		Insertdata(psystem);
		break;
	case 2:
		//printf("浏览信息\n");
		printdata(psystem);
		break;
	case 3:
		//printf("查找信息\n");
		serchdata(psystem);
		break;
	case 4:
		//printf("修改信息\n");
		amenddata(psystem);
		break;
	case 5:
		//printf("删除信息\n");
		deltedata(psystem);
		break;
	case 6:
		//printf("排序信息\n");
		datasortBymoney(psystem);
		break;
	default:
		printf("您的输入有误,请重新输入:");
	}
}
void loging()
{
	char username[20] = { "" };
	char password[20] = { "" };
	printf("用户名:");
	gets_s(username, 20);
	printf("密  码:");
	int key = 0;
	int i = 0;
	while ((key = _getch()) != '\r')
	{
		if (key == '\b')
		{
			printf("\b \b");
			password[i] = '\0';
			i--;
			continue;
		}
		putchar('*');
		password[i++] = key;
	}
	printf("\n");
	if (!strcmp(username, "root") && !strcmp(password, "123456"))
	{
		printf("登录成功!\n");
	}
	else
	{
		printf("登录失败!\n");
		exit(0);
	}
}
int main()
{
	//登录
	loging();

	struct System* psystem = Createtable();//创建系统
	while (1)
	{
		menu();
		Keydown(psystem);
		system("pause");//按任意键继续
		system("cls");  //清屏
	}
	return 0;
}

感言

怎么样?看到这里了,给一个免费的关注和收藏呗,感谢感谢!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

兴趣使然的Qsiri

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值