cplus第十四章第八题,一点微小bug

本文介绍了一个C语言实现的航空座位管理程序,支持显示空座、按字母顺序列出座位、分配乘客、删除预订等功能。通过菜单操作,用户可以方便地管理飞机上的座位状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
enum noof
{
    yes,
    no
};
struct airplane
{
    enum noof yno;
    int zuowei;
    char fname[20];
    char lname[20];
};
void menu()
{
    printf("To choose a function, empty its letter label:\n");
    printf("(a) Show number of empty seats\n");
    printf("(b) Show list of empty seats\n");
    printf("(c) Show alphabetical list of seats\n");
    printf("(d) Assign a customer to a seat assignment\n");
    printf("(e) Delete a seat to a seat assignment\n");
    printf("(f) Quit");
}
int * chongzhi(int n[])
{
    for (int i = 1; i <= 12; i++)
        n[i] = i;
    return n;
}
char * s_gets(char * st, int n)
{
    char * ret_val;
    char * find;
    
    ret_val = fgets(st, n, stdin);
    if (ret_val)
    {
        find = strchr(st, '\n');
        if (find)
            * find = '\0';
        else
            while (getchar() != '\n')
                continue;
    }
    return ret_val;
}
int main(void)
{
    char ch;
    struct airplane juren[13];
    int n[13];
    int temp;
    
    chongzhi(n);
    for (int i = 1; i <= 12; i++)
    {
        juren[i].zuowei = i;
        juren[i].yno = no;
    }
    menu();
    printf("请输入您的选择:\n");
    while (scanf("%c", &ch) != NULL)
    {
        if (ch == 'q')
            break;
        if (ch == '\n')
            continue;
        switch(ch)
        {
            case 'a':
                for (int i = 1; i <= 12; i++)
                    if (juren[i].yno == no)
                        printf("%d  ", juren[i].zuowei);
                printf("\n");
                break;
            case 'b': 
                for (int i = 1; i <= 12; i++)
                    if (juren[i].yno == no)
                        printf("%d号座位 ", juren[i].zuowei);
                printf("\n");
                break;
            case 'c': 
                for (int i = 1; i < 12; i++)
                    for (int j = i + 1; j <= 12; j++)
                        if (juren[n[i]].fname[0] > juren[n[j]].fname[0])
                        {
                            temp = n[i];
                            n[i] = n[j];
                            n[j] = temp;
                        }
                for (int i = 1; i <= 12; i++)
                    if (juren[n[i]].yno == yes)
                        printf("%d号: %s %s \n", juren[n[i]].zuowei, juren[n[i]].fname, juren[n[i]].lname);
                chongzhi(n);
                break;
            case 'd':
                printf("输入预定的座位号:\n");
                scanf("%d", &temp);
                while (getchar() != '\n')
                    continue;
                if (juren[temp].yno == yes)
                {
                    printf("输入号码已经有人预定.\n");
                    break;
                }
                else
                {
                    juren[temp].yno = yes;
                    printf("输入您的姓:\n"); 
                    s_gets(juren[temp].fname, 20);
                    printf("输入您的名:\n");
                    s_gets(juren[temp].lname, 20);
                }
                break;
            case 'e': 
                printf("输入取消的账号,您具有资格:\n");
                scanf("%d", &temp);
                juren[temp].yno = no;
                break;
        }
        menu();
        printf("请输入您的选择:\n");
    }
    printf("欢迎下次光临哦~\n");
    
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

顺安晓迪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值