?? flightmanagement.txt
字號:
#include<stdio.h>
#include<malloc.h>
#include<string.h>
#include<stdlib.h>
#define NULL 0
struct Address /*定義結構體*/
{
char Airline[20]; /*航向名稱*/
char Number[20]; /*航班號*/
long int Date; /*航班日期*/
int Plane; /*機型*/
char Company[20]; /*所屬公司*/
struct Address *next;
};
int n=0; /*定義一個全局變量 n*/
/****************添加記錄函數*******************/
struct Address * creat(struct Address *head) /*定義函數。創建并判斷鏈表是否已經存在,然后添加記錄*/
{
struct Address *p1,*p2;
if(head==NULL) /*判斷鏈表是否存在*/
{
p1=p2=(struct Address *)malloc(sizeof(struct Address));/*鏈表不存在,開辟一個新單元*/
scanf("%s%s%ld%d%s",p1->Airline,p1->Number,&p1->Date,&p1->Plane,p1->Company);/*錄入信息*/
while(p1->Date!=0) /*若輸入值是0,則鏈表創建結束*/
{
n=n+1;
if(n==1)head=p1; /*只有一條記錄時*/
else p2->next=p1;
p2=p1;
p1=(struct Address *)malloc(sizeof(struct Address)); /*新開辟一個結點*/
scanf("%s%s%ld%d%s",p1->Airline,p1->Number,&p1->Date,&p1->Plane,p1->Company);
}
p2->next=NULL; /*結束鏈表*/
}
else /*添加記錄*/
{
p1=head;
while(p1) /*尋找原鏈表最后結點*/
{
p2=p1;
p1=p1->next;
}
p1=(struct Address *)malloc(sizeof(struct Address)); /*新開辟一個結點*/
scanf("%s%s%ld%d%s",p1->Airline,p1->Number,&p1->Date,&p1->Plane,p1->Company);
while(p1->Date!=0) /*輸入信息結束標志*/
{
n=n+1;
p2->next=p1; /*將鏈表鏈接*/
p2=p1;
p1=(struct Address *)malloc(sizeof(struct Address));
scanf("%s%s%ld%d%s",p1->Airline,p1->Number,&p1->Date,&p1->Plane,p1->Company);
}
p2->next=NULL;
}
return(head); /*返回頭指針*/
}
/*******************顯示記錄函數***********************/
void print(struct Address *head) /*定義輸出函數*/
{
struct Address *p;
printf("航線\t航號班\t航班日期\t機型\t所屬公司\n\n");
p=head; /*指針賦值*/
if(head!=NULL) /*輸出整個鏈表*/
do
{
printf("%s\t%s\t%ld\t%d\t%s\n",p->Airline,p->Number,p->Date,p->Plane,p->Company);
p=p->next;
}while(p!=NULL); /*判斷鏈表結束標志*/
printf("\n");
}
void menu1() /*定義查詢菜單函數*/
{
printf("\n\t\t ~~~~~~~~~~~~~~~~~~~\n");
printf("\t\t\t歡迎您來查詢!\n");
printf("\t\t ~~~~~~~~~~~~~~~~~~~\n");
printf("查詢菜單:\n\n");
printf("1.航線\n");
printf("2.航班號\n");
printf("3.航班日期\n");
printf("4.機型\n");
printf("5.所屬公司\n");
printf("6.返回主菜單\n\n");
printf("請選擇您需要查詢的類別<1~6>:\n");
}
/******************分類查詢記錄函數**********************/
void inqurement(struct Address *head) /*定義查找函數*/
{ /*判斷標志*/
int c,flag;
struct Address *p;
start: /*位置標志*/
menu1();
repeat3:
scanf("%d",&c);
if(c<1 || c>6)
{
printf("輸入有誤!請重輸:\n");
goto repeat3;
}
switch(c)
{
case(1): /*實現輸入航線所有信息的查詢*/
p=head;
char inqureline[20];
flag=0;
system("cls"); /*清屏*/
printf("請輸入您需要查詢的航線:\n");
scanf("%s",inqureline);
while(p)
{
if(strcmp(inqureline,p->Airline)==0) /*判斷信息*/
{
if(flag==0)
{
flag=1; /*定義標志*/
system("cls");
printf("您所需的航班信息為:\n\n");
printf("航線\t航號班\t航班日期\t機型\t所屬公司\n\n");
printf("%s\t%s\t%ld\t%d\t%s\n",p->Airline,p->Number,p->Date,p->Plane,p->Company);
}
else
printf("%s\t%s\t%ld\t%d\t%s\n",p->Airline,p->Number,p->Date,p->Plane,p->Company);
}
p=p->next; /*p后移一個結點*/
}
if(flag==0)
{
printf("\n對不起,沒有您所需要的航班信息!\n");
p=head; /*使指針重新回到鏈表頭*/
}
getchar(); /*此語句用來接收在執行scanf語句時最后輸入的回車符*/
printf("\n按回車鍵返回查詢菜單!\n");
getchar();
system("cls");
goto start; /*返回頁面*/
break;
case(2): /*實現對輸入航班號的所有信息查詢*/
char inqurenumber[20];
p=head;flag=0;
system("cls");
printf("請輸入您需要查詢的航班號:\n\n");
scanf("%s",inqurenumber);
while(p)
{
if(strcmp(inqurenumber,p->Number)==0)
{
if(flag==0)
{
flag=1;
system("cls");
printf("您所需的航班信息為:\n");
printf("航線\t航號班\t航班日期\t機型\t所屬公司\n\n");
printf("%s\t%s\t%ld\t%d\t%s\n",p->Airline,p->Number,p->Date,p->Plane,p->Company);
}
else
printf("%s\t%s\t%ld\t%d\t%s\n",p->Airline,p->Number,p->Date,p->Plane,p->Company);
}
p=p->next;
}
if(flag==0)
printf("\n對不起,沒有您所需要的航班信息!\n");
getchar();
printf("\n按回車鍵返回查詢菜單!\n");
getchar();
system("cls");
goto start;
break;
case(3): /*實現對輸入航班日期所有信息查詢*/
long int inquredate;
p=head;flag=0;
system("cls");
printf("請輸入您需要查詢的航班日期:\n\n");
scanf("%ld",&inquredate);
while(p)
{
if(inquredate==p->Date)
{
if(flag==0)
{
flag=1;
system("cls");
printf("您所需的航班信息為:\n\n");
printf("航線\t航號班\t航班日期\t機型\t所屬公司\n\n");
printf("%s\t%s\t%ld\t%d\t%s\n",p->Airline,p->Number,p->Date,p->Plane,p->Company);
}
else
printf("%s\t%s\t%ld\t%d\t%s\n",p->Airline,p->Number,p->Date,p->Plane,p->Company);
}
p=p->next;
}
if(flag==0)
printf("\n對不起,沒有您所需要的航班信息!\n");
getchar();
printf("\n--按回車鍵返回查詢菜單!~\n");
getchar();
system("cls");
goto start;
break;
break;
case(4): /*實現對輸入機型所有信息查詢*/
int inqureplane;
p=head;flag=0;
system("cls");
printf("請輸入您需要查詢的機型:\n\n");
scanf("%ld",&inqureplane);
while(p)
{
if(inqureplane==p->Plane)
{
if(flag==0)
{
flag=1;
system("cls");
printf("您所需的航班信息為:\n\n");
printf("航線\t航號班\t航班日期\t機型\t所屬公司\n\n");
printf("%s\t%s\t%ld\t%d\t%s\n",p->Airline,p->Number,p->Date,p->Plane,p->Company);
}
else
printf("%s\t%s\t%ld\t%d\t%s\n",p->Airline,p->Number,p->Date,p->Plane,p->Company);
}
p=p->next;
}
if(flag==0)
printf("\n對不起,沒有您所需要的航班信息!\n");
getchar();
printf("\n按回車鍵返回查詢菜單!\n");
getchar();
system("cls");
goto start;
break;
break;
case(5): /*實現對輸入公司名稱所有信息查詢*/
char inqurecompany[20];
p=head;flag=0;
system("cls");
printf("請輸入您需要查詢的公司名稱:\n\n");
scanf("%s",inqurecompany);
while(p)
{
if(strcmp(inqurecompany,p->Company)==0)
{
if(flag==0)
{
flag=1;
system("cls");
printf("您所需的航班信息為:\n\n");
printf("航線\t航號班\t航班日期\t機型\t所屬公司\n\n");
printf("%s\t%s\t%ld\t%d\t%s\n",p->Airline,p->Number,p->Date,p->Plane,p->Company);
}
else
printf("%s\t%s\t%ld\t%d\t%s\n",p->Airline,p->Number,p->Date,p->Plane,p->Company);
}
p=p->next;
}
if(flag==0)
printf("\n對不起,沒有您所需要的航班信息!\n");
getchar();
printf("\n按回車鍵返回查詢菜單!\n");
getchar();
system("cls");
goto start;
break;
case(6):break; /*退出函數*/
}
}
/*******************航班號排序函數*********************/
struct Address *list(struct Address *head) /*定義排序函數*/
{ /*選擇法排序。bfp1為p1前一地址,bfmin為min前一地址。*/
struct Address *p1=NULL,*p2=NULL;
struct Address *bfp1=NULL,*min=NULL,*bfmin=NULL; /*定義結構體指針變量*/
p1=head;
while(p1->next) /*判斷鏈尾*/
{
min=p2=p1;
while(p2->next) /*判斷鏈尾*/
{
if(strcmp(min->Number,p2->next->Number)>0)
{
bfmin=p2;
min=p2->next;
}
p2=p2->next; /*下移*/
}
if(min!=p1) /*成立則修改鏈表*/
{
bfmin->next=min->next; /*刪除節點*/
min->next=p1; /*插入節點*/
if(p1==head) head=min;
else
bfp1->next=min; /*建立連接*/
bfp1=min;
}
else
{
bfp1=p1;
p1=p1->next;/*下移*/
}
}
return(head);
}
struct Address *dele(struct Address * head) /*創建刪除記錄函數,返回鏈表表頭*/
{
struct Address *p1,*p2;
p1=head;
int a,b,c;
char line[20];
if(head==NULL) /*系統信息有無判斷*/
{
system("cls");
printf("\n對不起,系統中暫時沒有可刪除的信息!\n");
}
else /*系統存在記錄,進入刪除程序*/
{
system("cls");
int i;
printf("*您需要:\n\n");
printf("1.逐條刪除\n");
printf("2.全部刪除\n");
printf("\n~請選擇1~2:\n");
back:
scanf("%d",&i);
if(i<1||i>2)
{
printf("輸入有誤!請重輸:\n"); /*輸入正誤判斷*/
goto back;
}
switch(i)
{
case(1):
repeat:
printf("請輸入您要刪除的航線名稱:\n"); /*實現逐條刪除*/
printf("如:bjsh\n");
scanf("%s",line);
while(strcmp(line,p1->Airline)!=0&&p1->next!=0) /*尋找需要查找的結點*/
{
p2=p1;p1=p1->next;
}
if(strcmp(line,p1->Airline)==0) /*判斷信息是否找到*/
{
system("cls");
printf("您要刪除的信息為:\n");
printf("航線\t航號班\t航班日期\t機型\t所屬公司\n\n");
printf("%s\t%s\t%ld\t%d\t%s\n",p1->Airline,p1->Number,p1->Date,
p1->Plane,p1->Company);
printf("請選擇:\n1.確認\t2.取消\n\n");
repeat1:
scanf("%d",&a);
if(a<1||a>2)
{
printf("輸入有誤!請重輸:\n"); /*輸入正誤判斷*/
goto repeat1;
}
switch(a)
{
case(1):
{
if(p1==head) /*刪除頭結點*/
head=p1->next;
else
p2->next=p1->next;
system("cls");
printf("*****刪除航線%s成功!\n",line);
n=n-1;
break;
}
case(2): break;
}
}
else
{
system("cls");
printf("對不起,系統中沒有您要找的%s \n",line);
printf("\n請選擇:\n1.重輸2.返回\n\n");
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -