C语言 航班管理系统(双链表)

1、可实现功能(思维导图一览)

注:普通用户账号:user                        密码:123456

       普通用户账号:admin                      密码:123456

       班期输入格式为:2024 3 20

       航班号唯一,时间为24小时制,输入格式为:17 28

2.fly.h代码

#define _CRT_SECURE_NO_WARNINGS 1
#ifndef _FLY_H_
#define _FLY_H

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <conio.h>

// 班期信息结构体
struct schedule
{
	int year; 
	int moth;
	int day;
};

// 时间信息结构体
struct time
{
	int hours;
	int min;
};

// 航班信息结构体
typedef struct flight_new
{
	char number[10]; // 航班号
	char staddress[10]; // 起点站
	char arraddress[10]; // 终点站
	struct schedule data; // 班期
	char type[10]; // 机型
	struct time stime; // 起飞时间
	struct time atime; // 达到时间
	float price; // 票价
}flight_new;

// 航班管理结构体(节点信息)
typedef struct flight
{
	flight_new datas; // 航班的信息数据
	struct flight* prev; //记录前驱的地址
	struct flight* next; //记录后继的地址
}flight;

// 管理结构体(头结点)
typedef struct headnode
{
	int numbers;    //记录有多少条信息
	flight* head;     //记录首结点的地址
	flight* tail;     //记录尾结点的地址
}headnode;

/* 
* brief: 初始化航班信息链表头节点信息
* param: None
* return: the type is struct headnode*
*/ 
struct headnode* flight_create_headnode();

/*
* brief: 初始化航班信息(新节点)
* param: the type is struct flight_new
* return: the type is struct flight*
*/
struct flight* flight_create_node(struct flight_new fly);

/*
* brief: 将新航班信息尾插到链表(创建链表)
* param: the type is struct headnode*
* return: 成功返回:ture 失败返回:false
*/
bool flight_addtailnode(headnode* head_node);

/*
* brief: 根据航班号删除信息
* param: the type is struct headnode*
* return: 成功返回:ture 失败返回:false
*/
bool flight_delnode(headnode* head_node);

/*
* brief: 根据航班号查找航班信息
* param: the type is struct headnode*
* return: 成功返回:ture 失败返回:false
*/
bool flight_findnumber(headnode* head_node);

/*
* brief: 航班信息修改系统
* param: the type is struct headnode*
* return: None
*/
void flight_modify(headnode* head_node);

/*
* brief: 根据航班号修改票价
* param: the type is struct headnode*
* return: 成功返回:ture 失败返回:false
*/
bool flight_modify_price(headnode* head_node);

/*
* brief: 根据航班号修改起点站
* param: the type is struct headnode*
* return: 成功返回:ture 失败返回:false
*/
bool flight_modify_staddress(headnode* head_node);

/*
* brief: 根据航班号修改终点站
* param: the type is struct headnode*
* return: 成功返回:ture 失败返回:false
*/
bool flight_modify_arraddress(headnode* head_node);

/*
* brief: 打印所有航班信息
* param: the type is struct headnode*
* return: 成功返回:ture 失败返回:false
*/
bool flight_print(headnode* head_node);

/*
* brief: 系统界面(管理员)
* param: None
* return: None
*/
void flight_mean_admin();

/*
* brief: 修改系统界面(管理员)
* param: None
* return: None
*/
void flight_Modify_mean();

/*
* brief: 航班信息管理系统(管理员)
* param: the type is struct headnode*
* return: None
*/
void flight_manage_admin(headnode* head_node);

/*
* brief: 航班系统登录界面
* param: None
* return: None
*/
void flight_login_mean();

/*
* brief: 管理员登录系统
* param: the type is struct headnode*
* return: None
*/
void flight_login_admin(headnode* head_node);

/*
* brief: 系统界面(普通用户)
* param: None
* return: None
*/
void flight_mean_user();

/*
* brief: 普通用户登录系统
* param: the type is struct headnode*
* return: None
*/
void flight_login_user(headnode* head_node);

/*
* brief: 航班信息管理系统(普通用户)
* param: the type is struct headnode*
* return: None
*/
void flight_manage_user(headnode* head_node);

/*
* brief: 根据起点站查询航班信息
* param: the type is struct headnode*
* return: None
*/
void flight_findstaddress(headnode* head_node);

/*
* brief: 查询系统界面(管理员)
* param: None
* return: None
*/
void flight_find_mean();

/*
* brief: 根据终点站查询航班信息
* param: the type is struct headnode*
* return: None
*/
void flight_findarraddress(headnode* head_node);

/*
* brief: 根据机型查询航班信息
* param: the type is struct headnode*
* return: None
*/
void flight_findtype(headnode* head_node);

#endif

3、fly.c代码

#include "fly.h"

// 初始化航班信息链表头节点信息
struct headnode* flight_create_headnode()
{
	// 为头节点申请空间
	struct headnode* head_node = malloc(sizeof(headnode));
	if (head_node == NULL)
		return NULL;

	// 初始化头节点
	head_node->numbers = 0;
	head_node->head = NULL;
	head_node->tail = NULL;

	return head_node;
}

//------------------------------

// 初始化航班信息(新节点)
struct flight* flight_create_node(struct flight_new fly)
{
	// 为新节点申请空间
	struct flight* new_node = malloc(sizeof(flight));
	if (new_node == NULL)
		return NULL;

	// 初始化航班信息
	strcpy(new_node->datas.number, fly.number);
	strcpy(new_node->datas.staddress, fly.staddress);
	strcpy(new_node->datas.arraddress, fly.arraddress);
	strcpy(new_node->datas.type, fly.type);

	new_node->datas.data.year = fly.data.year;
	new_node->datas.data.moth = fly.data.moth;
	new_node->datas.data.day = fly.data.day;

	new_node->datas.stime.hours = fly.stime.hours;
	new_node->datas.stime.min = fly.stime.min;

	new_node->datas.atime.hours = fly.atime.hours;
	new_node->datas.atime.min = fly.atime.min;

	new_node->datas.price = fly.price;

	new_node->prev = NULL;
	new_node->next = NULL;

	return new_node;
}

//------------------------------

// 将新航班信息尾插到链表(创建链表)
bool flight_addtailnode(headnode*head_node)
{
	flight_new fly; // 创建新的航班信息

	printf("请录入航班号\t");
	scanf("%s", fly.number);

	struct flight* p = head_node->head;

	// 遍历查找航班号是否重复添加
	while (p)
	{
		if (strcmp(p->datas.number, fly.number) == 0) 
		{
			printf("航班号重复,无法录入信息!\n");
			return false;
		}
		else
			p = p->next;
	}

	printf("请录入起点站\t");
	scanf("%s", fly.staddress);
	printf("请录入终点站\t");
	scanf("%s", fly.arraddress);
	printf("请录入班期\t");
	scanf("%d%d%d", &fly.data.year, &fly.data.moth, &fly.data.day);
	printf("请录入机型\t");
	scanf("%s", fly.type);
	printf("请录入起飞时间\t");
	scanf("%d%d", &fly.stime.hours, &fly.stime.min);
	printf("请录入到达时间\t");
	scanf("%d%d", &fly.atime.hours, &fly.atime.min);
	printf("请录入票价\t");
	scanf("%f", &fly.price);

	struct flight* new_node = flight_create_node(fly);

	if (new_node == NULL)
		return false;

	if (head_node->head == NULL) // 头节点为空时,直接将头尾节点指向新节点
	{
		head_node->head = new_node;
		head_node->tail = new_node;
		new_node->prev = head_node->head;
	}
	else // 尾插
	{
		new_node->prev = head_node->tail;
		head_node->tail->next = new_node;
		head_node->tail = new_node;
	}
	head_node->numbers++;
	printf("录入成功\n");

	return true;
}

//------------------------------

// 根据航班号删除信息
bool flight_delnode(headnode* head_node)
{
	struct flight* p = head_node->head;

	char number[10]; // 航班号
	printf("请输入要删除的航班信息的航班号:");
	scanf("%s", number);

	// 遍历查找指定航班号
	while (p)
	{
		if (strcmp(p->datas.number, number) == 0)
			break;
		else 
			p = p->next;
	}

	if (p == NULL)
	{
		printf("暂无匹配的航班信息,删除失败!\n");
		return false;
	}

	if (head_node->head == p) // 首节点
	{
		head_node->head = p->next;

		p->next = NULL;
		p->prev = NULL;
		free(p);
	}
	else if (head_node->tail == p) // 尾节点
	{
		head_node->tail = p->prev;

		p->prev->next = NULL;
		p->prev = NULL;
		free(p);
	}
	else // 中间节点
	{ 
		p->prev->next = p->next;
		p->next->prev = p->prev;
		p->next = NULL;
		p->prev = NULL;
		free(p);
	}
	head_node->numbers--;

	printf("航班信息删除成功\n");
	
	return true;
}

//------------------------------

// 根据航班号查找航班信息
bool flight_findnumber(headnode* head_node)
{
	char number[10]; // 航班号
	printf("请输入要查询的航班信息的航班号:");
	scanf("%s", number);

	struct flight* p = head_node->head;

	// 遍历查找指定航班号
	while (p)
	{
		if (strcmp(p->datas.number, number) == 0)
			break;
		else
			p = p->next;
	}

	if (p == NULL)
	{
		printf("暂无匹配的航班信息,查找失败!\n");
		return false;
	}
	printf("number\taddress\t                data\t        time\t                    price\t    type\n");
	printf("%s\t%-8s --> %-8s   %-4d.%-2d.%-2d      %02d:%02d -- %02d:%02d      $%-5.2f         %s\n",
		p->datas.number, p->datas.staddress, p->datas.arraddress, p->datas.data.year, p->datas.data.moth, p->datas.data.day,
		p->datas.stime.hours, p->datas.stime.min, p->datas.atime.hours, p->datas.atime.min, p->datas.price, p->datas.type);
	return true;
}

//------------------------------

// 根据航班号修改票价
bool flight_modify_price(headnode* head_node)
{
	char number[10]; // 航班号
	float newprice; // 票价

	printf("请输入要修改票价的航班号:");
	scanf("%s", number);

	struct flight* p = head_node->head;

	// 遍历查找指定航班号
	while (p)
	{
		if (strcmp(p->datas.number, number) == 0)
			break;
		else
			p = p->next;
	}

	if (p == NULL)
	{
		printf("暂无匹配的航班信息,票价修改失败!\n");
		return false;
	}

	printf("更新票价为:");
	scanf("%f", &newprice);

	p->datas.price = newprice; // 修改票价

	printf("%s次航班票价修改成功\n", p->datas.number);
	printf("number\taddress\t                data\t        time\t            price\t    type\n");
	printf("%s\t%-8s --> %-8s   %-4d.%-2d.%-2d      %02d:%02d -- %02d:%02d      $%-5.2f         %s\n",
		p->datas.number, p->datas.staddress, p->datas.arraddress, p->datas.data.year, p->datas.data.moth, p->datas.data.day,
		p->datas.stime.hours, p->datas.stime.min, p->datas.atime.hours, p->datas.atime.min, p->datas.price, p->datas.type);

	return true;
}

//------------------------------

// 根据航班号修改起点站
bool flight_modify_staddress(headnode* head_node) 
{
	char number[10]; // 航班号
	char newstaddress[10]; // 起点站

	printf("请输入要修改起点站的航班号:");
	scanf("%s", number);

	struct flight* p = head_node->head;

	// 遍历查找指定航班号
	while (p)
	{
		if (strcmp(p->datas.number, number) == 0)
			break;
		else
			p = p->next;
	}

	if (p == NULL)
	{
		printf("暂无匹配的航班信息,起点站修改失败!\n");
		return false;
	}

	printf("更新起点站为:");
	scanf("%s", newstaddress);

	strcpy(p->datas.staddress, newstaddress); // 修改起点站

	printf("%s次航班起点站修改成功\n", p->datas.number);
	printf("number\taddress\t                data\t        time\t            price\t    type\n");
	printf("%s\t%-8s --> %-8s   %-4d.%-2d.%-2d      %02d:%02d -- %02d:%02d      $%-5.2f         %s\n",
		p->datas.number, p->datas.staddress, p->datas.arraddress, p->datas.data.year, p->datas.data.moth, p->datas.data.day,
		p->datas.stime.hours, p->datas.stime.min, p->datas.atime.hours, p->datas.atime.min, p->datas.price, p->datas.type);

	return true;
}

//------------------------------

