order = 1;
while( u != NULL ) { for( count = 1, v = u->next; ______8______; v = v->next ) __9___; /* 累计工作量相同的人数 */ printf( \, order, u->q, count ); order += count;
for( ;__10____ != 0; u = u->next ) printf( \ /* 输出相同工作量的工人工号 */
printf( \ );
}
}
void main() { WL *wl, *tmp; int i, j; while( 1 ) { printf( \输入工人数(<1000,>0), 工作量记录数(<10000,>0), <=0退出\\n\ fflush( stdin ); scanf( \%d%d\, &j ); if( i <= 0 || j <= 0 ) return; if( i >= 1000 || j >= 10000 ) continue; wl = __11____; /* 创建职工工作量有序结构 */ print_wl( wl ); /* 按规定输出工作量结构数据 */ while(__12__ ) { /* 释放空间 */
tmp = wl->next;
free( wl ); wl = tmp; } } }
68
第三部分 课程设计实验
实验1 航空客运订票系统
2、参考程序
#include
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) printf(\空间不足\ return a; }
customer *start_cus() /*创建顾客链表 */ {
customer *c;
c=(customer*)malloc(sizeof(customer)); if(c==NULL)
69
printf(\空间不足\ 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(\ 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;
70
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(\our seat number is %d\ insert_cus(&q,name,air_num,p->total-p->left+1); p->left--; return OK; } else {
printf(\s 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);
71