c语言实现机票管理系统源代码
- 格式:docx
- 大小:116.03 KB
- 文档页数:50
#include<stdio.h> //标准输入、输出头文件#include<string.h> //包含字符串函数处理头文件#include<stdlib.h> //包含动态存储与释放函数头文件#include<process.h>//包含access函数的头文件#define N 10000struct plane //定义结构体数组{int num;char start[20];char over[20];char time[10];int count;int ys;}s[N];int i;int m=0;#define PRINT "%-d%10s%10s%10s%12d%12d\n",s[i].num,s[i].start,s[i].over,s[i].time,s [i].count,s[i].ys //定义输出格式void input(); //输入航班信息void save(); //保存航班信息void read(); //读取航班信息void order();//升序输出航班信息void search(); //查找航班信息void dingpiao(); //订票信息void tuipiao(); //退票信息void save1();//void main()//主函数{ int j;save1();do{printf(" \n");printf(" ★--- 您好,欢迎进入自制飞机订票系统!---★\n");printf(" \n");printf("********************************************************************* *\n");printf(" \n");printf(" -------- ☆ 1.输入航班信息☆-------- \n\n" " -------- ※ 2.浏览航班信息※-------- \n\n"" -------- ☆ 3.查找航班信息☆-------- \n\n"" -------- ※ 4.订票信息※-------- \n\n"" -------- ☆ 5.退票信息☆-------- \n\n"" -------- *0.退出* -------- \n\n"); printf(" \n");printf("********************************************************************* **\n");printf(" \n");printf(" 请在0-5中选择以回车键结束:\n\n");scanf("%d",&j);switch(j){case 1: input();//调用输入模块break;case 2:order();//调用打印模块break;case 3:search();//调用查找模块break;case 4:dingpiao();//调用订票模块break;case 5:tuipiao();//调用退票模块break;case 0:;break;}}while(j!=0); //判断结束printf("谢谢使用,再见!\n");}//主函数结束void input()//信息录入{ int y;{FILE *fp;//定义文件指针if((fp=fopen("plane.txt","wb"))==NULL)//打开文件并判断是否出错{printf("创建文件失败!\n\n");//打印出错提示getchar();return;}printf("→→→→→→→→→→→→→→→→→\n");printf("请依次输入航班信息\n\n""完成输入信息请键入0以回车键结束\n\n"); //提示信息printf("←←←←←←←←←←←←←←←←←\n");for(i=0;i<N;i++){printf("请输入航班号: \n");scanf("%d",&s[i].num); //读取航班号printf("请输入起始站: \n");scanf("%s",s[i].start);//读取起始站printf("请输入终点站: \n");scanf("%s",s[i].over);//读取终点站printf("请输入时间: \n");scanf("%s",s[i].time);//读取时间printf("请输入机票数(机票数为0结束输入): \n",);scanf("%d",&s[i].count);//读取机票数m++;//统计输入的航班总数printf("信息已经输完是否继续?请输入任意数字键并回车继续,按0键回车结束",m);scanf("%d",&y);if(y==0){save();//将结构体信息存盘break;}}}}void save()//保存模块程序{ FILE *fp;//定义文件指针if((fp=fopen("plane.txt","wb"))==NULL)//打开文件并判断是否出错{printf("创建文件失败!\n\n");//打印出错提示getchar();return;}for(i=0;i<m;i++)if(fwrite(&s[i],sizeof(struct plane),1,fp)==0)//写入数据判断是否出错printf("向文件输入数据失败!\n\n");fclose(fp);//关闭文件}void save1(){if(access("plane.txt",0))//判断文件是否存在{input();//调用输入模块}elsesave();//调用保存模块}void read()//从文件读取信息模块{FILE *fp;//定义文件指针if((fp=fopen("plane.txt","rb"))==NULL)//打开文件,并判断是否出错{printf("出错,请检查文件是否存在,按z键回车返回主菜单");//错误提示getchar();return;}i=0;while(!feof(fp)){fread(&s[i],sizeof(struct plane),1,fp);//从文件中读取信息i++;m++;}m--;fclose(fp);//关闭文件}void order()//升序排列航班信息模块{int i,j;//冒泡法排序struct plane t;for(i=0;i<m;i++){for(j=0;j<m-1;j++)if(s[j].num>s[j+1].num){t=s[j+1];s[j+1]=s[j];s[j]=t;}}{char w[20];printf("航班号起始站终点站飞行时间机票总数已售票数\n");for(i=0;i<m;i++){printf(PRINT);//打印信息}printf("请按z键回车键结束返回主菜单:\n");scanf("%s",w);}}void search()//查询模块{char name1[20];char name2[20];char hb[10];int n,b;do{printf("→→→→→→→→→→→→→→→→→\n"); printf("请选择查找方式:\n\n");//打印查询方式菜单printf("—— 1.按航班号查找——\n\n""—— 2.按起始站查找——\n\n""—— 3.终点站查找——\n\n""—— 0.返回——\n\n");printf("←←←←←←←←←←←←←←←←←\n"); printf("请在0-3中选择:\n\n");scanf("%d",&n);//读取查找方式if(n==0)break;switch(n){case 1:printf("请输入航班号: \n");scanf("%d",&b);//航班号break;case 2:printf("请输入起始站名称: \n");scanf("%s",name1);//读取终点站break;case 3:printf("请输入终点站名称: \n");scanf("%s",name2);//终点站break;}read();//调用读取函数for(i=0;i<m;i++){ if(strcmp(s[i].start,name1)==0)//按起始站判断输出条件{printf("\n查找航班信息成功!\n");printf("航班号起始站终点站飞行时间机票总数已售票数\n");printf(PRINT);//打印信息break;}if(strcmp(s[i].over,name2)==0)//按终点站判断输出条件{printf("\n查找航班信息成功!\n");printf("航班号起始站终点站飞行时间机票总数已售票数\n");printf(PRINT);//打印信息break;}if(s[i].num==b)//按航班号判断输出条件{ printf("\n查找航班信息成功!\n");printf("航班号起始站终点站飞行时间机票总数已售票数\n");printf(PRINT);//打印信息break;}}b=0;//将航班号赋值为0printf("**查找完毕**\n\n");printf("此航班若是您需要查询航班,请输入yes并回车确定\n""此航班不是您需要查询的航班,请输入no并回车键重新查询:\n"); scanf("%s",hb);}while(strcmp(hb,"no")==0);//判断结束}void dingpiao()//订票模块{int n;char a[10];do{search();//调用查询模块printf("请输入您要订的机票数以回车键结束:\n");scanf("%d",&n);//读取所订机票数if(s[i].count<n)//判断机票数是否足够{printf(" 机票数不足!\n");break;}if(n<=0){printf("请输入有效的机票数!\n");//判断机票数是否出错break;}if(s[i].count!=0&&s[i].count>=n)//判断是否出错{s[i].count=s[i].count-n;s[i].ys=n;save();//调用保存函数printf("\n""\n");printf("Θ⊕订票成功⊕Θ!\n\n");}printf("是否继续订票?请输入yes或no以回车键结束:\n");//判断是否继续scanf("%s",a);}while(strcmp(a,"yes")==0);//判断结束getchar();}void tuipiao()//退票模块{int n;char a[10];do{search();//调用查询模块printf("请输入您要退的机票数目:\n");scanf("%d",&n);//输入所退票数if(s[i].ys<n)//判断可退机票数是否足够{printf(" 可退机票数不足!\n"); break;}if(n<=0) //判断票数是否有效printf("请输入有效的机票数!\n");s[i].count=s[i].count+n;s[i].ys=s[i].ys-n;save(); //调用保存模块printf(" \n""⊙☉退票成功!☉⊙\n\n"" \n");printf("是否继续退票?请键入yes或no以回车键结束:\n\n");//是否继续scanf("%s",a);}while(strcmp(a,"yes")==0);//判断并跳出循环getchar();}。
#include <stdio.h〉#include <stdlib.h〉#include <string.h〉#define NOD struct plane_liststruct plane{char number [10];char start[10];char arrive [10];char date[10];char starttime[10];char arrivingtime[10];char price[10];char model[10];};NOD{char number [10];char start[10];char arrive [10];char date[10];char starttime[10];char arrivingtime[10];char price[10];char model[10];NOD*next;};FILE *fp;/*由文件中的数据生成一个飞机航班的链表,如果文件不存在,则是一个空链表*/ NOD *load(char planename[]){ NOD *p,*q,*head;struct plane per;p=(NOD *)malloc(sizeof(NOD));q=head=NULL;if((fp=fopen(planename,”rb”))==NULL)return head;else{while(!feof(fp)){if(fread(&per,sizeof(struct plane),1,fp)==1){p=(NOD *)malloc(sizeof(NOD));strcpy(p->number,per。
number);strcpy(p-〉start,per.start);strcpy(p->arrive,per。
arrive);strcpy(p—〉date,per。
date);strcpy(p->starttime,per.starttime);strcpy(p—〉arrivingtime,per.arrivingtime);strcpy(p—>price,per.price);strcpy(p—>model,per.model);head=p;p-〉next=q;q=head;}}}fclose(fp);return(head);}/*输入*/NOD *insert(NOD *head){NOD *temp,*p;p=head;temp=(NOD *)malloc(sizeof(NOD));printf(”\n\t请输入航班号:");scanf(”%s",temp-〉number);printf(”\n\t请输入起点站:”);scanf(”%s",temp->start);printf("\n\t请输入终点站:”);scanf("%s”,temp—〉arrive);printf(”\n\t请输入起飞时间:”);scanf(”%s",temp—>starttime);printf(”\n\t请输入到达时间:”);scanf(”%s”,temp-〉arrivingtime);printf(”\n\t请输入班期:”);scanf("%s”,temp—>date);printf(”\n\t请输入票价:");scanf(”%s",temp—>price);printf("\n\t请输入航班型号:”);scanf("%s",temp—>model);head=temp;temp—>next=p;return head;}/*保存*/void save(NOD *head, char filename[]){NOD*p;struct plane per;if((fp=fopen(filename,"wb”))==NULL){printf(" 文件无法写入”);exit(0);}else{ p=head;while(p!=NULL){ strcpy(per。
//---------------------航班管理程序系统---------------------//#include<stdio.h>#include<stdlib.h>#include<string.h>#include<conio.h>#define N 20void welcome()。
//定义一个欢迎界面函数 //void entrance()。
//定义一个进入界面 //void score()。
//定义一个记录查询函数 //void add()。
//定义一个添加航班的函数 //void cut()。
//定义一个删除航班的函数 //void sell()。
//定义一个售出航班的函数 //void consult()。
//定义一个按要求查询的函数 //void compos()。
//定义一个按航班号排序的函数 //void back()。
//定义一个返回函数 //void read()。
//定义一个读入函数 //void save()。
//定义一个保存函数 //int all=10。
int ans。
typedef struct flight{char flightNum[N]。
//航班号//char setPlace[N]。
//出发地//char destPlace[N]。
//目的地//int Amount。
//数量//char airCompany[N]。
//航空公司//char setTime[N]。
//出发时间//char arrTime[N]。
//到达时间//}ft。
struct flight fli[50]={{"A1001","北京","大连",1000,"北京航空公司","8:00","8:45"},{"A1002","上海","太原",2000,"春秋航空公司","4:00","5:00"},{"A1003","沈阳","长沙",2500,"东北航空公司","10:00","13:30"},{"A1014","石家庄","贵阳",3000,"河北航空公司","15:00","17:40"},{"A1005","长春","广州",4500,"长春航空公司","14:20","16:10"},{"B1006","郑州","武汉",5000,"新郑航空公司","19:30","20:10"},{"B1007","重庆","昆明",6000,"重庆航空公司","18:00","19:10"},{"B1008","厦门","兰州",7000,"厦门航空公司","6:40","8:20"},{"B1009","深圳","黑龙江",8000,"深圳航空公司","21:00","23:50"},{"B1010","海南","台北",8500,"海南航空公司","2:00","2:30"}}。
#include <string.h>#include <iostream.h>#define M 5//每种飞机票的总数目#define N 3//飞机票的总数目class Plane{private:char name[40];//终点站名int number;//航班号int Number;//飞机号int week;//星期几飞行int day;//日期int left;//余票额int n;//与数组flag一起确定客户订票状态public:int flag[20];//订票状态数组,-1为预订票,1为已定票,0为初始化状态Plane()//构造函数{name[0]='\0';number=0;Number=0;week=0;day=0;left=M;n=0;//数组从0开始计数for(int i=0;i<20;i++)flag[i]=0;}void init()//初始化每种飞机票{cout<<"请输入终点站名:";cin>>name;cout<<"请输入航班号:";cin>>number;cout<<"请输入飞机号:";cin>>Number;cout<<"请输入星期几飞行:";cin>>week;cout<<"请输入航班的日期:";cin>>day;}~Plane(){};//析构函数char *getname(){return name;}//获得终点站名int getnumber(){return number;}//获得航班号int getNumber(){return Number;}//获得飞机号int getweek(){return week;}//获得星期几飞行int getday(){return day;}//获得日期int getleft(){return left;}//获得余票额int getn(){return n;}//获得旅客数目void inleft(int n){left=left+n;}//余票额增加函数void deleft(int n){left=left-n;}//余票额减少函数void inn(){n++;}//旅客数目增加函数};Plane pl[N];int showmenu();//菜单函数void start();//初始化函数void query();//查询函数void make();//订票函数void back();//退票函数int main(){cout<<"这是民航售票处的计算机系统程序"<<endl;start();while(1){int choice;choice=showmenu();switch(choice){case 1:query();break;case 2:make();break;case 3:back();break;case 0:return 0;default:cout<<"你敲错了!\n";}}return 0;}int showmenu(){int ch;cout<<endl;cout<<"请选择你要执行的功能"<<endl;cout<<"1:查询航线"<<endl;cout<<"2:承办订票业务"<<endl;cout<<"3:承办退票业务"<<endl;cout<<"0:退出程序的运行"<<endl;cin>>ch;return ch;}void start(){for(int i=0;i<N;i++){pl[i].init();cout<<endl;}}void query(){int i,num=0;char name[40];cout<<endl;cout<<"请输入终点站名:";cin>>name;for(i=0;i<=N;i++)if(strcmp(name,pl[i].getname())==0){num++;cout<<"航班号:"<<pl[i].getnumber()<<endl;cout<<"飞机号:"<<pl[i].getNumber()<<endl;cout<<"星期:"<<pl[i].getweek()<<"飞行"<<endl;cout<<"航班日期:"<<pl[i].getday()<<endl;cout<<"余票额:"<<pl[i].getleft()<<endl;break;}if(num==0)cout<<"没有此航班"<<endl;}void make(){int number,n,sitnumber,nu,ch,num=0;cout<<"请输入航班号:";cin>>number;cout<<"请输入订票数额:";cin>>n;for(int i=0;i<N;i++)if(number==pl[i].getnumber()){num++;if(n<=pl[i].getleft()){cout<<"此航班有票"<<endl;pl[i].deleft(n);pl[i].inn();pl[i].flag[pl[i].getn()]=1;for(i=0;i<n;i++){cout<<"座位号";cin>>sitnumber;}}else{cout<<"余票额少于订票额,请重新输入订票数额,"<<"订票数额应该少于或等于"<<pl[i].getleft();cin>>nu;if(nu<=pl[i].getleft()){cout<<"此航班有票"<<endl;pl[i].deleft(nu);pl[i].inn();pl[i].flag[pl[i].getn()]=1;for(i=0;i<N;i++){cout<<"座位号";cin>>sitnumber;}}else{cout<<"是否需要预约"<<endl;cout<<"是(1) 否(2)"<<endl;cin>>ch;switch(ch){case 1:pl[i].inn();pl[i].flag[pl[i].getn()]=-1;break;case 2:break;default:cout<<"你敲错了!"<<endl;}}}}if(num==0)cout<<"没有此航班"<<endl;}void back(){int number,day,n,nu,sitnumber,num=0;//航班号,日期,退票数目,订票数目,座位号,标志量cout<<"请输入日期:";cin>>day;cout<<"请输入航班:";cin>>number;for(int i=0;i<N;i++)if((day==pl[i].getday())&&(number==pl[i].getnumber()))//日期与航班是否满足{num++;//日期与航班满足cout<<"输入退票数目";cin>>n;cout<<"退票成功"<<endl;pl[i].inleft(n);//该种飞机票增加,即已退票for(int j=0;j<=pl[i].getn();j++)//顺序查询客户订票状态{if(pl[i].flag[j]==-1)//客户是否为预定状态{cout<<"有预约订票,请输入订票数额:";cin>>nu;if(nu<=pl[i].getleft())//余票额是否满足要求{cout<<"此航班有票"<<endl;pl[i].flag[j]=1;cout<<"订票成功"<<endl;pl[i].deleft(nu);for(int k=0;k<nu;k++){cout<<"座位号"<<" ";cin>>sitnumber;}cout<<"余票额为"<<pl[i].getleft()<<endl;}}elsecout<<"没有预约订票!"<<"余票额为"<<pl[i].getleft()<<endl;}}if(num==0)cout<<"没有此票"<<endl;}。
C#数据库应用系统(机票预定系统)源代码using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Data.SqlClient;using System.Windows.Forms;namespace TicketOrder{public partial class Form1 : Form{public Form1(){InitializeComponent();}string sql = "";string connStr =@"server=sa\SQLEXPRESS;database=Ticket;trusted_connection=true";SqlDataAdapter da;DataSet ds;private void Form1_Load(object sender, EventArgs e){sql = "select FlightNO as '航班号',LeaveCity as '出发城市',Destination as '目的城市',LeaveTime as '出发时间' from TicketInfo where 1=1";Fill();}/// <summary>/// 初始化函数/// </summary>private void Fill(){da = new SqlDataAdapter(sql, connStr);ds = new DataSet();try{da.Fill(ds);dataGridView1.DataSource = ds.Tables[0];}catch (Exception ex){MessageBox.Show("输入信息有误,可能有不能识别的字符!"+ex.Message);}}private void button3_Click(object sender, EventArgs e){bool isNew = true;while (isNew){if (txtChufa.Text != ""){sql += string.Format(" and LeaveCity like'%{0}%'", txtChufa.Text);Fill();}if (txtMudi.Text != ""){sql += string.Format(" and Destination like'%{0}%'", txtMudi.Text);Fill();}isNew = false;sql = "select FlightNO as '航班号',LeaveCity as '出发城市',Destination as '目的城市',LeaveTime as '出发时间' from TicketInfo where 1=1";}}private void button1_Click(object sender, EventArgs e){sql = string.Format("insert into OrderInfo(FlightNO,SeatType,Number,LeaveDate) values('{0}','{1}','{2}','{3}')", textBox3.Text, cboClass.Text, textBox4.Text, textBox5.Text);SqlConnection conn = new SqlConnection(connStr);int num = 0;try{conn.Open();SqlCommand cmd = new SqlCommand(sql, conn);num = cmd.ExecuteNonQuery();if (num != 0)MessageBox.Show("预定成功!");elseMessageBox.Show("预定失败!");}catch (Exception ex){MessageBox.Show(ex.Message);}finally{conn.Close();}}private void button2_Click(object sender, EventArgs e){Application.Exit();}}}。
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<ctype.h>#define N 6#define M 150struct airline//*********************************************************飞机航班的结构定义{Charair_num[10];//**************************************************************航班号charplane_num[10];//************************************************************飞机号charstart_place[10];//**********************************************************起点站charend_place[10];//************************************************************终点站chardate[15];//*******************************************************************日期inttotal;//*********************************************************************总票数int left;//********************************************************************剩余票数}airline[N];struct customer//********************************************************客户信息的结构定义{charname[10];//*******************************************************************姓名char shenfenzheng[20];//*******************************************************身份证号charair_num[10];//**************************************************************航班号charcangwei[12];//****************************************************************仓位intpiaoshu;//********************************************************************订票数}customer[M];voidhangbanbaobiao();//***********************************************************航班报表void guanli();//***********************************************************基本信息管理函数(管理员通道)voidkehu();//*********************************************************************客户通道void luru();//*****************************************************************录入航线信息void xiugai();//***************************************************************修改信息函数void shanchu();//**************************************************************删除航线信息void hangxianchaxun();//*******************************************************航线查询函数void jipiaoyuding();//*********************************************************机票预订函数void tuidingjipiao();//********************************************************机票退订函数void zhucaidan();//**************************************************************主菜单函数void jiami(char * s,int);//********************************************************加密函数void main(){system("color 47");zhucaidan();}void zhucaidan(){int n;char mima[13];system("cls");printf("\t\t\t※*************************************※\n");printf("\t\t\t※※\n");//开始界面printf("\t\t\t※★欢迎进入宇宙航空客户管理系统!★※\n");printf("\t\t\t※※\n");printf("\t\t\t※*************************************※\n\n");printf("\t\t\t※*************************************※\n");printf("\t\t\t※※\n");printf("\t\t\t※请选择登入身份:※\n");printf("\t\t\t※管理员登入请按 1 ※\n");printf("\t\t\t※客户登入请按 2 ※\n");printf("\t\t\t※※\n");printf("\t\t\t※*************************************※\n");do//************************************************************************以防客户输错{scanf("%d",&n);if (n!=1&&n!=2)printf("\t\t输入错误,请重新输入\n");}while(n!=1&&n!=2);if(n==1)//*******************************************************************管理员登入{int cuowu=1;do{printf("\t\t请输入12位管理员密码:\n");jiami(mima,12);printf("\n");if (strcmp(mima,"xiongweizhou")==0)guanli();else{printf("\t\t密码输入错误,请注意大小写!\n");cuowu++;}if (cuowu==4){printf("\t\t对不起,你已经没有机会了!\n");printf("\t\t密码如果忘了请联系本系统管理员!\n");break;}}while(cuowu<=3&&strcmp(mima,"xiongweizhou")!=0);}if(n==2)//*********************************************************************客户登入{kehu();}}void kehu()//*********************************************************客户通道{int m;system("cls");do{printf("\t\t\t※*************************************※\n");printf("\t\t\t※※\n");printf("\t\t\t※★欢迎进入客户服务通道!★※\n");printf("\t\t\t※※\n");printf("\t\t\t※*************************************※\n\n");printf("\t\t\t※*************************************※\n");printf("\t\t\t※※\n");printf("\t\t\t※尊敬的客户您好,请选择以下操作: ※\n");printf("\t\t\t※航线查询请按 1 ※\n");printf("\t\t\t※机票预订请按 2 ※\n");printf("\t\t\t※退订机票请按 3 ※\n");printf("\t\t\t※想返回主菜单请按 4 ※\n");printf("\t\t\t※※\n");printf("\t\t\t※*************************************※\n");scanf("%d",&m);if (m!=1&&m!=2&&m!=3&&m!=4)printf("\t请按要求操作,谢谢!\n");}while(m!=1&&m!=2&&m!=3&&m!=4);if (m==1)hangxianchaxun();if (m==2)jipiaoyuding();if (m==3)tuidingjipiao();if (m==4)zhucaidan();}voidguanli()//********************************************************************基本信息管理函数{int m;system("cls");do{printf("\t\t\t※*************************************※\n");printf("\t\t\t※※\n");printf("\t\t\t※★欢迎进入管理员通道!★※\n");printf("\t\t\t※*************************************※\n\n");printf("\t\t\t※*************************************※\n");printf("\t\t\t※※\n");printf("\t\t\t※管理员您好,请选择以下操作: ※\n");printf("\t\t\t※录入航线信息请按 1 ※\n");printf("\t\t\t※修改航线信息请按 2 ※\n");printf("\t\t\t※删除航线信息请按 3 ※\n");printf("\t\t\t※打印航班报表请按 4 ※\n");printf("\t\t\t※想返回主菜单请按 5 ※\n");printf("\t\t\t※※\n");printf("\t\t\t※*************************************※\n");scanf("%d",&m);if (m!=1&&m!=2&&m!=3&&m!=4&&m!=5)printf("\t请按要求操作,谢谢!\n");}while(m!=1&&m!=2&&m!=3&&m!=4&&m!=5);if (m==1)luru();if (m==2)xiugai();if (m==3)shanchu();if (m==4)hangbanbaobiao();if (m==5)zhucaidan();}void luru()//*******************************************************录入航线信息{FILE *fp=NULL;static i=0;int fanhui;char ch='y';system("cls");if ((fp=fopen("flight.txt","a"))==NULL){printf("can not open flight.txt.\n");exit(0);}printf("\t\t\t※***********************※\n");printf("\t\t\t※★请认真输入信息!★※\n");printf("\t\t\t※***********************※\n");getchar();printf("\t\t请输入航班号:\n");gets(airline[i].air_num);printf("\t\t请输入飞机号:\n");gets(airline[i].plane_num);printf("\t\t请输入起始站:\n");gets(airline[i].start_place);printf("\t\t请输入终点站:\n");gets(airline[i].end_place);printf("\t\t请输入日期(****-**-**):\n");gets(airline[i].date);cuowu://goto标志printf("\t\t请输入总票数:\n");scanf("%d",&airline[i].total);printf("\t\t请输入余票数:\n");scanf("%d",&airline[i].left);if (airline[i].total<airline[i].left)//************************防止输入总票数小于余票数{printf("输入错误!总票数小于余票数!请重新输入!\n");goto cuowu;};fwrite(&airline[i],sizeof(airline[0]),1,fp);getchar();do{printf(" 你是否还要录入信息?是按\"y\",否按\"n\"! \n");ch=getchar();if (ch=='y'||ch=='Y'){fseek(fp,0,2);luru();}if (!(ch=='y'||ch=='n'||ch=='Y'||ch=='N'))printf("请按要求输入!\n");}while (!(ch=='y'||ch=='n'||ch=='Y'||ch=='N'));fclose(fp);if (ch=='n'||ch=='N'){fan://goto标志printf("返回主菜单请按1,返回管理员通道请按2!\n");scanf("%d",&fanhui);if (fanhui==1)zhucaidan();if (fanhui==2)guanli();if (fanhui!=1&&fanhui!=2)printf("\t请按要求输入!\n");goto fan;};}}void xiugai()//******************************************************修改信息函数{int n,fanhui;system("cls");printf("\t\t请先找到要修改的航线!\n\n");chongxin://goto的标志do{printf("\t\t\t※*************************************※\n");printf("\t\t\t※※\n");printf("\t\t\t※请选择查询方式:※\n");printf("\t\t\t※航班号查询请按 1 ※\n");printf("\t\t\t※起点站查询请按 2 ※\n");printf("\t\t\t※终点站查询请按 3 ※\n");printf("\t\t\t※日期查询请按 4 ※\n");printf("\t\t\t※返回主菜单请按 5 ※\n");printf("\t\t\t※※\n");printf("\t\t\t※*************************************※\n");scanf("%d",&n);if (n!=1&&n!=2&&n!=3&&n!=4&&n!=5)printf("\t\t请按要求输入!谢谢!\n");}while(n!=1&&n!=2&&n!=3&&n!=4&&n!=5);if (n==1){FILE *fp=NULL;char hangbanhao[10];char ch;int i,cunzai=0;printf("\t\t请输入要查询的航班号:\n");scanf("%s",&hangbanhao);if ((fp=fopen("flight.txt","r+"))==NULL){printf("can not open flight.txt.\n");exit(0);}for(i=0;i<N;i++){fread(&airline[i],sizeof(airline[0]),1,fp);for (i=0;i<N;i++){if (strcmp(hangbanhao,airline[i].air_num)==0){printf("\t航班号飞机号起始站终点站日期总票数余票\n");printf("\t%-10s",airline[i].air_num);printf("%-10s",airline[i].plane_num);printf("%-10s",airline[i].start_place);printf("%-10s",airline[i].end_place);printf("%-14s",airline[i].date);printf("%-8d",airline[i].total);printf("%-8d",airline[i].left);printf("\n");cunzai=1;chongshu://goto标志printf("\t\t确定要修改吗?('y'or'n')\n");getchar();ch=getchar();if(ch=='y'||ch=='Y'){getchar();printf("\t\t请输入航班号:\n");gets(airline[i].air_num);printf("\t\t请输入飞机号:\n");gets(airline[i].plane_num);printf("\t\t请输入起始站:\n");gets(airline[i].start_place);printf("\t\t请输入终点站:\n");gets(airline[i].end_place);printf("\t\t请输入日期(****-**-**):\n");gets(airline[i].date);cuowu:printf("\t\t请输入总票数:\n");scanf("%d",&airline[i].total);printf("\t\t请输入余票数:\n");scanf("%d",&airline[i].left);if (airline[i].total<airline[i].left)//********防止输入总票数小于余票数{printf("输入错误!总票数小于余票数!请重新输入!\n");goto cuowu;};fseek(fp,i*(long)(sizeof(struct airline)),0);fwrite(&airline[i],sizeof(airline[0]),1,fp);printf("\t\t已经修改成功!\n");fclose(fp);printf("\n");hui://goto标志printf("返回主菜单请按1,返回管理员通道请按2!\n");scanf("%d",&fanhui);if (fanhui==1)zhucaidan();if (fanhui==2)guanli();if (fanhui!=1&&fanhui!=2){printf("\t请按要求输入!\n");goto hui;};}if(ch!='n'&&ch!='N'&&ch!='y'&&ch!='Y'){printf("\t\t请按要求输入,谢谢!\n");goto chongshu;}};}if (cunzai==0){printf("\t\t所查找的航班不存在,请重新选择查询方式!\n");goto chongxin;};if(ch=='n'||ch=='N'){fan://goto标志printf("返回主菜单请按1,返回管理员通道请按2!\n");scanf("%d",&fanhui);if (fanhui==1)zhucaidan();if (fanhui==2)guanli();if (fanhui!=1&&fanhui!=2){printf("\t请按要求输入!\n");goto fan;};}}if (n==2){FILE *fp=NULL;char qishizhan[10];char hangbanhao[10];char ch;int i,cunzai=0;printf("\t\t请输入要查询的起始站:\n");scanf("%s",&qishizhan);if ((fp=fopen("flight.txt","r+"))==NULL){printf("can not open flight.txt.\n");exit(0);}for(i=0;i<N;i++){fread(&airline[i],sizeof(airline[0]),1,fp);}for (i=0;i<N;i++){if (strcmp(qishizhan,airline[i].start_place)==0){printf("\t航班号飞机号起始站终点站日期票数余票\n");printf("\t%-10s",airline[i].air_num);printf("%-10s",airline[i].plane_num);printf("%-10s",airline[i].start_place);printf("%-10s",airline[i].end_place);printf("%-14s",airline[i].date);printf("%-8d",airline[i].total);printf("%-8d",airline[i].left);printf("\n");cunzai=1;}}if (cunzai==1){printf("\t\t请选择输入航班号:\n");scanf("%s",&hangbanhao);cunzai=0;}for (i=0;i<N;i++){if (strcmp(hangbanhao,airline[i].air_num)==0){printf("\t航班号飞机号起始站终点站日期总票数余票\n");printf("\t%-10s",airline[i].air_num);printf("%-10s",airline[i].plane_num);printf("%-10s",airline[i].start_place);printf("%-10s",airline[i].end_place);printf("%-14s",airline[i].date);printf("%-8d",airline[i].total);printf("%-8d",airline[i].left);printf("\n");cunzai=1;chongshu2://goto标志printf("\t\t确定要修改吗?('y'or'n')\n");getchar();ch=getchar();if(ch=='y'||ch=='Y'){getchar();printf("\t\t请输入航班号:\n");gets(airline[i].air_num);printf("\t\t请输入飞机号:\n");gets(airline[i].plane_num);printf("\t\t请输入起始站:\n");gets(airline[i].start_place);printf("\t\t请输入终点站:\n");gets(airline[i].end_place);printf("\t\t请输入日期(****-**-**):\n");gets(airline[i].date);printf("\t\t请输入总票数:\n");scanf("%d",&airline[i].total);printf("\t\t请输入余票数:\n");scanf("%d",&airline[i].left);fseek(fp,i*(long)(sizeof(struct airline)),0);fwrite(&airline[i],sizeof(airline[0]),1,fp);printf("\t\t已经修改成功!\n");fclose(fp);printf("\n");hui2://goto标志printf("返回主菜单请按1,返回管理员通道请按2!\n");scanf("%d",&fanhui);if (fanhui==1)zhucaidan();if (fanhui==2)guanli();if (fanhui!=1&&fanhui!=2){printf("\t请按要求输入!\n");goto hui2;};}if(ch!='n'&&ch!='N'&&ch!='y'&&ch!='Y'){printf("\t\t请按要求输入,谢谢!\n");goto chongshu2;}};}if (cunzai==0){printf("\t\t所查找的航班不存在,请重新选择查询方式!\n");goto chongxin;};if(ch=='n'||ch=='N'){fan2://goto标志printf("返回主菜单请按1,返回管理员通道请按2!\n");scanf("%d",&fanhui);if (fanhui==1)zhucaidan();if (fanhui==2)guanli();if (fanhui!=1&&fanhui!=2){printf("\t请按要求输入!\n");goto fan2;};}}if (n==3){FILE *fp=NULL;char zhongdianzhan[10];char hangbanhao[10];char ch;int i,cunzai=0;printf("\t\t请输入要查询的终点站:\n");scanf("%s",&zhongdianzhan);if ((fp=fopen("flight.txt","r+"))==NULL){printf("can not open flight.txt.\n");exit(0);}for(i=0;i<N;i++){fread(&airline[i],sizeof(airline[0]),1,fp);}for (i=0;i<N;i++){if (strcmp(zhongdianzhan,airline[i].end_place)==0){printf("\t航班号飞机号起始站终点站日期总票数余票\n");printf("\t%-10s",airline[i].air_num);printf("%-10s",airline[i].plane_num);printf("%-10s",airline[i].start_place);printf("%-10s",airline[i].end_place);printf("%-14s",airline[i].date);printf("%-8d",airline[i].total);printf("%-8d",airline[i].left);printf("\n");cunzai=1;}}if (cunzai==1){printf("\t\t请选择输入航班号:\n");scanf("%s",&hangbanhao);cunzai=0;}for (i=0;i<N;i++){if (strcmp(hangbanhao,airline[i].air_num)==0){printf("\t航班号飞机号起始站终点站日期总票数余票\n");printf("\t%-10s",airline[i].air_num);printf("%-10s",airline[i].plane_num);printf("%-10s",airline[i].start_place);printf("%-10s",airline[i].end_place);printf("%-14s",airline[i].date);printf("%-8d",airline[i].total);printf("%-8d",airline[i].left);printf("\n");cunzai=1;chongshu3://goto标志printf("\t\t确定要修改吗?('y'or'n')\n");getchar();ch=getchar();if(ch=='y'||ch=='Y'){getchar();printf("\t\t请输入航班号:\n");gets(airline[i].air_num);printf("\t\t请输入飞机号:\n");gets(airline[i].plane_num);printf("\t\t请输入起始站:\n");gets(airline[i].start_place);printf("\t\t请输入终点站:\n");gets(airline[i].end_place);printf("\t\t请输入日期(****-**-**):\n");gets(airline[i].date);printf("\t\t请输入总票数:\n");scanf("%d",&airline[i].total);printf("\t\t请输入余票数:\n");scanf("%d",&airline[i].left);fseek(fp,i*(long)(sizeof(struct airline)),0);fwrite(&airline[i],sizeof(airline[0]),1,fp);printf("\t\t已经修改成功!\n");fclose(fp);printf("\n");hui3://goto标志printf("返回主菜单请按1,返回管理员通道请按2!\n");scanf("%d",&fanhui);if (fanhui==1)zhucaidan();if (fanhui==2)guanli();if (fanhui!=1&&fanhui!=2){printf("\t请按要求输入!\n");goto hui3;};}if(ch!='n'&&ch!='N'&&ch!='y'&&ch!='Y'){printf("\t\t请按要求输入,谢谢!\n");goto chongshu3;};}}if (cunzai==0){printf("\t\t所查找的航班不存在,请重新选择查询方式!\n");goto chongxin;};if(ch=='n'||ch=='N'){fan3://goto标志printf("返回主菜单请按1,返回管理员通道请按2!\n");scanf("%d",&fanhui);if (fanhui==1)zhucaidan();if (fanhui==2)guanli();if (fanhui!=1&&fanhui!=2){printf("\t请按要求输入!\n");goto fan3;};}}if (n==4){FILE *fp=NULL;char riqi[10];char hangbanhao[10];char ch;int i,cunzai=0;printf("\t\t请输入要查询的日期(****-**-**):\n");scanf("%s",&riqi);if ((fp=fopen("flight.txt","r+"))==NULL){printf("can not open flight.txt.\n");exit(0);}for(i=0;i<N;i++){fread(&airline[i],sizeof(airline),1,fp);}for (i=0;i<N;i++){if (strcmp(riqi,airline[i].date)==0){printf("\t航班号飞机号起始站终点站日期总票数余票\n");printf("\t%-10s",airline[i].air_num);printf("%-10s",airline[i].plane_num);printf("%-10s",airline[i].start_place);printf("%-10s",airline[i].end_place);printf("%-14s",airline[i].date);printf("%-8d",airline[i].total);printf("%-8d",airline[i].left);printf("\n");cunzai=1;}}if (cunzai=1){printf("\t\t请选择输入航班号:\n");scanf("%s",&hangbanhao);cunzai=0;}for (i=0;i<N;i++){if (strcmp(hangbanhao,airline[i].air_num)==0){printf("\t航班号飞机号起始站终点站日期总票数余票\n");printf("\t%-10s",airline[i].air_num);printf("%-10s",airline[i].plane_num);printf("%-10s",airline[i].start_place);printf("%-10s",airline[i].end_place);printf("%-14s",airline[i].date);printf("%-8d",airline[i].total);printf("%-8d",airline[i].left);printf("\n");cunzai=1;chongshu4://goto标志printf("\t\t确定要修改吗?('y'or'n')\n");getchar();ch=getchar();if(ch=='y'||ch=='Y'){getchar();printf("\t\t请输入航班号:\n");gets(airline[i].air_num);printf("\t\t请输入飞机号:\n");gets(airline[i].plane_num);printf("\t\t请输入起始站:\n");gets(airline[i].start_place);printf("\t\t请输入终点站:\n");gets(airline[i].end_place);printf("\t\t请输入日期(****-**-**):\n");gets(airline[i].date);printf("\t\t请输入总票数:\n");scanf("%d",&airline[i].total);printf("\t\t请输入余票数:\n");scanf("%d",&airline[i].left);fseek(fp,i*(long)(sizeof(struct airline)),0);fwrite(&airline[i],sizeof(airline[0]),1,fp);printf("\t\t已经修改成功!\n");fclose(fp);printf("\n");hui4://goto标志printf("返回主菜单请按1,返回管理员通道请按2!\n");scanf("%d",&fanhui);if (fanhui==1)zhucaidan();if (fanhui==2)guanli();if (fanhui!=1&&fanhui!=2){printf("\t请按要求输入!\n");goto hui4;};}if(ch!='n'&&ch!='N'&&ch!='y'&&ch!='Y'){printf("\t\t请按要求输入,谢谢!\n");goto chongshu4;};}}if (cunzai==0){printf("\t\t所查的航班不存在,请重新选择查询方式!\n");goto chongxin;};if(ch=='n'||ch=='N'){fan4://goto标志printf("返回主菜单请按1,返回管理员通道请按2!\n");scanf("%d",&fanhui);if (fanhui==1)zhucaidan();if (fanhui==2)guanli();if (fanhui!=1&&fanhui!=2){printf("\t请按要求输入!\n");goto fan4;};}}if (n==5)zhucaidan();if (n!=1&&n!=2&&n!=3&&n!=4&&n!=5){printf("\t\t输入错误!请按要求输入!\n");goto chongxin;};}voidshanchu()//********************************************************************** ********删除航线信息{int n,fanhui;system("cls");chongxin://goto的标志printf("\t\t请先找到要删除的航线!\n\n");do{printf("\t\t\t※*************************************※\n");printf("\t\t\t※※\n");printf("\t\t\t※请选择查询方式:※\n");printf("\t\t\t※航班号查询请按 1 ※\n");printf("\t\t\t※起始站查询请按 2 ※\n");printf("\t\t\t※终点站查询请按 3 ※\n");printf("\t\t\t※日期查询请按 4 ※\n");printf("\t\t\t※返回菜单请按 5 ※\n");printf("\t\t\t※※\n");printf("\t\t\t※*************************************※\n");scanf("%d",&n);if (n!=1&&n!=2&&n!=3&&n!=4&&n!=5)printf("请按要求输入!谢谢!\n");}while(n!=1&&n!=2&&n!=3&&n!=4&&n!=5);if (n==1){FILE *fp=NULL;char hangbanhao[10];char ch;int i,j,k,l=0,cunzai=0;printf("\t\t请输入要查询的航班号:\n");scanf("%s",&hangbanhao);if ((fp=fopen("flight.txt","r+"))==NULL){printf("can not open flight.txt.\n");exit(0);}for(i=0;i<N;i++){fread(&airline[i],sizeof(airline[0]),1,fp);}while(isdigit(*airline[l].air_num)){l++;}for (i=0;i<N;i++){if (strcmp(hangbanhao,airline[i].air_num)==0){j=i+1;printf("\t航班号飞机号起始站终点站日期总票数余票\n");printf("\t%-10s",airline[i].air_num);printf("%-10s",airline[i].plane_num);printf("%-10s",airline[i].start_place);printf("%-10s",airline[i].end_place);printf("%-14s",airline[i].date);printf("%-8d",airline[i].total);printf("%-8d",airline[i].left);printf("\n");cunzai=1;chongshu:printf("\t\t确定要删除吗?('y'or'n') \n");getchar();ch=getchar();if(ch=='y'||ch=='Y'){fseek(fp,j*(long)(sizeof(struct airline)),0);for(k=j;k<l;k++){fread(&airline[k-1],sizeof(airline[0]),1,fp);}fclose(fp);if ((fp=fopen("flight.txt","w"))==NULL){printf("can not open flight.txt.\n");exit(0);}for(j=0;j<l-1;j++){fwrite(&airline[j],sizeof(airline[0]),1,fp);}printf("\t\t已经删除成功!\n");fclose(fp);printf("\n");fan://goto标志printf("返回主菜单请按1,返回管理员通道请按2!\n");scanf("%d",&fanhui);if (fanhui==1)zhucaidan();if (fanhui==2)guanli();if (fanhui!=1&&fanhui!=2){printf("\t请按要求输入!\n");goto fan;};}if(ch=='n'||ch=='N')shanchu();if(ch!='n'&&ch!='N'&&ch!='y'&&ch!='Y'){printf("\t\t请按要求输入,谢谢!\n");goto chongshu;};}}if (cunzai==0){printf("\t\t所查找的航班不存在,请重新选择查询方式!\n");goto chongxin;};}if (n==2){FILE *fp=NULL;char qishizhan[10];char hangbanhao[10];char ch;int i,j,k,l=0,cunzai=0;printf("\t\t请输入要查询的起始站:\n");scanf("%s",&qishizhan);if ((fp=fopen("flight.txt","r+"))==NULL){printf("can not open flight.txt.\n");exit(0);}for(i=0;i<N;i++){fread(&airline[i],sizeof(airline[0]),1,fp);}while(isdigit(*airline[l].air_num)){l++;}for (i=0;i<N;i++){if (strcmp(qishizhan,airline[i].start_place)==0){printf("\t航班号飞机号起始站终点站日期总票数余票\n");printf("\t%-10s",airline[i].air_num);printf("%-10s",airline[i].plane_num);printf("%-10s",airline[i].start_place);printf("%-10s",airline[i].end_place);printf("%-14s",airline[i].date);printf("%-8d",airline[i].total);printf("%-8d",airline[i].left);printf("\n");cunzai=1;}}if (cunzai==1){printf("\t\t请选择输入航班号:\n");scanf("%s",&hangbanhao);cunzai=0;}for (i=0;i<N;i++){if (strcmp(hangbanhao,airline[i].air_num)==0){j=i+1;printf("\t航班号飞机号起始站终点站日期总票数余票\n");printf("\t%-10s",airline[i].air_num);printf("%-10s",airline[i].plane_num);printf("%-10s",airline[i].start_place);printf("%-10s",airline[i].end_place);printf("%-14s",airline[i].date);printf("%-8d",airline[i].total);printf("%-8d",airline[i].left);printf("\n");cunzai=1;chongshu2://goto标志printf("\t\t确定要删除吗?('y'or'n') \n");getchar();ch=getchar();if(ch=='y'||ch=='Y'){fseek(fp,j*(long)(sizeof(struct airline)),0);for(k=j;k<l;k++){fread(&airline[k-1],sizeof(airline[0]),1,fp);}fclose(fp);if ((fp=fopen("flight.txt","w"))==NULL){printf("can not open flight.txt.\n");exit(0);}for(j=0;j<l-1;j++){fwrite(&airline[j],sizeof(airline[0]),1,fp);}printf("\t\t已经删除成功!\n");fclose(fp);printf("\n");fan2://goto标志printf("返回主菜单请按1,返回管理员通道请按2!\n");scanf("%d",&fanhui);if (fanhui==1)zhucaidan();if (fanhui==2)guanli();if (fanhui!=1&&fanhui!=2){printf("\t请按要求输入!\n");goto fan2;};}if(ch=='n'||ch=='N')shanchu();if(ch!='n'&&ch!='N'&&ch!='y'&&ch!='Y'){printf("\t\t请按要求输入,谢谢!\n");goto chongshu2;};}}if (cunzai==0){printf("\t\t所查找的航班不存在,请重新选择查询方式!\n");goto chongxin;};}if (n==3){FILE *fp=NULL;char zhongdianzhan[10];char hangbanhao[10];char ch;int i,j,k,l=0,cunzai=0;printf("\t\t请输入要查询的终点站:\n");scanf("%s",&zhongdianzhan);if ((fp=fopen("flight.txt","r+"))==NULL){printf("can not open flight.txt.\n");。
#include 〈stdio、h>#include<stdlib、h〉#include<string、h〉#define NOD struct plane_liststruct plane{char number[10];char start[10];char arrive [10];chardate[10];char starttime[10];chararrivingtime[10];char price[10];charmodel[10];};NOD{char number [10];char start[10];char arrive [10];char date[10];charstarttime[10];char arrivingtime[10];char price[10];charmodel[10];NOD*next;};FILE *fp;/*由文件中得数据生成一个飞机航班得链表,如果文件不存在,则就是一个空链表*/ NOD*load(char planename[]){NOD *p,*q,*head;structplaneper;p=(NOD *)malloc(sizeof(NOD));q=head=NULL;if((fp=fopen(planename,"rb"))==NULL)ﻩreturn head;else{while(!feof(fp)){if(fread(&per,sizeof(struct plane),1,fp)==1){p=(NOD*)malloc(sizeof(NOD));strcpy(p->number,per、number);strcpy(p->start,per、start);strcpy(p->arrive,per、arrive);strcpy(p—>date,per、date);strcpy(p->starttime,per、starttime);ﻩstrcpy(p—>arrivingtime,per、arrivingtime);strcpy(p—>price,per、price);strcpy(p-〉model,per、model);ﻩhead=p;p—〉next=q;q=head;}}}fclose(fp);return(head);}/*输入*/NOD *insert(NOD *head){NOD *temp,*p;p=head;temp=(NOD*)malloc(sizeof(NOD));printf(”\n\t请输入航班号:”);scanf("%s",temp—>number);printf("\n\t请输入起点站:");scanf("%s”,temp—>start);printf(”\n\t请输入终点站:");scanf("%s”,temp->arrive);printf(”\n\t请输入起飞时间:”);scanf("%s”,temp->starttime);printf("\n\t请输入到达时间:”);scanf(”%s”,temp->arrivingtime);printf("\n\t请输入班期:”);scanf("%s",temp—〉date);printf("\n\t请输入票价:");scanf(”%s",temp—〉price);printf("\n\t请输入航班型号:");scanf(”%s",temp—>model);head=temp;temp—〉next=p;return head;}/*保存*/void save(NOD *head,char[]){NOD*p;structplane per;if((fp=fopen(,"wb”))==NULL){printf("文件无法写入");exit(0);}else{p=head;while(p!=NULL){ strcpy(per、number,p—〉number);strcpy(per、start,p—〉start);ﻩstrcpy(per、arrive,p->arrive);strcpy(per、date,p—>date);strcpy(per、starttime,p-〉starttime);ﻩstrcpy(per、arrivingtime,p—〉arrivingtime);strcpy(per、price,p->price);strcpy(per、model,p-〉model);if(fwrite(&per,sizeof(structplane),1,fp)!=1)ﻩ{printf("文件不能写入数据,请检查后重新运行、\n");ﻩexit(0);ﻩ}p=p—>next;}fclose(fp);}}/*显示*/void display(NOD*head){ NOD *p;p=head;while(p!=NULL){ printf("航班号:%s\n”,p—>number);printf(”起点站:%s\n”,p-〉start);printf(”终点站:%s\n",p-〉arrive);printf("班期:%s\n”,p-〉date);printf("起飞时间:%s\n”,p->starttime);ﻩprintf("到达时间:%s\n",p->arrivingtime);printf("票价:%s\n”,p—>price);printf(”飞机型号:%s\n”,p-〉model);p=p-〉next;}}/*航班号查找*/void finda(NOD*head){ NOD*p;char number[10];printf("请输入查找航班得编号:”);scanf("%s”,number);p=head;while (p!=NULL){ if(strcmp(number,p—〉number)==0){printf("航班号:%s\n",p—>number);printf(”起点站:%s\n”,p—>start);printf(”终点站:%s\n",p->arrive);printf("班期:%s\n",p->date);printf(”起飞时间:%s\n”,p->starttime);printf(”到达时间:%s\n",p-〉arrivingtime);printf(”票价:%s\n",p—>price);printf("飞机型号:%s\n”,p-〉model);break;}elseﻩp=p->next;}if(p==NULL)ﻩprintf("\n\t查无此航班\n");}/*起点站查找*/voidfindb(NOD *head){NOD *p;char start[10];printf("请输入查找航班得起点站:");scanf(”%s”,start);p=head;while(p!=NULL){if(strcmp(start,p-〉start)==0){printf(”航班号:%s\n",p->number);printf(”起点站:%s\n",p—〉start);printf(”终点站:%s\n",p->arrive);printf(”班期:%s\n",p—〉date);printf("起飞时间:%s\n",p—〉starttime);printf(”到达时间:%s\n",p->arrivingtime);printf("票价:%s\n”,p->price);printf("飞机型号:%s\n",p->model);ﻩbreak;}elseﻩp=p->next;}if(p==NULL)printf("\n\t查无此航班\n”);}/*终点站查找*/void findc(NOD*head){NOD *p;char arrive[10];printf("请输入查找航班得终点站:”);scanf("%s”,arrive);p=head;while (p!=NULL){if(strcmp(arrive,p->arrive)==0){printf(”航班号:%s\n",p->number);printf(”起点站:%s\n",p—>start);printf("终点站:%s\n",p—>arrive);printf("班期:%s\n",p->date);printf("起飞时间:%s\n",p->starttime);printf("到达时间:%s\n”,p-〉arrivingtime);printf(”票价:%s\n",p—〉price);printf("飞机型号:%s\n",p->model);break;}elseﻩp=p—>next;}if(p==NULL)printf("\n\t查无此航班\n");}/*起飞时间查找*/void findd(NOD *head){ NOD *p;char starttime[10];printf("请输入查找航班得起飞时间:");scanf("%s”,starttime);p=head;while(p!=NULL){if(strcmp(starttime,p->starttime)==0){printf("航班号:%s\n",p->number);printf("起点站:%s\n",p—〉start);printf("终点站:%s\n”,p->arrive);printf(”班期:%s\n",p—〉date);printf("起飞时间:%s\n",p-〉starttime);printf(”到达时间:%s\n",p—>arrivingtime);printf("票价:%s\n",p—〉price);printf("飞机型号:%s\n”,p->model);ﻩbreak;}elsep=p-〉next;}if(p==NULL)printf("\n\t查无此航班\n");}/*到达时间查找*/void finde(NOD*head){NOD *p;chararrivingtime[10];printf(”请输入查找航班得到达时间:");scanf(”%s",arrivingtime);p=head;while (p!=NULL){if(strcmp(arrivingtime,p—〉arrivingtime)==0){printf("航班号:%s\n”,p-〉number);printf("起点站:%s\n",p—〉start);printf(”终点站:%s\n”,p->arrive);printf("班期:%s\n",p-〉date);printf("起飞时间:%s\n”,p—>starttime);ﻩprintf("到达时间:%s\n",p->arrivingtime);printf("票价:%s\n",p-〉price);printf("飞机型号:%s\n",p—〉model);break;}elseﻩp=p—〉next;}if(p==NULL)printf(”\n\t查无此航班\n”);}/*删除*/NOD *dele(NOD *head){NOD *p,*q;char number[5];printf(":请输入要删除得航班编号”);scanf("%s”,number);p=q=head;while(p!=NULL){if(strcmp(number,p->number)==0){ﻩif(head==p)ﻩﻩhead=p—>next;ﻩelseq->next=p->next;ﻩfree(p);ﻩbreak;}else{q=p;p=p—>next;}}if(p==NULL)printf(”\n\t查无此航班\n”);returnhead;}/*主函数*/voidmain(){ NOD*head;char fnum[10];int choise;printf("\n\t欢迎光临航班查询系统:");scanf("%s”,fnum);head=load(fnum);while(1){printf("\n\t\t 航班信息检索与查询\n");printf("\t\t********************************\n”);printf("\t\t1、航班号查找\n”);printf("\t\t 2、起点站查找\n");printf(”\t\t 3、终点站查找\n");printf("\t\t4、起飞时间查找\n");printf("\t\t5、到达时间查找\n");printf("\t\t6、航班号删除\n");printf(”\t\t7、增加新航班\n");printf("\t\t 8、显示所有航班\n");printf("\t\t 9、存盘并退出\n”);printf(”\n\t请选择1—9:");scanf("%d”,&choise);switch(choise){ case 1:finda(head);break;case 2:findb(head);break;case 3:findc(head);break;case4:findd(head);break;case 5:finde(head);break;case 6:head=dele(head);break;ﻩcase 7:head=insert(head);break;ﻩcase 8:display(head);break;ﻩ case9:save(head,fnum);exit(0);default:printf("输入错误,重新输入\n");ﻩ }} }。
c语⾔程序设计飞机,C语⾔程序设计――飞机订票系统《C语⾔程序设计――飞机订票系统》由会员分享,可在线阅读,更多相关《C语⾔程序设计――飞机订票系统(7页珍藏版)》请在⼈⼈⽂库⽹上搜索。
1、C语⾔程序设计飞机订票系统代码如下:”#include stdio.h#include stdlib.h#include string.h#define LEN sizeof (struct plane)#define MAX 10;struct planechar destination12;char num10;char time12;int price;int amount;typedef struct plane PLANE;PLANE a100;void menu();void input();void search();void preserve();void planeadd()。
2、;void delplane();void main()system(cls);menu();void menu()char *menu = * 欢迎进⼊飞机订票系统*, a:输⼊航线 , b:查询航线 , c:退订票系统 , d:追加航线 , e:删除航线 , f: 退出 ,* ;int i;char NO;int quit = 0;dosystem(cls);for (i = 0; i9; i+)printf(n%s,menui);printf(n请输⼊服务代码a,b,c,d,e或fn);NO = getchar();switch (NO)casea: input(); break;ca。
3、seb: search(); break;casec: preserve(); break;cased: planeadd(); break;casee: delplane(); break;casef: quit = 1; break; while (!quit);void input()int i, n;FILE *fp;system(cls);if (fp = fopen(D:file, wb) = NULL)printf(error!n); exit(0);printf(n请输⼊航班总数n:);scanf(%d, &n);printf(n请按下⾯提⽰输⼊航班信息:起点站:沈阳);for。
#include<stdio.h> //标准输入、输出头文件#include<string.h> //包含字符串函数处理头文件#include<process.h> //包含access函数的头文件#include<io.h>#include<stdlib.h>#include<windows.h>#include<conio.h>#define N 9999 //定义最多的航班数#define PRINT "%d\t\t%s\t\t%s\t\t星期%s\t\t%d\n ",s[i].num,s[i].start,s[i].over,s[i].time,s[i].count //宏定义输出格式struct air //定义结构体数组{int num; //定义航班号char start[20]; //航班起始站char over[20]; //终点站char time[10]; //飞行时间int count; //机票数量}s[N];int i,a,m=0; //定义全局变量char ii[10];void add(); //函数声明增加航班信息函数void print(); //显示航班信息void search(); //查找航班信息void dingpiao(); //订票业务void tuipiao(); //退票void read(); //读取文件void save(); //保存文件void output(); //输出格式void paixu(); //航班排序void chushihua(); //系统初始化void build(); //建立数据文件void paixu1(); //按航班号从小到大排序void paixu2(); //从大到小int head (); //进入订票系统int main() //主函数{int j;system("color b0");chushihua(); //系统初始化判断是否存在原始数据文件system("cls");head(); //打印出系统主界面system("cls");do{printf("=============================================== ================================= ");printf("1.增加航班信息\n""\t2.浏览航班信息\n""\t\t3.查找航班信息(按航班号)\t\t\n""\t\t\t4.航班排序(按航班号)\n""\t\t\t\t5.订票业务\n""\t\t\t\t\t6.退票业务\n""\t\t\t\t\t\t0.退出\n");printf("============================================ ==================================== ");printf("请在0-6中选择以回车键结束:");scanf("%d",&j);switch(j){case 1: add(); system("cls"); //调用增加航班函数break;case 2:print(); s ystem("cls");//调用显示模块break;case 3:search();system("cls"); //调用查找模块break;case 4:paixu(); system("cls"); //调用排序函数break;case 5:dingpiao();system("cls"); //调用订票模块break;case 6:tuipiao();system("cls"); //调用退票模块break;case 0: //退出系统save();system("cls");printf("\n\n\n\t\t\t\t\n\n\t谢谢使用,再见!");printf("\n\n\n\n\n\n\n\n\n\n\n\n\n");break;}}while(j!=0); //判断是否调用其他函数}void chushihua() //定义系统初始化函数{if(access("hangban.dat",0)){build();}elseread();}void build() //定义建立数据文件函数{FILE *fp; //定义文件指针if((fp=fopen("hangban.dat","wb"))==NULL) //打开文件并判定是否出错{printf("创建文件失败! "); //打印出错提示getchar();return;}printf("请依次输入航班信息(以回车键结束):\n"); //打印提示信息printf("-------------------------------------------------------------------------- \n");for(i=0;i<N;i++){printf("请输入航班号: ");scanf("%d",&s[i].num); //输入航班号printf("请输入起始站: ");scanf("%s",s[i].start); //输入起始站printf("请输入终点站: ");scanf("%s",s[i].over); //输入终点站printf("请输入时间(星期几): ");scanf("%s",s[i].time); //输入时间printf("请输入机票数: ");scanf("%d",&s[i].count); //输入机票数fwrite(&s[i],sizeof(struct air),1,fp);m++;printf("添加完毕,是否继续添加?请键入y或n以回车键结束:");scanf("%s",ii);if(strcmp(ii,"y")!=0) //判断是否继续添加航班信息{fclose(fp); //关闭文件return;}}}void read() //定义读取文件函数{FILE *fp;if((fp=fopen("hangban.dat","r"))==NULL){printf("创建文件失败! ");getchar();return;}i=0;while(!feof(fp)){fread(&s[i],sizeof(struct air),1,fp); //逐块读取数据i++;m++; //计算存在航班数}m--;fclose(fp);printf("请稍候,正在初始化");for(a=0;a<3;a++){printf(".");Sleep(600);}printf("\n");}void save() //定义保存函数{FILE *fp;if((fp=fopen("hangban.dat","wb"))==NULL) {printf("创建文件失败! ");getchar();return;}for(i=0;i<m;i++) //逐块保存数据fwrite(&s[i],sizeof(struct air),1,fp);fclose(fp);printf("正在保存数据并退出");for(a=0;a<3;a++){printf(".");Sleep(600);}printf("\n");printf("\n");}void add() //定义增加航班信息函数{do{printf("请依次输入您要增加的航班信息(以回车键结束): \n"); //打印提示信息printf("-------------------------------------------------------------------------- \n");printf("请输入航班号: ");scanf("%d",&s[m].num); //读取航班号printf("请输入起始站: ");scanf("%s",s[m].start); //读取起始站printf("请输入终点站: ");scanf("%s",s[m].over); //读取终点站printf("请输入时间(星期几): ");scanf("%s",s[m].time); //读取时间printf("请输入机票数: ");scanf("%d",&s[m].count); //读取机票数m++;printf("添加完毕,是否继续添加?请键入y或n以回车键结束:");scanf("%s",ii);}while(!strcmp(ii,"y")); //判断是否继续添加printf("正在保存,请稍候");for(a=0;a<5;a++){printf(".");Sleep(600);}printf("\n");}void output() //定义输出格式函数{printf("航班号\t\t起始站\t\t终点站\t\t时间\t\t机票数\n"); //信息标for(i=0;i<m;i++)printf(PRINT);//打印出信息}void print() //定义显示航班信息函数{printf("正在加载,请稍候");for(a=0;a<5;a++){printf(".");Sleep(400);}printf("\n");system("cls");printf("\n目前我们有如下航班:\n\n");output(); //调用输出格式函数printf("\n请按回车键返回上层菜单");getchar();getchar();void search() //定义查询函数{int n;do{printf("\n请输入航班号:");scanf("%d",&n); //输入查询的航班号printf("正在查询");for(a=0;a<5;a++){printf(".");Sleep(400);}printf("\n");for(i=0;i<m;i++){if(s[i].num==n) //按航班号判定输出条件{printf("\n您所查找的航班信息为:\n ");printf("航班号\t\t起始站\t\t终点站\t\t时间\t\t机票数\n\n");printf(PRINT); //显示信息printf("\n查询完毕,按回车键继续");getchar();getchar();return;}}printf("\n对不起,没有您需要的信息!\n ");printf("是否重新查找?请键入y或n以回车键结束");scanf("%s",ii);}while(!strcmp(ii,"y"));//判定是否重新查找}void dingpiao() //定义订票业务函数{int n,x;char a[10]="y";do{search(); //调用查询模块if(!strcmp(ii,"n")){printf("对不起!没有找到您所需要的航班,所以不能订票。
#include<stdio.h> //标准输入、输出头文件#include<string.h> //包含字符串函数处理头文件#include<process.h> //包含access函数的头文件#define N 9999 //定义最多的航班数#define PRINT "%d\t\t%s\t\t%s\t\t星期%s\t\t%d\n ",s[i].num,s[i].start,s[i].over,s[i].time,s[i].count //宏定义输出格式struct air //定义结构体数组{int num; //定义航班号char start[20]; //航班起始站char over[20]; //终点站char time[10]; //飞行时间int count; //机票数量}s[N];int i,m=0; //定义全局变量char ii[10];void add(); //函数声明增加航班信息函数void print(); //显示航班信息void search(); //查找航班信息void dingpiao(); //订票业务void tuipiao(); //退票void read(); //读取文件void save(); //保存文件void output(); //输出格式void paixu(); //航班排序void chushihua(); //系统初始化void build(); //建立数据文件void paixu1(); //按航班号从小到大排序void paixu2(); //从大到小void main() //主函数{int j;chushihua(); //系统初始化判断是否存在原始数据文件printf(" 欢迎使用飞机订票系统\n"); //打印出系统主界面do{printf("============================================================ ==================== ");printf("1.增加航班信息\n""\t2.浏览航班信息\n""\t\t3.查找航班信息(按航班号)\t\t╮(╯_╰)╭\n""\t\t\t4.航班排序(按航班号)\n""\t\t\t\t5.订票业务\n""\to(︶︿︶)o\t\t\t6.退票业务\n""\t\t\t\t\t\t0.退出\n");printf("======================================================== ======================== ");printf("请在0-6中选择以回车键结束:");scanf("%d",&j);switch(j){case 1: add(); //调用增加航班函数break;case 2:print(); //调用显示模块break;case 3:search(); //调用查找模块break;case 4:paixu(); //调用排序函数break;case 5:dingpiao(); //调用订票模块break;case 6:tuipiao(); //调用退票模块break;case 0: //退出系统save();printf("谢谢使用,再见!");break;}}while(j!=0); //判断是否调用其他函数}void chushihua() //定义系统初始化函数{if(access("hangban.dat",0)){build();}elseread();}void build() //定义建立数据文件函数{FILE *fp; //定义文件指针if((fp=fopen("hangban.dat","wb"))==NULL) //打开文件并判定是否出错{printf("创建文件失败! "); //打印出错提示getchar();return;}printf("请依次输入航班信息(以回车键结束):\n"); //打印提示信息printf("-------------------------------------------------------------------------- \n");for(i=0;i<N;i++){printf("请输入航班号: ");scanf("%d",&s[i].num); //输入航班号printf("请输入起始站: ");scanf("%s",s[i].start); //输入起始站printf("请输入终点站: ");scanf("%s",s[i].over); //输入终点站printf("请输入时间(星期几): ");scanf("%s",s[i].time); //输入时间printf("请输入机票数: ");scanf("%d",&s[i].count); //输入机票数fwrite(&s[i],sizeof(struct air),1,fp);m++;printf("添加完毕,是否继续添加?请键入y或n以回车键结束:");scanf("%s",ii);if(strcmp(ii,"y")!=0) //判断是否继续添加航班信息{fclose(fp); //关闭文件return;}}}void read() //定义读取文件函数{FILE *fp;if((fp=fopen("hangban.dat","r"))==NULL){printf("创建文件失败! ");getchar();return;}i=0;while(!feof(fp)){fread(&s[i],sizeof(struct air),1,fp); //逐块读取数据i++;m++; //计算存在航班数}m--;fclose(fp);}void save() //定义保存函数{FILE *fp;if((fp=fopen("hangban.dat","wb"))==NULL){printf("创建文件失败! ");getchar();return;}for(i=0;i<m;i++) //逐块保存数据fwrite(&s[i],sizeof(struct air),1,fp);fclose(fp);}void add() //定义增加航班信息函数{do{printf("请依次输入您要增加的航班信息(以回车键结束): \n"); //打印提示信息printf("-------------------------------------------------------------------------- \n");printf("请输入航班号: ");scanf("%d",&s[m].num); //读取航班号printf("请输入起始站: ");scanf("%s",s[m].start); //读取起始站printf("请输入终点站: ");scanf("%s",s[m].over); //读取终点站printf("请输入时间: ");scanf("%s",s[m].time); //读取时间printf("请输入机票数: ");scanf("%d",&s[m].count); //读取机票数m++;printf("添加完毕,是否继续添加?请键入y或n以回车键结束:");scanf("%s",ii);}while(!strcmp(ii,"y")); //判断是否继续添加}void output() //定义输出格式函数{printf("航班号\t\t起始站\t\t终点站\t\t时间\t\t机票数\n"); //信息标题for(i=0;i<m;i++)printf(PRINT);//打印出信息}void print() //定义显示航班信息函数{printf("\n目前我们有如下航班:\n");output(); //调用输出格式函数printf("\n请按回车键返回上层菜单");getchar();getchar();}void search() //定义查询函数{int n;do{printf("\n请输入航班号:");scanf("%d",&n); //输入查询的航班号for(i=0;i<m;i++){if(s[i].num==n) //按航班号判定输出条件{printf("\n您所查找的航班信息为:\n ");printf("航班号\t\t起始站\t\t终点站\t\t时间\t\t机票数\n\n");printf(PRINT); //显示信息printf("\n查询完毕,按回车键继续");getchar();getchar();return;}}printf("\n对不起,没有您需要的信息!\n ");printf("是否重新查找?请键入y或n以回车键结束");scanf("%s",ii);}while(!strcmp(ii,"y"));//判定是否重新查找}void dingpiao() //定义订票业务函数{int n;char a[10]="y";do{search(); //调用查询模块if(!strcmp(ii,"n")){printf("对不起!没有找到您所需要的航班,所以不能订票。
飞机场管理程序(c语言源代码)#include "stdio.h"#include "stdlib.h"#include "time.h"typedef struct node{int oiltime;int waittime;struct node *next;}planenode;planenode *airhead,*landhead;int maxlen,maxoil,maxwait,maxtime;int n1=0,n2=0;int Random(int,int);planenode* intialize(void);void Print(int);void planedown(void);void planeup(void);void emergency(planenode *);int running(void);void loading(void);int main(){printf("欢迎进入飞机场管理系统\n");printf("loading...\n");srand((unsigned)time(NULL));loading();printf("谢谢使用!\n\n");return 0;}void loading(void){int time=0,flag=1;printf("请您输入模拟结束时间:");scanf("%d",&maxtime);getchar(); printf("\n请您输入飞机队列的最大容量:"); scanf("%d",&maxlen);getchar();printf("\n请您输入飞机最大油量:"); scanf("%d",&maxoil);getchar();printf("\n请您输入飞机最长等待时间:"); scanf("%d",&maxwait);getchar(); airhead=intialize();landhead=intialize();while((time<=maxtime)&&flag){Print(time);flag=running();getchar();time++;}}int running(void){planenode *p,*q;int i;if(airhead->next==NULL){if(airhead->oiltime==0){printf("油量不足,紧急迫降!\n");return 0;}else if(airhead->waittime==0){printf("等待时间已到,飞机成功降落!\n"); return 0;}}else if(airhead->next!=NULL){for(p=airhead,i=0;p!=NULL;p=p->next) if(p->oiltime==0){i++;q=p;}if(i>1){printf("多架飞机油量不足,系统崩溃!\n"); return 0;}else if(i==1){if(q!=airhead)emergency(q);elseplanedown();}else if(airhead->waittime==0)planedown();}else if(landhead->waittime==0)planeup();airhead->waittime--;for(p=airhead;p!=NULL;p=p->next)p->oiltime--;return 1;}planenode* intialize(void){planenode *p,*head;int i;i=Random(1,maxlen);head=(planenode *)malloc(sizeof(planenode)); head->oiltime=Random(1,maxoil);head->waittime=Random(1,maxwait);head->next=NULL;p=head;while(--i){p->next=(planenode *)malloc(sizeof(planenode)); p=p->next;p->oiltime=Random(1,maxoil);p->waittime=0;p->next=NULL;}return (head);}void Print(int time){int i,j;planenode *p;printf("**********time%d***********\n",time); printf("空中队列信息\n");printf("编号\t剩油量\n");for(p=airhead,i=1;p!=NULL;p=p->next)printf("%4d\t%4d\n",i++,p->oiltime);printf("\n机场队列信息\n");printf("编号\t剩油量\n");for(p=landhead,j=1;p!=NULL;p=p->next) printf("%4d\t%4d\n",j++,p->oiltime);printf("空中队列平均等待时间:%f\n",(float)n1/i); printf("机场队列平均等待时间:%f\n",(float)n2/j); n1+=i;n2+=j;}void planedown(){planenode *p;p=airhead;airhead=airhead->next;airhead->waittime=Random(1,maxwait);free(p);printf("等待时间已到,飞机成功降落!\n");}void planeup(){planenode *p;p=landhead;landhead=landhead->next;landhead->waittime=Random(1,maxwait); free(p);printf("等待时间已到,飞机成功起飞!\n");}void emergency(planenode *q){planenode *p;for(p=airhead;p->next!=q;p=p->next);q=p;p=p->next;q->next=p->next;free(p);printf("油量不足,紧急迫降!\n");}int Random(int x,int y){int n;n=rand()%(y-x+1)+x;return n;}。
C语⾔实现-航空订票系统(飞机订票系统)开发环境:CodeBlocks开发语⾔:C实现功能:登录,订票,退票数据存储:⽂本读写涉及⽂件:相关⽂件下载:码云: GitHub:相关图⽚(仅供参考):程序是没有涉及旅⾏社的ER图:数据库:类图:⽤例图:订票顺序图:订票状态图:登录活动图:以上图⽚仅供参考,请⾃⾏斟酌程序主界⾯:源码如下:1 #include <stdio.h>2 #include <stdlib.h>3 #include <string.h>4 #include <stdbool.h>5//#include "getch.h"6 #include <conio.h>7#define MAX_Flight 508#define MAX_Passenger 209#define MAX_Order 501011 typedef struct Flight12{13char fid[20]; //航班号14char fname[20]; //航班名称15char start[10]; //起点16char end[10]; //终点17int fnum; //票数18}Flight;1920 typedef struct Passenger21{22char pid[20]; //⾝份证23char pname[10]; //姓名24char password[20]; //密码25char tell[20]; //电话26}Passenger;2728 typedef struct Order29{30char pid[20]; //⾝份证31char fid[20]; //航班号32int num; //票数33}Order;3435 Flight *FLI;36 Passenger *PAS;37 Order *ORD;3839char start[10]; //起点40char end[10]; //终点41char search_fid[50][20]; //符合条件的航班号42int search_fnum[50]; //符合条件的航班票数43int online = 0; //是否登录的变量44char online_pid[20]; //在线⽤户的⾝份证45int search_num = 0; //符合条件的航班数4647void init_sys(void); // 系统初始化48void show_flight(void); // 显⽰航班表49void start_sys(void); // 系统开始运⾏50void exit_sys(void); // 退出系统51void menu(void); // ⽣成主菜单52void login(void); // 登录53void logout(void); //⽤户登出54void passenger_info(void); //查询旅客信息55bool change_pas_info(void); //修改旅客信息56void search_start(void); // ⽣成查询页⾯57bool search(void); // 查询航班58void order_list(void); // ⽣成订单表59void del_order(void); // 退票60void clear_stdin(void); // 清除输⼊缓冲区61char* get_str(char* str,size_t len); // 获取字符串62char get_cmd(char start,char end); // 获取cmd命令 6364int main()65{66 init_sys();67 start_sys();68 exit_sys();69return0;70}7172// 系统初始化73void init_sys(void)74{75// 申请堆内存、加载数据76 FLI = calloc(MAX_Flight,sizeof(Flight));77 PAS = calloc(MAX_Passenger,sizeof(Passenger));78 ORD = calloc(MAX_Order,sizeof(Order));79 printf("system_init...\n");8081 FILE* ofrp = fopen("order.txt","r");82int i=0;83for(i=0; i<MAX_Order; i++) //读取⽂本中的数据到内存84 { int num = 0;85 num = fscanf(ofrp,"%s %s %d\n",ORD[i].pid,ORD[i].fid,&ORD[i].num);86 }8788 FILE* ffrp = fopen("flight.txt","r");89for(i=0; i<MAX_Flight; i++)90 {91int num = 0;92 num = fscanf(ffrp,"%s %s %s %s %d\n",FLI[i].fid,FLI[i].fname,FLI[i].start,FLI[i].end,&FLI[i].fnum);93 }9495 FILE* pfrp = fopen("passenger.txt","r");96for(i=0; i<MAX_Passenger; i++)97 {98int num = 0;99 num = fscanf(pfrp,"%s %s %s %s\n",PAS[i].pid,PAS[i].pname,PAS[i].password,PAS[i].tell);100 }101}102103// 显⽰航班表104void show_flight(void)105{106int i = 0;107for(i=0; i<MAX_Flight; i++)108 {109if(strlen(FLI[i].fid) != 0)110 {111 printf("id:%s name:%s start:%s end:%s fnum:%d\n",FLI[i].fid,FLI[i].fname,FLI[i].start,FLI[i].end,FLI[i].fnum); 112 }113 }114}115116// 系统开始运⾏117void start_sys(void)118{119// 进⼊系统的业务流程控制120//printf("系统开始运⾏...\n");121//show_flight();122while(true)123 {124 menu();125switch(get_cmd('0','7'))126 {127case'1': search_start(); break;128case'2': order_list(); break;129case'3': del_order(); break;130case'4': passenger_info(); break;131case'5': change_pas_info(); break;132case'6': login(); break;133case'7': logout(); break;134case'0': return;135 }136 }137}138139// 系统结束140void exit_sys(void)141{142 printf("data insert...\n");143 FILE* ofwp = fopen("order.txt","w");144 printf("ready insert order.txt\n");145int i= 0;146for(i=0; i<MAX_Order; i++) //数据存储回本地147 {148int num = 0;149if(strlen(ORD[i].pid) != 0)150 {151 num = fprintf(ofwp,"%s %s %d\n",ORD[i].pid,ORD[i].fid,ORD[i].num);152//printf("insert order.txt success\n");153 }154 }155156 FILE* ffwp = fopen("flight.txt","w");157 printf("insert flight.txt\n");158for(i=0; i<MAX_Flight; i++)159 {160int num = 0;161if(strlen(FLI[i].fid) != 0)162 {163 num = fprintf(ffwp,"%s %s %s %s %d\n",FLI[i].fid,FLI[i].fname,FLI[i].start,FLI[i].end,FLI[i].fnum); 164//printf("insert flight.txt success\n");165 }166 }167168 FILE* pfwp = fopen("passenger.txt","w");169 printf("insert passenger.txt\n");170for(i=0; i<MAX_Passenger; i++)171 {172int num = 0;173if(strlen(PAS[i].pid) != 0)174 {175 num = fprintf(pfwp,"%s %s %s %s\n",PAS[i].pid,PAS[i].pname,PAS[i].password,PAS[i].tell); 176//printf("insert passenger.txt success\n");177 }178 }179// 释放内存、保存数据180free(FLI);181free(PAS);182free(ORD);183 printf("exit...\n");184}185186// ⽣成主菜单187void menu(void)188{189 printf("\n");190 printf("********************************\n");191 printf("| |\n");192 printf("| flight order system |\n");193 printf("* 1.search_flight *\n"); //查询航班194 printf("| 2.order_list |\n"); //查询订票信息195 printf("* 3.del_order *\n"); //退订196 printf("| 4.passenger_info |\n"); //查询旅客信息197 printf("* 5.change_pas_info *\n"); //修改旅客信息198 printf("| 6.login |\n"); //⽤户登录199 printf("* 7.logout *\n"); //⽤户登出200 printf("| 0.exit_sys |\n"); //退出系统201 printf("| |\n");202 printf("********************************\n");203//printf("\n");204}205206// 登录207void login(void)208{209if(online == 0) //如果没有登录210 {211int i=0;212int time = 0;213while(time<3)215char entry_pid[20]; //临时变量⾝份证216char entry_pw[20]; //临时变量密码217 printf("please login!\n");218 printf("please entry pid:");219 get_str(entry_pid,20);220 printf("please entry password:");221 get_str(entry_pw,20);222for(i=0; i<MAX_Passenger; i++)223 {224if(strlen(entry_pid)==0 || strlen(entry_pw)==0)225 {226 printf("pid or password can't be empty\n");227 time++;228break;229 }230else if(strcmp(PAS[i].pid,entry_pid) == 0 && strcmp(PAS[i].password,entry_pw) == 0) 231 {232 printf("login success!\n");233 strcpy(online_pid,entry_pid);234 online = 1;235return;236 }237else if(i==MAX_Passenger-1)238 {239 printf("pid or password error\n");240 time++;241 }242 }243 }244 online = -1;245 printf("you have been locked,you can use this system now\n");246 }247else if(online ==1)248 {249 printf("you have been login\n");250 }251else252 {253 printf("you have been locked,you can use this system now\n");254 }255256}257258// ⽤户登出259void logout(void)260{261if(online == 1) //如果已经登录262 {263 online = 0;264 printf("logout success\n");265 }266else if(online == -1)267 {268 printf("you have been locked,you can use this system now\n");269 }270else271 {272 printf("you have not login\n");273 }274}275276// 查询旅客信息277void passenger_info(void)278{279if(online == 1) //如果已经登录280 {281//printf("online_pid:");282//puts(online_pid);283int i = 0;284for(i=0; i<MAX_Passenger; i++)286if(strcmp(online_pid,PAS[i].pid)==0)287 {288 printf("pid:%s, pname:%s, password:%s, tell:%s\n",PAS[i].pid,PAS[i].pname,PAS[i].password,PAS[i].tell); 289break;290 }291 }292 }293else if(online == -1)294 {295 printf("you have been locked,you can use this system now\n");296 }297else298 {299 printf("you have not login\n");300 }301}302303//修改旅客信息304bool change_pas_info(void)305{306if(online == 1) //如果已经登录307 {308 printf("your old info:\n");309int i = 0;310for(i=0; i<MAX_Passenger; i++)311 {312if(strcmp(online_pid,ORD[i].pid)==0)313 {314 printf("pid:%s, pname:%s\npassword:%s, tell:%s\n",PAS[i].pid,PAS[i].pname,PAS[i].password,PAS[i].tell); 315break;316 }317 }318char new_pid[20];319char new_pname[10];320char new_password[20];321char new_tell[20];322 printf("please entry new pid:");323 get_str(new_pid,20);324 printf("please entry new pname:");325 get_str(new_pname,10);326 printf("please entry new password:");327 get_str(new_password,20);328 printf("please entry new tell:");329 get_str(new_tell,20);330 strcpy(PAS[i].pid,new_pid);331 strcpy(PAS[i].pname,new_pname);332 strcpy(PAS[i].password,new_password);333 strcpy(PAS[i].tell,new_tell);334 printf("change success\n");335 }336else if(online == -1)337 {338 printf("you have been locked,you can use this system now\n");339 }340else341 {342 printf("you have not login\n");343 }344}345346// 开始查询航班347void search_start(void)348{349if(search())350 {351 printf("1.order\n");352 printf("0.back\n");353char cmd = get_cmd('0','1');354if(cmd == '0')355 {356return;357//start_sys();358 }359else360 {361char fid[20]; // 选择的航班号362if(online == 1) // 如果已经登录363 {364 printf("please entry fid:");365 get_str(fid,20);366if(0 == strlen(fid))367 {368 printf("fid is empty\n");369 }370int i = 0;371for(i=0; i<search_num; i++)372 {373//printf("fid:%s s_fid:%s num:%d\n",fid,search_fid[i],search_fnum[i]); 374if(strcmp(fid,search_fid[i])==0 && search_fnum[i]>0) //查询到对应航班375 {376 printf("order success\n");377int j=0;378for(j=0; j<MAX_Flight; j++) // 遍历航班表379 {380if(strcmp(fid,FLI[j].fid)==0)381 {382 FLI[j].fnum--; //票数减1383break;384 }385 }386int k=0;387for(k=0; k<MAX_Order; k++) // 遍历订票表388 {389//printf("ready insert...\n");390if(strlen(ORD[k].pid) == 0) // 在空位置插⼊数据391 {392 strcpy(ORD[k].pid,online_pid); // 插⼊当前⽤户⾝份证393 strcpy(ORD[k].fid,search_fid[i]); // 插⼊当前选择的航班号394 ORD[k].num = 1;395 printf("insert_to_order success\n");396break;397 }398 }399return;400 }401else if(strcmp(fid,search_fid[i])==0 && search_fnum[i] == 0)402 {403 printf("no ticket\n");404 search_start();405 }406else if(i==MAX_Flight-1)407 {408 printf("don't have this fid\n");409 search_start();410 }411 }412 }413else if(online == -1)414 {415 printf("you have been locked,you can use this system now\n");416 }417else418 {419 login();420 }421 }422 }423}424425// 查询航班426bool search(void)427{428 printf("start: \n");429 get_str(start,10);430 printf("end: \n");431 get_str(end,10);432int i=0;433 search_num = 0;434for(i=0; i<MAX_Flight; i++)435 {436if(strlen(start) == 0 || strlen(end) == 0)437 {438 printf("start or end can't be empty\n");439return false;440 }441if(strcmp(FLI[i].start,start)==0 && strcmp(FLI[i].end,end)==0)442 {443 printf("fid:%s, ticket_num:%d\n",FLI[i].fid,FLI[i].fnum);444 strcpy(search_fid[search_num],FLI[i].fid);445 search_fnum[search_num] = FLI[i].fnum;446//printf("search_fid[%d]:%s, search_fun[%d]:%d\n",search_num,search_fid[search_num],search_num,search_fnum[search_num]); 447 ++search_num;448 }449if(0 == search_num && i == MAX_Flight-1)450 {451 printf("no flight\n");452return false;453 }454if(search_num > 0 && i == MAX_Flight-1)455 {456//show_flight();457return true;458 }459 }460}461462// 输出订单信息463void order_list(void)464{465if(online == 1)466 {467int i=0;468for(i=0; i<MAX_Order; i++)469 {470if(strcmp(online_pid,ORD[i].pid)==0)471 {472//printf("online_pid:%s\n",online_pid);473 printf("fid:%s, pid:%s, ticket:%d\n",ORD[i].fid,ORD[i].pid,ORD[i].num);474 }475 }476 }477else if(online == -1)478 {479 printf("you have been locked,you can use this system now\n");480 }481else482 {483 login();484 }485}486487// 删除订单488void del_order(void)489{490if(online == 1)491 {492char fid[20];493 printf("order_list:\n");494 order_list();495 printf("please entry del_order fid:");496 get_str(fid,20);497int i=0;498for(i=0; i<MAX_Order; i++)499 {500if(strlen(fid)==0) //判空501 {502 printf("del_order fid can't be empty\n");503return;504 }505if(strcmp(fid,ORD[i].fid)==0)506 {507 memset(ORD[i].pid,'\0',sizeof(ORD[i].pid));508int j=0;509for(j=0; j<MAX_Flight; j++)510 {511if(strcmp(fid,FLI[j].fid)==0)512 {513 FLI[j].fnum++; // 返还飞机票514break;515 }516 }517 printf("delete success\n");518return;519 }520 }521 }522else if(online == -1)523 {524 printf("you have been locked,you can use this system now\n"); 525 }526else527 {528 login();529 }530531}532533// 清理输⼊缓冲区534/*void clear_stdin(void)535{536 stdin->_IO_read_ptr = stdin->_IO_read_end;//清理输⼊缓冲区537}538*/539540// 读取输⼊字符串541char* get_str(char* str,size_t len)542{543if(NULL == str)544 {545 puts("empty ptr!");546return NULL;547 }548549char *in=fgets(str,len,stdin);550551 size_t cnt = strlen(str);552if('\n' == str[cnt-1])553 {554 str[cnt-1] = '\0';555 }556else557 {558 scanf("%*[^\n]");559 scanf("%*c");560 }561562//clear_stdin();563564return str;565}566567// 获取cmd命令568char get_cmd(char start,char end)569{570//clear_stdin();571572 printf("please entry cmd:"); 573while(true)574 {575char val = getch();576if(val >= start && val <= end) 577 {578 printf("%c\n",val);579return val;580 }581 }582 }。
目录第一部分源程序---------------------------------------------------3第二部分函数流程图--------------------------------------------11 menu()-----------------------------------------------------12 enter()-----------------------------------------------------13 input()-----------------------------------------------------14 browse()---------------------------------------------------15 menu1()---------------------------------------------------16 order()-----------------------------------------------------17 search_time()---------------------------------------------18 search_end()----------------------------------------------19 search()----------------------------------------------------20 book()------------------------------------------------------21 back()------------------------------------------------------22 save()------------------------------------------------------23 load()------------------------------------------------------24 第三部分心得体会------------------------------------------------25第一部分:源程序#include <stdio.h>#include <string.h>#include <stdlib.h>#define N 1000typedef struct plane{char ID[10]; /*航班代号*/char BePlace[10];/*飞机起飞地点*/char EnPlace[10];/*飞机降落终点*/char data[15];/*飞机起飞时间*/int max;/*飞机最大乘客人数*/int price;/*飞机票价*/int num;/*飞机已售票数*/}PLANE;PLANE ti[N];int n;/*当前的航班数目*/void menu();void menu1();void input(int i){printf("请输入航班代号:\n");scanf("%s",ti[i].ID);printf("请输入起飞地点:\n");scanf("%s",ti[i].BePlace);printf("请输入降落地点:\n");scanf("%s",ti[i].EnPlace);printf("请输入起飞时间:\n");scanf("%s",ti[i].data);printf("请输入航班的最大载客人数:\n");scanf("%d",&ti[i].max);printf("请输入航班的票价:\n");scanf("%d",&ti[i].price);ti[i].num=0;}void enter(){int i;system( "cls" );printf("请输入航班的数目(0-%d)?:",N);scanf("%d",&n); /*要输入的记录个数*/printf("\n请输入数据\n\n");for(i=0;i<n;i++){printf("\n请输入第%d 航班记录.\n",i+1);input(i); /*调用输入函数*/}getchar();menu();}void printf_one(int i) /*显示一个记录的函数*/{printf("%11s %6s %10s %6s %6d %6d %6d",ti[i].ID,ti[i].BePlace,ti[i].EnPlace ,ti[i].data,ti[i].price,ti[i].max,ti[i].num);}void browse(){int i;system( "cls" );puts("\n--------------------------------------------------------------------");printf("\n\t航班代号起飞地点降落地点起飞时间票价最大乘客已售票数\n");for(i=0;i<n;i++){printf_one(i);printf("\n");}getchar();getchar();menu();}void order() /*排序模块(按平均成绩)*/{int i,j;struct plane s;system( "cls" );for(i=0;i<n;i++) /*冒泡法排序*/{for(j=i+1;j<n;j++)if(strcmp(ti[i].data,ti[j].data)>0){s=ti[i];ti[i]=ti[j];ti[j]=s;}}browse();}void search_time(){int i,m=0;struct plane s;system( "cls" );printf("\n\nEnter the time:");scanf("%s",s.data); /*输入出发的时间*/puts("\n--------------------------------------------------------------------");printf("\n\t航班代号起飞地点降落地点起飞时间票价最大乘客已售票数\n");for(i=0;i<n;i++){if(strcmp(s.data,ti[i].data)==0){m++;if((m!=0)&&(m%10==0)) /*目的是分屏显示*/{printf("\n\nPress any key to contiune . . .");getchar();puts("\n\n");}printf_one(i);printf("\n");/*调用显示一个记录的函数*/}}puts("\n--------------------------------------------------------------------");getchar(); /*按任意健*/getchar();menu1();}void serch_end(){int i,m=0;struct plane s;system( "cls" );printf("\n\nEnter the end Place:");scanf("%s",s.EnPlace); /*输入要到达的地方*/puts("\n--------------------------------------------------------------------");printf("\n\t航班代号起飞地点降落地点起飞时间票价最大乘客已售票数\n");for(i=0;i<n;i++){if(strcmp(ti[i].EnPlace,s.EnPlace)==0){m++;if((m!=0)&&(m%10==0)) /*目的是分屏显示*/{printf("\n\nPress any key to contiune . . .");getchar();puts("\n\n");}printf_one(i);printf("\n");/*调用显示一个记录的函数*/}}puts("\n--------------------------------------------------------------------");getchar(); /*按任意健*/getchar();menu1();}void menu1(){int n,w1;do{system( "cls" ); /*清屏*/puts("\t\t\t\t 飞机售票操作!\n\n");puts("\t\t*********************MENU*********************\n\n");puts("\t\t\t\t1.按照时间排序");puts("\t\t\t\t2.按照时间查找航班");puts("\t\t\t\t3.按照地点查找航班");puts("\t\t\t\t4.返回主菜单");puts("\n\n\t\t**********************************************\n");printf("Choice your number(1-4): [ ]\b\b");scanf("%d",&n);if(n<1||n>4) /*对选择的数字作判断*/{w1=1;printf("your choice is not between 1 and 4,Please input again:");getchar();getchar();}else w1=0;} while(w1==1);/*选择功能*/switch(n){case 1:order();break;case 2:search_time();break;case 3:serch_end();break;case 4:menu();break;}}int search() /*查找模块*/{int i,k;struct plane s;k=-1;system( "cls" );printf("\n\n请输入要订票的起飞地点:");scanf("%s",s.BePlace); /*输入要到达的地方*/printf("\n\n请输入要订票的降落地点:");scanf("%s",s.EnPlace);printf("\n\n请输入要订票的起飞时间:");scanf("%s",s.data); /*输入出发的时间*/for(i=0;i<n;i++) /*查找要修改的数据*/{if(strcmp(s.BePlace,ti[i].BePlace)==0&&strcmp(s.EnPlace,ti[i].EnPlace)==0&&strcmp(s.dat a,ti[i].data)==0){k=i; /*找到要修改的记录*/printf_one(k);break; /*调用显示一个记录的函数*/}}if(k==-1){printf("\n\nNO exist!");return -1;}elsereturn k;}void book(){int i;system( "cls" );printf("欢迎进入售票窗口!\n");i=search();if(i!=-1){if(ti[i].num>=ti[i].max){printf("\n该趟航班票已售完!");}else{ti[i].num++;printf("\n订票成功!\n");}}elseprintf("该航班不存在!\n");getchar();getchar(); /*按任意健*/menu();}void back(){int i,k=-1;struct plane s;system( "cls" );printf("欢迎进入退票窗口!\n");printf("\n\n输入航班代号:");scanf("%s",s.ID); /*输入要到达的地方*/for(i=0;i<n;i++) /*查找要修改的数据*/{if(strcmp(s.ID,ti[i].ID)==0){k=i; /*找到要修改的记录*/printf_one(k);break; /*调用显示一个记录的函数*/}}if(k==-1){printf("\n\nNO exist!");}else{ti[i].num--;printf("\n退票成功!\n");}getchar(); /*按任意健*/getchar(); /*按任意健*/menu();}void save(){int w=1;FILE *fp;int i;system( "cls" );if((fp=fopen("D:\\我的文档\\桌面\\ticket.txt","wt"))==NULL) /*以输出打开方式,在此前的记录被覆盖*/{printf("\nCannot open file\n");return ;}for(i=0;i<n;i++)if(fwrite(&ti[i],sizeof(struct plane),1,fp)!=1){printf("file write error\n");w=0;}if(w==1){printf("file save ok!\n");}fclose(fp);getchar();getchar();menu();}void load(){FILE *fp;int i,w;w=1;system( "cls" );if((fp=fopen("D:\\我的文档\\桌面\\ticket.txt","rt"))==NULL){printf("\nCan not open file\n");w=0;return;}n=0;for(i=0;!feof(fp);i++){fread(&ti[i],sizeof(struct plane),1,fp);n++;}n=n-1;fclose(fp);if(w==1)printf("Load file ok!");getchar();getchar();menu();}void menu(){int n,w1;do{system( "cls" ); /*清屏*/ /*清屏*/puts("\t\t\t\t 飞机售票管理系统!\n\n");puts("\t\t*********************MENU*********************\n\n");puts("\t\t\t\t1.输入新航班");puts("\t\t\t\t2.浏览");puts("\t\t\t\t3.航班操作");puts("\t\t\t\t4.订票");puts("\t\t\t\t5.退票");puts("\t\t\t\t6.保存");puts("\t\t\t\t7.载入");puts("\t\t\t\t8.退出");puts("\n\n\t\t**********************************************\n");printf("Choice your number(1-8): [ ]\b\b");scanf("%d",&n);if(n<1||n>8) /*对选择的数字作判断*/{w1=1;printf("your choice is not between 1 and 8,Please input enter to choice again:");getchar();getchar();}else w1=0;} while(w1==1);/*选择功能*/switch(n){case 1:enter();break; /*输入模块*/case 2:browse();break; /*浏览模块*/case 3:menu1();break; /*查找模块*/case 4:book();break; /*订票模块*/case 5:back();break; /*退票模块*/case 6:save();break; /*保存模块*/case 7:load();break; /*加载模块*/case 8:exit(0);}}void main(){menu();}第二部分:函数流程图(2)enter函数流程图第三部分:心得体会(1)开始对c语言只是一种零散的认识,作为一个c语言的初学者对编程没有明确的概念,只是对语句的格式与编程规定有了一个初步了解。
/*1、用户和管理员及航班信息请以英文字母或数字输入*//*2、管理员账户为:boss,密码为:123。
保存在txt文件中,需要修改请于程序中修改*/ /*3、部分文件读写为二进制读写,所以打开文件时会看到乱码*/#include <stdio.h>#include <string.h>#include <stdlib.h>#include<conio.h>#define N 1000void zhujiemian();//主界面函数void verify();//用户及管理员登录选择void loginmanager();//管理员登录void loginuser();//用户登录void loginflightm();//管理员登录机票系统void loginflightu();//用户登录机票系统void creatfile();//创建用户信息模块void saveuser();//用户信息保存模块程序void input(); //输入航班信息void print(); //输出航班信息void save(); //保存航班信息void read(); //读取航班信息void paixu(); // 对所有航班按航班号排序void search(); //查找航班信息void dingpiao(); //订票信息struct users //管理员/用户信息结构体,管理员可以修改航班信息{char Name[20]; //管理员/用户姓名char sexual[10];//用户性别char ps[8]; // 用户密码int age; //用户年龄long Number; //用户身份证号码int power; //power为1是管理员登录,为0是用户登录}user[N],up,mg;//up为键盘输入用户信息,user[N]为文件保存的用户信息,mg为管理员结构体int n;//所有用户个数,初始化为0struct air //航班信息结构体{int num; //航班号char start[20]; //出发地char over[20]; //目的地char time[10]; //时间int count; //票数int prize; //票价}s[N],fnew;int i;int m=0; //所有航班个数#define PRINT "%-d%12s%12s%10s%12d%10d\n",s[i].num,s[i].start,s[i].over,s[i].time,s[i].count,s[i].pri ze //定义输出格式void main()//主函数{zhujiemian();}void zhujiemian()//主界面函数{int j;printf("#===================================================#\n");printf("# 欢迎进入机票管理系统 #\n");printf("# 1、登录系统 #\n");printf("# 2、新用户注册 #\n");printf("# 0、退出 #\n");printf("#===================================================#\n");printf("请在1-2中选择以回车键结束:\n\n");scanf("%d",&j);switch(j){case 1:verify();//进入机票系统break;case 2:creatfile();//进入用户注册系统break;case 0:;break;}}void verify()//验证用户及管理员信息模块{int j;system("cls");printf("#===================================================#\n");printf("# 1、管理员登录 #\n");printf("# 2、用户登录 #\n");printf("# 0、返回主界面 #\n");printf("#===================================================#\n");scanf("%d",&j);switch(j){case 1:loginmanager();//进入管理员登录界面break;case 2:loginuser();//进入用户登录界面break;case 0:system("cls");zhujiemian(); //进入主界面break;}}/********管理员登录确定函数**********/void loginmanager(){FILE * fp=NULL;//定义文件指针char DataFile[20]="manager.txt";//存储管理员信息的文件名int i=0,j=1;char relogin; //是否重新登录int success=0; //登录成功的标志printf("\n---管理员登录---\n");fp=fopen(DataFile,"r");if(fp==NULL)//如果当前文件不存在,初始化根用户名为boss,密码为123,权限为管理员{printf("首次使用该系统!\n");printf("管理员账户为:boss 密码为:123\n");fp=fopen(DataFile,"a");//以追加方式打开文件user[0].Number=0;strcpy(user[0].Name,"boss");strcpy(user[0].sexual,"male");user[0].age=22;user[0].power=1;strcpy(user[0].ps,"123");fwrite(&user[0],sizeof(user),1,fp);fclose(fp);}elsefclose(fp);again:printf("请输入管理员姓名:");scanf("%s",);//输入用户名[19]='\0';printf("请输入管理员密码:");fflush(stdin);for(i=0;i<7;i++)//输入密码,以*在屏幕显示{up.ps[i]=getch();up.ps[i+1]='\0';//字符要以'\0'结尾if(up.ps[i]=='\b'){i--;up.ps[i]='\0';//清除前一个字符i--;//接收前一个字符printf("\b ");printf("\b");continue;}if(up.ps[i]=='\r'){up.ps[i]='\0';break;}printf("*");}fp=fopen(DataFile,"rt");if(fp==NULL) // 打开文件失败时提示{printf("\n打开 %s 失败!按任意键结束程序\n",DataFile);perror("Open file fail");getchar();return;}if((fp=fopen("manager.txt","r"))==NULL)//打开文件,并判断是否出错{printf("\n出错,请检查文件是否存在,按任意键返回主菜单\n");//打印出错提示getchar();}elsefread(&mg,sizeof(struct users),1,fp);//从文件中读取信息fclose(fp);//关闭文件if(strcmp(,)==0&&strcmp(mg.ps,up.ps)==0){success=1;}if(success==1) //登录成功{printf("\n登录成功,按任意键进入机票调整系统!\n");getchar();loginflightm();}else//未登录成功{fflush(stdin);//清除输入缓冲区中的字符printf("\n用户名或密码错误!重新输入请按y,退出请按n:\n");relogin=getchar();if(relogin=='y'||relogin=='Y'){getchar();goto again;}else{verify();exit(0);}}}/********用户登录函数**********/void loginuser(){FILE *fp=NULL,*fp1;//定义文件指针char DataFile[20]="yonghu.txt";//存储管理员信息的文件名int i=0,j=0;char relogin; //是否重新登录int success=0; //登录成功的标志printf("\n---用户登录---\n");fp=fopen(DataFile,"r");//读取文件中数据if((fp1=fopen("howmanyusers.txt","a"))==NULL)//读写方式打开文件,若文件不存在,则n=0 {//printf("创建文件失败!\n\n");//打印出错提示n=0;//getchar();//continue;}else{fp1=fopen("howmanyusers.txt","r");fscanf(fp1, "%d",&n);//读取fp1中的用户个数}fclose(fp1);if((fp=fopen("yonghu.txt","r"))==NULL)//打开文件,并判断是否出错{fp1=fopen("howmanyusers.txt","w+");//以写方式打开fprintf(fp1,"%d",0);//打开用户文件失败,则输入用户个数0到fp1fclose(fp1);printf("\n目前没有用户信息,请按ENTER键返回主菜单先进行注册!\n");getchar();getchar();system("cls");zhujiemian();}for(i=0;i<n;i++){fread(&user[i],sizeof(struct users),1,fp);//从文件中读取信息}fclose(fp);//关闭文件//输入数据与文件中用户比对again:printf("请输入用户姓名:");scanf("%s",);//输入用户名[19]='\0';printf("请输入用户密码:");fflush(stdin);for(i=0;i<7;i++)//输入密码,以*在屏幕显示{up.ps[i]=getch();up.ps[i+1]='\0';//字符要以'\0'结尾if(up.ps[i]=='\b'){i--;up.ps[i]='\0';//清除前一个字符i--;//接收前一个字符printf("\b ");printf("\b");continue;}if(up.ps[i]=='\r'){up.ps[i]='\0';break;}printf("*");}for(i=0;i<n;i++) //对比用户名和密码,进行登录{if(strcmp(user[i].Name,)==0&&strcmp(user[i].ps,up.ps)==0){success=1;break;}}if(success==1) //登录成功{printf("\n登录成功,按任意键进入机票调整系统!\n");getchar();loginflightu();}else //未登录成功{fflush(stdin);//清除输入缓冲区中的字符printf("\n用户名或密码错误!重新输入请按y,退出请按n:\n");relogin=getchar();if(relogin=='y'||relogin=='Y'){getchar();goto again;}else{verify();exit(0);}}}void saveuser(struct users[])//用户信息保存模块程序{FILE *fp,*fp1;//定义文件指针if((fp=fopen("yonghu.txt","a"))==NULL)//打开文件并判断是否出错{printf("创建文件失败!\n\n");//打印出错提示getchar();return;}if((fp1=fopen("howmanyusers.txt","w+"))==NULL)//打开文件并判断是否出错{printf("创建文件失败!\n\n");//打印出错提示getchar();return;}for(i=0;i<n;i++){if(fwrite(&user[i],sizeof(struct users),1,fp)==0)//向文件写入数据,并判断是否出错{printf("向文件输入数据失败!\n\n");}}fprintf(fp1,"%d",n);//输入用户个数到fp1fclose(fp);//关闭文件fclose(fp1);//关闭文件}void creatfile()//增加用户信息模块{FILE *fp=NULL,*p=NULL,*fp1;char DataFile[20]="yonghu.txt";//存储用户信息的文件名//int a[100];int i=0,k=1,count=0;fp=fopen(DataFile,"r");system("cls");//清屏if(fp==NULL)//如果当前文件不存在,提示打开文件失败{fp1=fopen("howmanyusers.txt","w+");//以写方式打开fprintf(fp1,"%d",0);//打开用户文件失败,则输入用户个数0到fp1fclose(fp1);printf("\n不存在%s,正在创建!\n",DataFile);fp=fopen(DataFile,"a");creatfile();}if((fp1=fopen("howmanyusers.txt","a"))==NULL)//读写方式打开文件,若文件不存在,则n=0 {n=0;}else{fp1=fopen("howmanyusers.txt","r");fscanf(fp1, "%d",&n);//读取fp1中的用户个数}fclose(fp1);for(i=0;i<n;i++){fread(&user[i],sizeof(struct users),1,fp);//从文件中读取信息}fclose(fp);//关闭文件//如果成功打开文件,则提示输入用户相关信息printf("请输入用户信息\n");fflush(stdin);while(k){//printf("\n输入身份证号码注意身份证号码不能为0!\n");printf("请输入身份证号码:");scanf("%ld",&up.Number);i=0;//再次初始化i为0//判断身份证号是否存在while(i<n){if(user[i].Number==up.Number){printf("该身份证号码已被使用过!\n请重新输入身份证号:");scanf("%ld",&up.Number);i=0;//continue;}elsei++;}//经循环对比后,i的值仍和n相等,将新注册的信息加入数组末位user[i].Number=up.Number;printf("姓名:");scanf("%s",&user[i].Name);user[i].Name[19]='\0';printf("性别:");scanf("%s",&user[i].sexual);printf("用户密码:");scanf("%s",&user[i].ps);printf("年龄:");scanf("%d",&user[i].age);n++;//用户数目增加printf("是否继续注册?是:选1,否:选0;");scanf("%d",&k);}saveuser(user);//保存用户信息fclose(fp);//在屏幕上显示文件内容system("cls");printf("数据已经成功保存到%s中\n",DataFile);getchar();printf("按任意键返回主界面!\n");getchar();system("cls");zhujiemian();//返回主界面}void loginflightm()//管理员登录机票系统{int j;do{system("cls");printf(" ★----------------您好,欢迎进入自动化飞机订票系统!---★\n");printf("=========================================================================== =====\n");printf(" **-------- -------☆ 1.输入航班信息☆-------- -------------------**\n\n" " **-------- ----☆ 2. 浏览航班信息☆----- ------------------**\n\n" " **-------- ☆ 3. 查找航班信息 -☆-------- ------------**\n\n" " **-------- ---☆ 4.对航班按航班票价排序---☆-----------------------**\n\n" " **-------- ------☆ 5. 订票信息-☆-------- -----------------**\n\n" " **-------- ----------☆0.退出-☆-------- ---------------------**\n\n" " **-------- ---------------☆☆---------------------------------**\n\n" " **-------- -----------------☆-------- --------------------------**\n\n" " **-------- ---------------☆☆-------- --------------------------**\n\n");printf("=========================================================================== =====\n");printf("请在0-5中选择以回车键结束:\n\n");scanf("%d",&j);switch(j){case 1:input();//调用输入模块break;case 2:system("cls");print();//调用打印模块break;case 3:search();//调用查找模块break;case 4:paixu();//调用排序模块break;case 5:dingpiao();//调用订票模块break;case 0:;break;}}while(j!=0); //判断结束printf("按任意键返回主界面\n");system("cls");zhujiemian();}//登录函数结束void loginflightu()//用户登录机票系统{int j;do{system("cls");printf(" ★----------------您好,欢迎进入自动化飞机订票系统!---★\n");printf("=========================================================================== =====\n");printf(" **-------- ----☆ 1. 浏览航班信息☆----- ------------------**\n\n" " **-------- ☆ 2. 查找航班信息 -☆--------------------**\n\n" " **-------- ---☆ 3.对航班按航班票价排序---☆-----------------------**\n\n" " **-------- ------☆ 4. 订票信息-☆-------- -----------------**\n\n" " **-------- ----------☆0.退出-☆-------- ---------------------**\n\n" " **-------- ---------------☆☆-------- -------------------------**\n\n" " **-------- -----------------☆-------- --------------------------**\n\n" " **-------- ---------------☆☆-------- --------------------------**\n\n");printf("=========================================================================== =====\n");printf("请在0-5中选择以回车键结束:\n\n");scanf("%d",&j);switch(j){case 1:system("cls");print();//调用打印模块break;case 2:search();//调用查找模块break;case 3:paixu();//调用排序模块break;case 4:dingpiao();//调用订票模块break;case 0:;break;}}while(j!=0); //判断结束printf("按任意键返回主界面\n");system("cls");zhujiemian();}//登录函数结束void input()//输入航班信息模块,管理员操作{int i=0,k=1;read();printf("请依次输入航班信息(航班号,起始站,终点站,起飞时间,机票数,票价):\n\n");//打印提示信息printf("--------------------------------------------------------------------------\ n");//fflush(stdin);while(k){printf("请输入航班号:\n");scanf("%d",&fnew.num); //读取航班号i=0;//再次初始化i为0//判断航班是否已经存在while(i<m){if(s[i].num==fnew.num){printf("该航班已经存在!\n请重新输入:");scanf("%d",&fnew.num);i=0;//continue;}elsei++;}//经循环对比后,i的值仍和n相等,将新注册的信息加入数组末位s[i].num=fnew.num;printf("请输入起始站:\n");scanf("%s",s[i].start);//读取起始站printf("请输入终点站:\n");scanf("%s",s[i].over);//读取终点站printf("请输入时间:\n");scanf("%s",s[i].time);//读取时间printf("请输入余票数(机票数为0结束输入):\n",m);scanf("%d",&s[i].count);//读取机票数printf("请输入机票票价:\n",m);scanf("%d",&s[i].prize);//读取机票票价m++; //所有航班信息个数// printf("第%d个信息已经输完是否继续?按1-9任意数字继续,按0结束",m);//scanf("%d",&y);printf("是否继续添加航班?是:选1,否:选0;");scanf("%d",&k);if(k==0){save();//将结构体信息存盘system("cls");print();//输出输入的航班信息break;}}}void save()//航班信息保存模块程序{FILE *fp,*fp1;//定义文件指针if((fp=fopen("flight.txt","wb"))==NULL)//打开文件并判断是否出错printf("创建文件失败!\n\n");//打印出错提示getchar();return;}if((fp1=fopen("howmanyflights.txt","wb"))==NULL)//打开文件并判断是否出错{printf("创建文件失败!\n\n");//打印出错提示getchar();return;}for(i=0;i<m;i++)if(fwrite(&s[i],sizeof(struct air),1,fp)==0)//向文件写入数据,并判断是否出错printf("向文件输入数据失败!\n\n");fprintf(fp1,"%d",m);fclose(fp);//关闭文件fclose(fp1);//关闭文件}void read()//从文件读取航班信息模块{FILE *fp,*fp1;//定义文件指针fp=fopen("flight.txt","r");//system("cls");//清屏if(fp==NULL)//如果当前文件不存在,提示打开文件失败{fp1=fopen("howmanyflights.txt","w+");//以写方式打开fprintf(fp1,"%d",0);//打开用户文件失败,则输入用户个数0到fp1fclose(fp1);printf("\n不存在flight.txt,正在创建!\n");fp=fopen("flight.txt","a");printf("创建完成!\n");system("cls");read();//perror("Open file fail");//getch();}if((fp1=fopen("howmanyflights.txt","rb"))==NULL)//读写方式打开文件,若文件不存在,则m=0{//printf("创建文件失败!\n\n");//打印出错提示m=0;}else{fp1=fopen("howmanyflights.txt","r");fscanf(fp1, "%d",&m);//读取fp1中的用户个数fclose(fp1);for(i=0;i<m;i++){fread(&s[i],sizeof(struct air),1,fp);//从文件中读取信息}fclose(fp);//关闭文件}void print()//屏幕打印航班信息模块{read();//调用读取文件函数if(m==0)printf("\n\n目前没有航班信息!\n");else{printf("航班信息如下:\n");printf("航班号起始站终点站时间余票数票价\n");for(i=0;i<m;i++){printf(PRINT);//打印信息}}printf("\n请按任意键回车键结束返回主菜单");getchar();getchar();}void paixu()//对所有航班按航班价格排序{int j;struct pai{int no;char name1[20];char name2[20];char time[20];int count;int prize;}p[1];//临时定义结构体,作为排序时的第三变量read();//调用读取信息函数for(j=0;j<(m-1);j++){for(i=0;i<(m-(1+j));i++){if(s[i].prize>s[i+1].prize) //按价格升序排列,p[0]为中间变量{p[0].no=s[i].num;//替换航班号strcpy(p[0].name1,s[i].start);//替换其始站strcpy(p[0].name2,s[i].over);//替换终点站strcpy(p[0].time,s[i].time);//替换时间p[0].count=s[i].count;//替换机票数p[0].prize=s[i].prize;//替换票价s[i]=s[i+1];s[i+1].num=p[0].no;//替换航班号strcpy(s[i+1].start,p[0].name1);//替换其始站strcpy(s[i+1].over,p[0].name2);//替换终点站strcpy(s[i+1].time,p[0].time);//替换时间s[i+1].count=p[0].count;//替换机票数s[i+1].prize=p[0].prize;}}}save();//调用保存函数system("cls");printf("排序后,");print();}void search()//按航班号查询模块{char ii[10];int no,k;read();//调用读取函数do{system("cls");k=0;//每次查找都初始化k为0printf("请输入你要找的航班号:");//打印查询方式菜单scanf("%d",&no);//航班号for(i=0;i<m;i++){if(s[i].num==no)//按航班号判断输出条件{k=1;system("cls");printf("\n查找航班信息成功!\n");printf("航班号起始站终点站时间余票数票价\n");printf(PRINT);//打印信息break;}}no=0;//将航班号重新赋值为0if(k==0){printf("没有您需要的信息\n");}printf("\n是否继续查找?请键入yes或no以回车键结束\n");scanf("%s",ii);}while(strcmp(ii,"yes")==0);//判断结束}void dingpiao()//订票模块{int n;char a[10];search();//调用查询模块do{printf("请输入您要订的机票数以回车键结束:\n");scanf("%d",&n);//读取所订机票数if(n<0){printf("请输入有效的机票数!\n");//判断机票数是否出错break;}if(s[i].count!=0&&s[i].count>=n)//判断是否出错{s[i].count=s[i].count-n;save();//调用保存函数printf("订票成功!\n\n");break;}if(s[i].count<n)//判断是否出错{printf("余票不足,请输入有效的机票数!\n");getchar();}printf("是否继续订票?请输入yes或no以回车键结束:\n");//判断是否继续订票scanf("%s",a);}while(!strcmp(a,"yes"));//判断结束getchar();printf("按ENTER键返回用户主界面。