// 根据航班号修改终点站
bool flight_modify_arraddress(headnode* head_node)
{
	char number[10]; // 航班号
	char newarraddress[10]; // 终点站

	printf("请输入需要修改终点站的航班号:");
	scanf("%s", number);

	struct flight* p = head_node->head;

	// 遍历查找指定航班号
	while (p)
	{
		if (strcmp(p->datas.number, number) == 0)
			break;
		else
			p = p->next;
	}

	if (p == NULL)
	{
		printf("暂无匹配的航班信息,终点站修改失败!\n");
		return false;
	}

	printf("更新终点站为:");
	scanf("%s", newarraddress);

	strcpy(p->datas.arraddress, newarraddress); // 修改终点站

	printf("%s次航班终点站修改成功\n", p->datas.number);
	printf("number\taddress\t                data\t        time\t            price\t    type\n");
	printf("%s\t%-8s --> %-8s   %-4d.%-2d.%-2d      %02d:%02d -- %02d:%02d      $%-5.2f         %s\n",
		p->datas.number, p->datas.staddress, p->datas.arraddress, p->datas.data.year, p->datas.data.moth, p->datas.data.day,
		p->datas.stime.hours, p->datas.stime.min, p->datas.atime.hours, p->datas.atime.min, p->datas.price, p->datas.type);

	return true;
}

//------------------------------

// 根据航班号修改机型
bool flight_modify_type(headnode* head_node)
{
	char number[10]; // 航班号
	char newtype[10]; // 机型

	printf("请输入需要修改机型的航班号:");
	scanf("%s", number);

	struct flight* p = head_node->head;

	// 遍历查找指定航班号
	while (p)
	{
		if (strcmp(p->datas.number, number) == 0)
			break;
		else
			p = p->next;
	}

	if (p == NULL)
	{
		printf("暂无匹配的航班信息,机型修改失败!\n");
		return false;
	}

	printf("更新机型为:");
	scanf("%s", newtype);

	strcpy(p->datas.type, newtype); // 修改机型

	printf("%s次航班机型修改成功\n", p->datas.number);
	printf("number\taddress\t                data\t        time\t            price\t    type\n");
	printf("%s\t%-8s --> %-8s   %-4d.%-2d.%-2d      %02d:%02d -- %02d:%02d      $%-5.2f         %s\n",
		p->datas.number, p->datas.staddress, p->datas.arraddress, p->datas.data.year, p->datas.data.moth, p->datas.data.day,
		p->datas.stime.hours, p->datas.stime.min, p->datas.atime.hours, p->datas.atime.min, p->datas.price, p->datas.type);

	return true;
}

//------------------------------

// 打印所有航班信息
bool flight_print(headnode* head_node)
{
	struct flight* p = head_node->head;
	int n = head_node->numbers;

	if (p == NULL)
	{
		printf("当前暂无航班信息!\n");
		return false;
	}
	printf("number\taddress\t                data\t        time\t            price\t    type\n");
	while (p)
	{
		printf("%s\t%-8s --> %-8s   %-4d.%-2d.%-2d      %02d:%02d -- %02d:%02d      $%-5.2f         %s\n",
			p->datas.number, p->datas.staddress, p->datas.arraddress, p->datas.data.year, p->datas.data.moth, p->datas.data.day,
			p->datas.stime.hours, p->datas.stime.min, p->datas.atime.hours, p->datas.atime.min, p->datas.price, p->datas.type);
		p = p->next;
	}
	return true;
}

//------------------------------

// 系统界面(管理员)
void flight_mean_admin()
{
	printf("=================================================\n");
	printf("**               航班信息管理系统              **\n");
	printf("*************************************************\n");
	printf("**                1.录入航班信息               **\n");
	printf("**                2.删除航班信息               **\n");
	printf("**                3.修改航班信息               **\n");
	printf("**                4.查询航班信息               **\n");
	printf("**                5.显示所有航班信息           **\n");
	printf("**                0.退出管理系统               **\n");
	printf("=================================================\n");
	printf("注:航班号唯一\t\t时间显示为24小时制\n");
}

//------------------------------

// 修改系统界面(管理员)
void flight_Modify_mean()
{
	printf("=================================================\n");
	printf("**               航班信息修改系统              **\n");
	printf("*************************************************\n");
	printf("**                1.修改航班起点站             **\n");
	printf("**                2.修改航班终点站             **\n");
	printf("**                3.修改航班票价               **\n");
	printf("**                4.修改航班机型               **\n");
	printf("**                0.退出修改系统               **\n");
	printf("=================================================\n");
	printf("注:航班号唯一\t\t时间显示为24小时制\n");
}

