c语言航班管理系统,普通用户录入,查询,排序你,登录,注册,管理员用户可以增删改查,排序。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char user_id[10] = {0};
char user_pw[10] = {0};
char F_name[10];
char F_start[10];
char F_bourn[10];
char F_schedule[10];
char F_s_votes[10];
char F_price[5];
typedef struct flight
{
char name[10];
char start[10];
char bourn[10];
char f_schedule[10];
char spare_votes[10];
char price[5];
struct flight *next;
}flight;
typedef struct node
{
flight data;
struct node *next;
}Node;
flight *creat_list()
{
flight *Head=malloc(sizeof(flight));
if(NULL!=Head)
Head->next=NULL;
else
printf("\n开辟内存失败\n");
return Head;
}
Node *create_list()
{
Node *Head=malloc(sizeof(Node));
if(NULL!=Head)
Head->next=NULL;
else
printf("\n开辟内存失败\n");
return Head;
}
Node *get_newNode(Node *user)
{
Node *newNode=malloc(sizeof(Node));
if(NULL!=newNode)
{
printf("请输入要增加的航班名称: \t");
scanf("%s", F_name);
strcpy(newNode->data.name, F_name);
printf("请输入该航班的起始点: \t");
scanf("%s", F_start);
strcpy(newNode -> data.start, F_start);
printf("请输入该航班的目的地: \t");
scanf("%s", F_bourn);
strcpy(newNode -> data.bourn, F_bourn);
printf("请输入该航班的航班时间:\t");
scanf("%s", F_schedule);
strcpy(newNode -> data.f_schedule, F_schedule);
printf("请输入该航班的价格: \t");
scanf("%s", F_price);
strcpy(newNode -> data.price, F_price);
printf("请输入该航班的剩余票数: \t");
scanf("%s", F_s_votes);
strcpy(newNode -> data.spare_votes, F_s_votes);
printf("\n");
newNode->next=NULL;
return newNode;
}
else
{
printf("\n开辟内存失败\n");
return 0;
}
}
void *print_List(Node *user)
{
Node *p;
p=user->next;
if(p==NULL)
printf("暂无航班!\n");
else
{
int i =0;
while(NULL!=p)
{
printf("航班的名称\t航班的起始点\t航班的目的地\t航班的航班时间\t航班的剩余票数\t航班的价格\n");
printf("%s\t\t%s\t\t%s\t\t%s\t\t%s\t\t%s\n",p -> data.name,p -> data.start,p -> data.bourn,
p -> data.f_schedule,p -> data.spare_votes,p -> data.price);
printf("\n");
i++;
p=p->next;
}
printf("共有%d个航班!\n",i);
}
}
void *print_List1(Node *user1)
{
Node *p;
p=user1->next;
if(p==NULL)
printf("暂无航班!\n");
else
{
int i =0;
while(NULL!=p)
{
printf("航班的名称\t航班的起始点\t航班的目的地\t航班的航班时间\t航班的剩余票数\t航班的价格\n");
printf("%s\t\t%s\t\t%s\t\t%s\t\t%s\t\t%s\n",p -> data.name,p -> data.start,p -> data.bourn,
p -> data.f_schedule,p -> data.spare_votes,p -> data.price);
printf("\n");
i++;
p=p->next;
}
printf("共有%d个航班!\n",i);
}
}
Node *bubble(Node *user1)
{
for (Node *p1 = user1;p1->next != NULL;p1 = p1->next)
{
for (Node *p2 = user1;p2->next !=NULL;p2 = p2->next)
{
if (strcmp(p2->data.f_schedule,p2->next->data.f_schedule)<0)
{
flight temp=p2->data;
p2->data = p2->next->data;
p2->next->data = temp;
}
}
}
print_List1(user1);
}
void addflight(Node *user)
{
int flag;
printf("请输入要增加的航班数:");
scanf("%d",&flag);
while(flag)
{
char s[2];
int ch;
Node *tail;
tail=user;
while(NULL!=tail->next)
tail = tail->next;
tail->next = get_newNode(user);
flag--;
}
}
void findflight(Node *user)
{
char choose[5];
int flag = 1, ch;
while(flag)
{
printf("----请输入要查询的方式----\n");
printf("----1.按航班的名称查询----\n");
printf("----2.按航班的起始点------\n");
printf("----3.查询所有航班--------\n");
printf("----4.退出查询------------\n");
scanf("%s",choose);
if (strspn(choose, "0123456789") == strlen(choose))
{
ch = atoi(choose);
switch(ch)
{
case 1:
printf("请输入要查询的航班名称:\t");
scanf("%s", F_name);
int i=0;
Node *q=user->next;
while(q != NULL)
{
if(strcmp(q -> data.name, F_name) == 0)
{
printf("航班的名称\t航班的起始点\t航班的目的地\t航班的航班时间\t航班的剩余票数\t航班的价格\n");
printf("%s\t\t%s\t\t%s\t\t%s\t\t%s\t\t%s\n",q -> data.name,q -> data.start,q -> data.bourn,
q -> data.f_schedule,q -> data.spare_votes,q -> data.price);
i++;
}
q = q -> next;
}
if(i == 0)
{
printf("该航班不存在!\n");
}
else
{
printf("要查询的航班共有%d个\n",i);
}
break;
case 2:
printf("请输入要查询的航班起始点:\t");
scanf("%s", F_start);
int ai = 0;
Node *a=user->next;
while(a != NULL)
{
if(strcmp(a -> data.start, F_start) == 0)
{
printf("航班的名称\t航班的起始点\t航班的目的地\t航班的航班时间\t航班的剩余票数\t航班的价格\n");
printf("%s\t\t%s\t\t%s\t\t%s\t\t%s\t\t%s\n",a -> data.name,a -> data.start,a -> data.bourn,
a -> data.f_schedule,a-> data.spare_votes,a-> data.price);
ai++;
}
a = a -> next;
}
if(ai == 0)
{
printf("该航班不存在!\n");
}
else
{
printf("要查询的航班共有%d个\n",ai);
}
break;
case 3:
print_List(user);
break;
case 4:
flag = 0;
break;
default:
printf("请输入正确的序号!\n");
break;
}
}
else
{
printf("请输入正确的序号!\n");
}
}
printf("已退出查询!\n");
}
void common_user(Node *user)
{
int flag = 1, ch;
while(flag)
{
printf("----1.查找航班信息 ----\n");
printf("----2.录入航班信息 ----\n");
printf("----3.按时间排序排序----\n");
printf("----4.退出用户操作 ----\n");
printf("请输入你要进行的操作:\n");
char choose[10];
scanf("%s",choose);
if (strspn(choose, "0123456789") == strlen(choose))
{
ch = atoi(choose);
switch(ch)
{
case 1:
findflight(user);
break;
case 2:
addflight(user);
break;
case 3:
bubble(user);
break;
case 4:
flag = 0;
break;
default:
printf("请输入正确的序号!\n");
break;
}
}
else
{
printf("请输入正确的序号!\n");
}
}
printf("退出普通用户操作成功!\n");
}
void login(char *id, char *pw)
{
int flag = 1,n;
char input_num[10] = {0};
while(flag)
{
printf("\t**1.开始注册 2.返回主界面**\t\n");
scanf("%s",input_num);
if (strspn(input_num, "0123456789") == 1)
{
n = atoi(input_num);
switch(n)
{
case 1:
printf("请输入账号: \n");
scanf("%s", id);
printf("请输入密码: \n");
scanf("%s", pw);
printf("\n注册成功请返回登陆\n");
break;
case 2:
printf("退出注册成功!\n");
flag = 0;
break;
case 0:
flag = 0;
break;
default :
printf("请输入正确的序号!\n");
break;
}
}
else
{
printf("请输入正确的序号!\n");
}
}
}
void *deleteflight(Node *user)
{
printf("请输入要删除的航班信息:\t\n");
printf("航班名称:\t");
scanf("%s", F_name);
printf("航班起始点:\t");
scanf("%s", F_start);
printf("航班目的地:\t");
scanf("%s", F_bourn);
printf("航班时间:\t");
scanf("%s",F_schedule);
Node *p;
Node *q;
for(p = user; NULL != p -> next; p = p -> next)
{
if((strcmp(p -> next -> data.name, F_name) == 0)&&
strcmp(p -> next -> data.start, F_start) == 0&&
strcmp(p -> next -> data.bourn, F_bourn) == 0&&
strcmp(p -> next -> data.f_schedule, F_schedule) == 0 )
{
q = p -> next;
p -> next = q -> next;
free(q);
q = NULL;
printf("删除成功\n");
print_List(user);
}
}
printf("删除失败!,请检查此航班是否存在!\n");
}
Node *updataflight(Node *user)
{
printf("请输入要更新的航班信息:\t\n");
printf("航班名称:\t");
scanf("%s", F_name);
printf("航班起始点:\t");
scanf("%s", F_start);
printf("航班目的地:\t");
scanf("%s", F_bourn);
printf("航班时间:\t");
scanf("%s",F_schedule);
Node *p;
for(p = user; NULL != p -> next; p = p -> next)
{
if((strcmp(p->next ->data.name, F_name) == 0)&&
strcmp(p ->next->data.start, F_start) == 0&&
strcmp(p ->next->data.bourn, F_bourn) == 0&&
strcmp(p ->next->data.f_schedule, F_schedule) == 0 )
{
printf("请输入要增加的航班名称: \t");
char f_name[10];
scanf("%s", f_name);
strcpy(p->next->data.name,f_name);
printf("请输入该航班的起始点: \t");
char f_start[10];
scanf("%s", f_start);
strcpy(p->next->data.start,f_start);
printf("请输入该航班的目的地: \t");
char f_bourn[10];
scanf("%s", f_bourn);
strcpy(p->next->data.bourn,f_bourn);
printf("请输入该航班的航班时间:\t");
char f_scheddule[10];
scanf("%s", f_scheddule);
strcpy(p->next->data.f_schedule,f_scheddule);
printf("请输入该航班的价格: \t");
char f_price[10];
scanf("%s", f_price);
strcpy(p->next-> data.price, f_price);
printf("请输入该航班的剩余票数: \t");
char f_s_votes[10];
scanf("%s", f_s_votes);
strcpy(p->next-> data.spare_votes, f_s_votes);
}
}
print_List(user);
}
void *insert(Node *user)
{
Node *p1=get_newNode(user);
printf("\n");
printf("请输入要插入的航班信息的后一个节点:\t\n");
printf("航班名称:\t");
scanf("%s", F_name);
printf("航班起始点:\t");
scanf("%s", F_start);
printf("航班目的地:\t");
scanf("%s", F_bourn);
printf("航班时间:\t");
scanf("%s",F_schedule);
struct node *p=user;
struct node *pre=NULL;
while (p)
{
if((strcmp(p->data.name, F_name) == 0)&&
strcmp(p->data.start, F_start) == 0&&
strcmp(p->data.bourn, F_bourn) == 0&&
strcmp(p->data.f_schedule, F_schedule) == 0 )
{
break;
}
else
{
pre=p;
p=p->next;
}
}
if(p==NULL)
{
pre->next=p1;
}
else if((strcmp(user->data.name, F_name) == 0)&&
strcmp(user->data.start, F_start) == 0&&
strcmp(user->data.bourn, F_bourn) == 0&&
strcmp(user->data.f_schedule, F_schedule) == 0 )
{
p1->next=user;
user=p1;
}
else
{
p1->next=p;
pre->next=p1;
}
print_List(user);
}
Node *mananer(Node *user)
{
{
int flag = 1, ch;
while(flag)
{
printf("----1.查找航班信息 ----\n");
printf("----2.录入航班信息 ----\n");
printf("----3.删除航班信息 ----\n");
printf("----4.修改航班信息 ----\n");
printf("----5.按时间排序排序----\n");
printf("----6.退出用户操作 ----\n");
printf("----7.插入航班信息----------\n");
printf("请输入你要进行的操作:\n");
char choose[10];
scanf("%s",choose);
if (strspn(choose, "0123456789") == strlen(choose))
{
ch = atoi(choose);
switch(ch)
{
case 1:
findflight(user);
break;
case 2:
addflight(user);
break;
case 3:
deleteflight(user);
break;
case 4:
updataflight(user);
break;
case 5:
bubble(user);
break;
case 6:
flag = 0;
break;
case 7:
insert(user);
break;
default:
printf("请输入正确的序号!\n");
break;
}
}
else
{
printf("请输入正确的序号!\n");
}
}
printf("退出管理员操作成功!\n");
}
}
void sign(char *u_id, char *u_pw,Node *user)
{
char login_id[10] = {0};
char login_pw[10] = {0};
printf("请输入账号:\n");
scanf("%s", login_id);
printf("请输入密码:\n");
scanf("%s", login_pw);
if((strcmp(login_id,"jack")==0)&&(strcmp(login_pw,"1234")==0))
{
printf("管理员登录成功\n");
mananer(user);
}
else if( (strcmp(login_id, u_id) == 0) && (strcmp(login_id, u_pw) == 0))
{
printf("用户登录成功\n");
common_user(user);;
}
else
{
printf("此账号未注册\n");
}
}
int main()
{
Node *user=create_list();
flight *user1=creat_list();
printf("\n");
int flag = 1, nu;
while(flag)
{
printf("\n");
printf("---------滁州市凤阳县国际机场提醒您--------\n");
printf("---------欢迎来到盛真皮国际航班系统--------\n");
printf("\n");
printf("-----------------1.注册--------------------\n");
printf("\n");
printf("-----------------2.登录--------------------\n");
printf("\n");
printf("-----------------0.退出---------------------\n");
char num[10];
scanf("%s",num);
if (strspn(num, "0123456789") == 1)
{
nu = atoi(num);
switch(nu)
{
case 0:
printf("已退出系统!\n");
flag = 0;
break;
case 1:
login(user_id, user_pw);
break;
case 2:
sign(user_id, user_pw,user);
break;
default:
printf("请输入正确的序号!\n");
break;
}
}
else
{
printf("请输入正确的序号!\n");
}
}
}