题目7飞机票订票系统
问题描述:
某公司每天有10航班(航班号、价格),每个航班的飞机,共有80个座位,
20排,每排4个位子。编号为A,BCD。如座位号:10D表示10排D座。
运行界面如下:
1)能从键盘录入订票信息:乘客的姓名、身份证号、航班号、乘坐日期
座位号;
打印订票信息:
4)查询指定航班、指定日期的乘客信息;
2) 能根据身份证、航班号、乘坐日期修改乘坐座位;
部分代码
int queryMoney(pTICKET head)//统计票价
{
int count=0;
int yearl,yearr;
printf("输入左区间索引 输入右区间索引:");
scanf("%d %d", &yearl,&yearr);
int price = 0;
pTICKET p=head->next;
while (p!=NULL)
{
if ((yearl <= p->date.year) && (p->date.year <= yearr))
{
count += p->price;
}
p = p->next;
}
return count;
}
void booking(pTICKET *head)//订票
{
pTICKET ticket, p;
int i;
char strDate[20], str[10];
ticket = (pTICKET )malloc(sizeof(TICKET));
printf("输入姓名:");
scanf("%s", ticket->name);
do
{
printf("输入身份证号:");
scanf("%s", ticket->id);
if (strlen(ticket->id) == 15 || strlen(ticket->id) == 18)
break;
printf("身份证位数错误!");
} while (1);
do
{
printf("输入航班号:");
scanf("%s", ticket->flugNo);
for (i = 0; i<N; i++)
{
if (strcmp(flug[i].no, ticket->flugNo) == 0)
{
ticket->price = flug[i].price;
break;
}
}
if (i<N)
break;
printf("指定航班号不存在!");
} while (1);
do
{
printf("输入乘坐日期:");
scanf("%s", strDate);
if (checkDate(strDate) == 1)
break;
printf("日期格式错误!");
} while (1);
ticket->date = strToDate(strDate);
do
{
printf("输入座位号(如:10D):");
scanf("%s", str);
ticket->seat.row = atoi(str);
if (ticket->seat.row<0 || ticket->seat.row>20)
{
printf("排数错误!");
continue;
}
ticket->seat.col = str[strlen(str) - 1];
if ('A'>ticket->seat.col || 'D'<ticket->seat.col)
{
printf("列数错误!");
continue;
}
for (p =(*head)->next; p != NULL; p = p->next)
{
if (ticket->date.year == p->date.year&&ticket->date.month == p->date.month&&ticket->date.day == p->date.day)
{
if (strcmp(ticket->flugNo, p->flugNo) == 0)
{
if (ticket->seat.row == p->seat.row&&ticket->seat.col == p->seat.col)
{
printf("座位已被预订!");
continue;
}
}
}
}
insert(&head, &ticket);
break;
} while (1);
}
void refund(pTICKET *head)//退票
{
pTICKET ticket, p;
pTICKET prev = *head;
int i;
char strDate[20], str[10];
ticket = (TICKET *)malloc(sizeof(TICKET));
printf("输入姓名:");
scanf("%s", ticket->name);
do{
printf("输入航班号:");
scanf("%s", ticket->flugNo);
for (i = 0; i<N; i++)
{
if (strcmp(flug[i].no, ticket->flugNo) == 0)
break;
}
if (i<N)
break;
printf("指定航班号不存在!");
} while (1);
do
{
printf("输入乘坐日期:");
scanf("%s", strDate);
if (checkDate(strDate) == 1)
break;
printf("日期格式错误!");
} while (1);
ticket->date = strToDate(strDate);
do
{
p = (*head)->next;
if (strcmp(ticket->name, p->name) == 0)
{
if (strcmp(ticket->flugNo, p->flugNo) == 0)
{
if (ticket->date.year == p->date.year&&ticket->date.month == p->date.month&&ticket->date.day == p->date.day)
{
prev->next= p->next;
free(p);
p = NULL;
return;
}
}
}
p = p->next;
prev = prev->next;
} while (p != NULL&&prev != NULL);
//printf("无此订票信息!");
return;
}
程序定制访问链接
【闲鱼】https://m.tb.cn/h.UTxLWFA?tk=v1mTdcsMxUp CZ0001 「我在闲鱼发布了【沙发靠垫抱枕大三角靠垫床头靠垫办公室腰靠背垫床上靠枕护颈枕】」
点击链接直接打开
欢迎在闲鱼联系我下单喔