//------------------------------

// 查询系统(管理员)
void flight_find_mean()
{
	printf("=================================================\n");
	printf("**               航班信息查询系统              **\n");
	printf("*************************************************\n");
	printf("**                1.航班起点站查询             **\n");
	printf("**                2.航班终点站查询             **\n");
	printf("**                3.航班号查询                 **\n");
	printf("**                4.航班机型查询               **\n");
	printf("**                0.退出查询系统               **\n");
	printf("=================================================\n");
	printf("注:航班号唯一\t\t时间显示为24小时制\n");
}

//------------------------------

// 航班信息查询系统
void flight_find(headnode* head_node)
{
	flight_find_mean();
	int input;
	printf("请根据对应序号选择需要查询的信息:");
	scanf("%d", &input);
	switch (input)
	{
	case 0:
		printf("已退出航班信息查询系统\n");
		return 0;
	case 1:
		flight_findstaddress(head_node); // 根据起点站查询航班信息
		break;
	case 2:
		flight_findarraddress(head_node); // 根据终点站查询航班信息
		break;
	case 3:
		flight_findnumber(head_node); // 根据航班号查询航班信息
		break;
	case 4:
		flight_findtype(head_node); // 根据机型查询航班信息
		break;
	default:
		printf("输入错误,请重新输入\n");
		break;
	}
}

//------------------------------

// 航班信息修改系统
void flight_modify(headnode* head_node) 
{
	flight_Modify_mean();
	int input;
	printf("请根据对应序号选择需要修改的信息:");
	scanf("%d", &input);
	switch (input)
	{
	case 0:
		printf("已退出航班信息修改系统\n");
		return 0;
	case 1:
		flight_modify_staddress(head_node); // 根据航班号修改起点站
		break;
	case 2:
		flight_modify_arraddress(head_node); // 根据航班号修改终点站
		break;
	case 3:
		flight_modify_price(head_node); // 根据航班号修改票价
		break;
	case 4:
		flight_modify_type(head_node); // 根据航班号修改机型
		break;
	default:
		printf("输入错误,请重新输入\n");
		break;
	}
}

//------------------------------

// 航班信息管理系统(管理员)
void flight_manage_admin(headnode* head_node)
{
	while (1)
	{
		flight_mean_admin();
		int input;
		printf("请根据对应序号选择功能:");
		scanf("%d", &input);
		switch (input)
		{
		case 0:
			printf("已退出登录系统\n");
			return 0;
		case 1:
			flight_addtailnode(head_node); // 录入航班信息
			break;
		case 2:
			flight_delnode(head_node); // 根据航班号删除信息
			break;
		case 3:
			flight_modify(head_node); // 修改航班信息
			break;
		case 4:
			flight_find(head_node); // 查找航班信息
			break;
		case 5:
			flight_print(head_node); // 打印航班信息
			break;
		default:
			printf("输入错误,请重新输入\n");
			break;
		}
	}
}

//------------------------------

// 航班系统登录界面
void flight_login_mean()
{
	printf("=================================================\n");
	printf("**               航班系统登录界面              **\n");
	printf("*************************************************\n");
	printf("**                1.普通用户登录               **\n");
	printf("**                2.管理员登录                 **\n");
	printf("**                0.退出登录系统               **\n");
	printf("=================================================\n");
}

//------------------------------

// 管理员登录系统
void flight_login_admin(headnode* head_node)
{
	char username[20]; // 用户名
	char password[20] = { 0 }; // 密码
	int flag = 0; // 登录次数

	while (1)
	{

		printf("请输入用户名:\t");
		scanf("%s", username);

		int i = 0; //记录密码长度
		char c; //用于实现密码隐式输入
		printf("请输入密码:\t");
		while (1)
		{
			c = _getch(); //用 _getch() 函数输入,字符不会显示在屏幕上
			if (c == '\r') //遇到回车,表明密码输入结束
			{
				break; //while 循环的出口
			}
			else if (c == '\b') //遇到退格,需要删除前一个星号
			{
				printf("\b \b");  //退格,打一个空格,再退格,实质上是用空格覆盖掉星号
				--i;
			}
			else
			{
				password[i++] = c;//将字符放入数组
				printf("*");
			}	
		}
		printf("\n");

		if (strcmp(username, "admin") == 0 && strcmp(password, "123456") == 0)
		{
			printf("管理员登录成功\n");
			flight_manage_admin(head_node);
			break;
		}
		else
		{
			printf("用户名或密码错误,请重新输入用户名或密码\n");
			flag++;
			if (flag == 3)
			{
				printf("登录失败,退出系统\n");
				break;
			}
		}
	}
}

//------------------------------

// 系统界面(普通用户)
void flight_mean_user()
{
	printf("=================================================\n");
	printf("**               航班信息查询系统              **\n");
	printf("*************************************************\n");
	printf("**                1.查询航班信息               **\n");
	printf("**                2.显示航班信息               **\n");
	printf("**                0.退出查询系统               **\n");
	printf("=================================================\n");
	printf("注:航班号唯一\t\t时间显示为24小时制\n");
}

//------------------------------

// 普通用户登录系统
void flight_login_user(headnode* head_node)
{
	char username[20]; // 用户名
	char password[20] = { 0 };// 密码
	int flag = 0; // 登录次数

	while (1)
	{
		printf("请输入用户名:\t");
		scanf("%s", username);

		int i = 0; //记录密码长度
		char c; //用于实现密码隐式输入
		printf("请输入密码:\t");
		while (1) {
			c = _getch(); //用 _getch() 函数输入,字符不会显示在屏幕上
			if (c == '\r') //遇到回车,表明密码输入结束
			{ 
				break; //while 循环的出口
			}
			else if (c == '\b') //遇到退格,需要删除前一个星号
			{ 
				printf("\b \b");  //退格,打一个空格,再退格,实质上是用空格覆盖掉星号
				--i;
			}
			else 
			{
				password[i++] = c;//将字符放入数组
				printf("*");
			}	
		}
		printf("\n");

		if (strcmp(username, "user") == 0 && strcmp(password, "123456") == 0)
		{
			printf("用户登录成功\n");
			flight_manage_user(head_node);
			break;
		}
		else
		{
			printf("用户名或密码错误,请重新输入用户名或密码\n");
			flag++;
			if (flag == 3)
			{
				printf("登录失败,退出系统\n");
				break;
			}
		}
	}
}

//------------------------------

// 根据起点站查询航班信息
void flight_findstaddress(headnode* head_node)
{
	struct flight* p = head_node->head;
	char staddress[10]; // 起点站
	int flag = 0;
	printf("请输入需要查询的起点站:");
	scanf("%s", staddress);
	
	printf("number\taddress\t                data\t        time\t            price\t    type\n");

	// 遍历查找指定起点站
	for (p; p != NULL; p = p->next) 
	{
		if (strcmp(p->datas.staddress, staddress) == 0)
		{
			printf("%s\t%-8s --> %-8s   %-4d.%-2d.%-2d      %02d:%02d -- %02d:%02d      $%-5.2f         %s\n",
				p->datas.number, p->datas.staddress, p->datas.arraddress, p->datas.data.year, p->datas.data.moth, p->datas.data.day,
				p->datas.stime.hours, p->datas.stime.min, p->datas.atime.hours, p->datas.atime.min, p->datas.price, p->datas.type);
			flag++;
		}
	}

	if (flag == 0) 
	{
		printf("暂无匹配的航班信息,查找失败!\n");
		return false;
	}

	return true;
}

//------------------------------

// 根据终点站查询航班信息
void flight_findarraddress(headnode* head_node)
{
	struct flight* p = head_node->head;
	char arraddress[10]; // 终点站
	int flag = 0;
	printf("请输入需要查询的终点站:");
	scanf("%s", arraddress);

	printf("number\taddress\t                data\t        time\t            price\t    type\n");

	// 遍历查找指定终点站
	for (p; p != NULL; p = p->next)
	{
		if (strcmp(p->datas.arraddress, arraddress) == 0)
		{
			printf("%s\t%-8s --> %-8s   %-4d.%-2d.%-2d      %02d:%02d -- %02d:%02d      $%-5.2f         %s\n",
				p->datas.number, p->datas.staddress, p->datas.arraddress, p->datas.data.year, p->datas.data.moth, p->datas.data.day,
				p->datas.stime.hours, p->datas.stime.min, p->datas.atime.hours, p->datas.atime.min, p->datas.price, p->datas.type);
			flag++;
		}
	}

	if (flag == 0)
	{
		printf("暂无匹配的航班信息,查找失败!\n");
		return false;
	}

	return true;
}

