鱼C论坛

 找回密码
 立即注册
查看: 1488|回复: 1

结构问题

[复制链接]
发表于 2019-8-2 23:48:16 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include <stdio.h>
#define LEN 10
#define SIZE 12
struct seat {
        int seat_num;
        int seat_book;
        char fname[LEN];
        char lanme[LEN];
};

char meun(void);
void show_num(struct seat num[]);
void show_list(struct seat list[]);
void show_alp(struct seat alp[]);
void assign_seat(struct seat assign[]);
void delete_seat(struct seat delete[]);

int main(void)
{
        struct seat plane[SIZE] = {0};
        int index;
        char ch;

        for (index = 0; index < SIZE; index++) //座位编号
                plane[index].seat_num = index;

        ch = meun();
        while (ch != 'f')
        {
                switch (ch)
                {
                case 'a':
                        show_num(plane);
                        break;
                case 'b':
                        show_list(plane);
                        break;
                case 'c':
                        show_alp(plane);
                        break;
                case 'd':
                        assign_seat(plane);
                        break;
                case 'e':
                        delete_seat(plane);
                        break;
                }
                ch = meun();
        }

        getchar();
        return 0;
}

char meun(void)
{
        char ch;

        puts("To choose a function, enter its letter label:");
        puts("a) Show number of empty seats");
        puts("b) Show list of empty seats");
        puts("c) Show alphabetical list of seats");
        puts("d) Assign a customer to a seat assignment");
        puts("e) Delete a seat assignment");
        puts("f) Quit");
        ch = getchar();
        getchar();

        return ch;
}

void show_num(struct seat num[])
{
        int index,count = 0;
        for (index = 0; index < SIZE; index++)
        {
                //printf("The empty seat number is ");
                if (num[index].seat_book == 0)
                        //printf(" %d", num[index].seat_num);
                        count++;
               
        }
        if (count == 0)
                printf("There is no empty seat.\n");
        else if (count == 1)
                printf("There is 1 empty seat.\n");
        else
                printf("There are %d empty seat.\n", count);

}

void show_list(struct seat list[])
{
        int index, count = 0;
        printf("The empty seat number is ");
        for (index = 0; index < SIZE; index++)
        {
                if (list[index].seat_book == 0)
                {
                        printf(" %d", list[index].seat_num);
                        count++;
                }
        }
        putchar('\n');
        if (count == 0)
                printf("There is no empty seat.\n");
}

void show_alp(struct seat alp[])
{
        int i, j, k;
        struct seat temp;
        for (i = 0; i < SIZE - 1; i++)
        {
                for (j = i + 1; j < SIZE; j++)
                {
                        if (strcmp(alp[i].fname, alp[j].fname) > 0)
                        {
                                temp = alp[i];
                                alp[i] = alp[j];
                                alp[j] = temp;
                        }
                }
        }
        for (k = 0; k < SIZE; k++)
        {
                if (alp[k].seat_book == 0)
                        printf("The %d seat is empty.\n", alp[k].seat_num);
                else
                        printf("seat number:%d, name: %s %s.\n", alp[k].seat_num, alp[k].fname, alp[k].lanme);
        }
}

void assign_seat(struct seat assign[])
{
        int num;
        puts("Enter the number what you assign:");
        scanf("%d", &num);
        getchar();
        puts("Enter your fname:");
        gets(assign[num].fname);
        puts("Enter your lname:");
        gets(assign[num].lanme);
        assign[num].seat_book = 1;
}

void delete_seat(struct seat delete[])
{
        int num;
        struct seat temp = { 0,0,"","" };
        puts("Enter the number what you delete:");
        scanf("%d", &num);
        delete[num] = temp;
        delete[num].seat_num = num;
        printf("%d\n", delete[num].seat_num);

}


为什么我在输入e之后,然后再输入其他字母没反应的?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2019-8-2 23:50:56 | 显示全部楼层
不用回答了,答案已经找到,谢谢!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-5 02:45

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表