c语言数据结构大作业飞机购票,C语言飞机订票系统

#include#define OK 1

#define ERROR 0

typedef struct airline{

char air_num[8];

char plane_num[8];

char end_place[20];

int  total;

int  left;

struct airline *next;

}airline;

typedef struct customer{

char name[8];

char air_num[8];

int  seat_num;

struct customer *next;

}customer;

airline *start_air()

{

airline *a;

a=(airline*)malloc(sizeof(airline));

if(a==NULL)

a->next=NULL;

return a;

}

customer *start_cus()

{

customer *c;

c=(customer*)malloc(sizeof(customer));

if(c==NULL)

c->next=NULL;

return c;

}

airline *modefy_airline(airline *l,char *air_num)

{

airline *p;

p=l->next;

for(;p!=NULL;p=p->next)

{

if(strcmp(air_num,p->air_num)==0)

{

p->left++;

return l;

}

printf("NO the airline!");

return 0;

}

}

int insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)

{

airline *q;

q=(airline*)malloc(sizeof(airline));

strcpy(q->air_num,air_num);

strcpy(q->plane_num,plane_num);

strcpy(q->end_place,end_place);

q->total=total;

q->left=left;

q->next=NULL;

(*p)->next=q;

(*p)=(*p)->next;

return OK;

}

int  insert_cus(customer **p,char *name,char *air_num,int seat_num)

{

customer *q;

q=(customer*)malloc(sizeof(customer));

strcpy(q->name,name);

strcpy(q->air_num,air_num);

q->seat_num=seat_num;

q->next=NULL;

(*p)->next=q;

(*p)=(*p)->next;

return OK;

}

int book(airline *a,char *air_num,customer *c,char *name)

{

airline *p=a;

customer *q=c->next;

p=a->next;

for(;q->next!=NULL;q=q->next){}

for(;p->next!=NULL;p=p->next)

{

if(p->left>0)

{

printf("Your seat number is %d",(p->total-p->left+1));

insert_cus(&q,name,air_num,p->total-p->left+1);

p->left--;

return OK;

}

else

{

printf("seat is full");

return 0;

}

}

}

int del_cus(customer *c,airline *l,char *name)

{

customer *p,*pr;

char air_num[8];

pr=c;

p=pr->next;

while(p!=NULL)

{

if(strcmp(p->name,name)==0)

{

strcpy(air_num,p->air_num);

l=modefy_airline(l,air_num);

pr->next=p->next;

p=pr->next;

printf("finish!");

return OK;

本实验课题主要是要解决数据在文件中的读取,航班信息用文件保存,因而要提供文件的输入输出操作;航班信息浏览功能要提供现实操作;要查询的航线需要提供查找功能;存储客户信息和客户订票信息,并能浏览和查询客户订票信息;另外要提供键盘式选择菜单以实现功能选择。此实验需要在CodeBlocks等C语言编译平台上完成同时本实验要求所写的程序可以流畅的在编译平台上运行。首先为用户提供一个菜单,展示各个选项的功能,用户可输入一个选项(数字),执行相应的功能,通过运用switch语句对用户输入的数字进行处理判断出用户想要执行的操作。一共有9个选项,第3个和第6选项没有使用函数,其他模块分别对应着一个函数。 航班信息的写入(定义FILE *fp指针),先将将航班次数写入文件,以结构体数组的形式来保存键盘上输入的每条航线相应的信息。然后再用fprintf函数的格式写入方式将数组中的数据写入文档中。 客户信息的写入(定义FILE *fp指针),先将将客户人数写入文件,以结构体数组的形式来保存键盘上输入的每位客户相应的信息。然后再用fprintf函数的格式写入方式将数组中的数据写入文档中。 航班信息的读取,先定义结构体数组,从文件中读取航班的航班号、起始终点站等信息写入到结构体数组fly中,在用fscanf函数的格式读取方式将文档中相应的数据保存在相应的结构体数组里定义的变量中。 用户信息的读取,先定义结构体数组,从文件中读取用户的证件号姓名等信息写入到结构体数组cus中,在用fscanf函数的格式读取方式将文档中相应的数据保存在相应的结构体数组里定义的变量中。 浏览的功能,是按不同的要求分别将航班信息和客户信息排序出来,然后按排好的序输出出来。 查询显示等功能,可以通过读取得到的结构体数组,进行重写文档,打印等方式实现功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值