//------------------------------

// 根据机型查询航班信息
void flight_findtype(headnode* head_node)
{
	struct flight* p = head_node->head;
	char type[10]; // 机型
	int flag = 0;
	printf("请输入需要查询的机型:");
	scanf("%s", type);

	printf("number\taddress\t                data\t        time\t            price\t    type\n");

	// 遍历查找指定机型
	for (p; p != NULL; p = p->next) 
	{
		if (strcmp(p->datas.type, type) == 0)
		{
			printf("%s\t%-8s --> %-8s   %-4d.%-2d.%-2d      %02d:%02d -- %02d:%02d      $%-5.2f         %s\n",
				p->datas.number, p->datas.staddress, p->datas.arraddress, p->datas.data.year, p->datas.data.moth, p->datas.data.day,
				p->datas.stime.hours, p->datas.stime.min, p->datas.atime.hours, p->datas.atime.min, p->datas.price, p->datas.type);
			flag++;
		}
	}

	if (flag == 0)
	{
		printf("暂无匹配的航班信息,查找失败!\n");
		return false;
	}

	return true;
}

//------------------------------

// 航班信息管理系统(普通用户)
void flight_manage_user(headnode* head_node)
{
	while (1)
	{
		flight_mean_user();
		int input;
		printf("请根据对应序号选择功能:");
		scanf("%d", &input);
		switch (input)
		{
		case 0:
			printf("已退出查询系统\n");
			return 0;
		case 1:
			flight_find(head_node); // 查找航班信息
			break;
		case 2:
			flight_print(head_node); // 打印航班信息
			break;
		default:
			printf("输入错误,请重新输入\n");
			break;
		}
	}
}

4.main.c代码

#include "fly.h"

int main()
{
	headnode* head_node = flight_create_headnode();
	
	while (1) 
	{
		flight_login_mean();
		int input;
		printf("请根据对应序号选择功能:");
		scanf("%d", &input);

		switch (input)
		{
		case 0:
			printf("已退出航班系统\n");
			return 0;
		case 1:
			flight_login_user(head_node);
			break;
		case 2:
			flight_login_admin(head_node);
			break;
		default:
			printf("输入错误,请重新输入\n");
			continue;
		}
	}
	return 0;
}

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
好的,下面是一个简单的C语言双向链表实现图书管理系统的示例代码: ``` #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct Book { char name[50]; char author[50]; int year; struct Book *prev; struct Book *next; } Book; Book *head = NULL; Book *tail = NULL; void addBook(char name[], char author[], int year) { Book *newBook = (Book*) malloc(sizeof(Book)); strcpy(newBook->name, name); strcpy(newBook->author, author); newBook->year = year; newBook->prev = tail; newBook->next = NULL; if (head == NULL) { head = newBook; } else { tail->next = newBook; } tail = newBook; } void removeBook(char name[]) { Book *current = head; while (current != NULL) { if (strcmp(current->name, name) == 0) { if (current == head) { head = current->next; } else { current->prev->next = current->next; } if (current == tail) { tail = current->prev; } else { current->next->prev = current->prev; } free(current); return; } current = current->next; } printf("Book not found.\n"); } void displayBooks() { Book *current = head; while (current != NULL) { printf("Name: %s\n", current->name); printf("Author: %s\n", current->author); printf("Year: %d\n", current->year); printf("\n"); current = current->next; } } int main() { addBook("The Great Gatsby", "F. Scott Fitzgerald", 1925); addBook("To Kill a Mockingbird", "Harper Lee", 1960); addBook("1984", "George Orwell", 1949); displayBooks(); removeBook("To Kill a Mockingbird"); displayBooks(); return 0; } ``` 这段代码实现了三个主要的操作:添加书籍、删除书籍和显示所有书籍。每本书都被表示为一个 `Book` 结构体,其中包含书名、作者、出版年份和指向前一本书和后一本书的指针。`addBook` 函数将新书添加到链表的末尾,`removeBook` 函数从链表中删除指定的书籍,`displayBooks` 函数遍历整个链表并打印每本书的信息。 你可以根据需要修改这段代码以适应自己的需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值