关闭

用C语言写一个订座系统

标签: 函数c语言typedefstructC初学者基础项目
134人阅读 评论(0) 收藏 举报
分类:

函数声明部分写出该系统的主要功能以及结构体
typedef struct SeatPosition{
int num;
int flage;
char name[20];

}Seat;
void menu();//主菜单
void SelectFunction(Seat *seat);//选择功能
void ShowAll(Seat * seat);//显示所有座位
void ShowNum(Seat * seat);//显示未预定的座位编号
void AddSeat(Seat * seat);//添加一个位子
void DeleteSeat(Seat * seat);//删除一个位子
void Empty(Seat *seat);//清空
void Exit();//退出

函数实现部分

include “test.h”

include

pragma mark —2

char Delete(char *string)
{
printf(“请输入一串字符串”);
scanf(“%s”,string);
gets(string);
while (string != ‘\0’) {
if (*string == ’ ‘) {
string = (string+1);
string–;
}
}
printf(“%s”,string);
return *string;
}

pragma mark —3

void menu()
{
printf(“*欢迎来到万达电影订座系统**\n”);
printf(“功能如下:\n”);
printf(“1.所有座位的信息\n”);
printf(“2.未预定的座位编号\n”);
printf(“3.添加一个座位\n”);
printf(“4.删除一个座位\n”);
printf(“5.清空所有的预定座位\n”);
printf(“6.退出\n”);
}//主菜单
void SelectFunction(Seat * seat)
{
int number = 0;
do {

    menu();
    printf("请输入:\n");
    scanf("%d",&number);
    switch (number) {
        case 1:
            ShowAll(seat);
            break;
        case 2:
            ShowNum(seat);
            break;
        case 3:
            AddSeat(seat);
            break;
        case 4:
            DeleteSeat(seat);
            break;
        case 5:
            Empty(seat);
            break;
        case 6:
            Exit();
            break;
        default:
            break;
    }
} while (number != 6);

}//选择功能
void ShowAll(Seat *seat)
{
for (int i = 0; i < 12; i++) {
if (seat[i].flage == 1) {
printf(“已经预定的编号:%d,姓名:%s\n”,seat[i].num,seat[i].name);
}
}

}//显示所有座位
void ShowNum(Seat *seat)
{
for (int i = 0; i < 12; i++) {
if (seat[i].flage == 0) {
printf(“未预约的编号:%d\n”,seat[i].num);
}

}

}//显示未预定的座位编号
void AddSeat(Seat *seat)
{
ShowNum(seat);
int num = 0;
char name[] = “”;
printf(“请输入你要预约的编号\n”);
scanf(“%d”,&num);

int flag = 0;
for ( int i = 0; i < 12; i++) {

    if (seat[i].num == num) {
        if (seat[i].flage ==0){
        printf("请输入你的姓名%s\n",name);
        scanf("%s",name);
        seat[i].flage = 1;
        strcpy(seat[i].name, name);

        flag =1;
        printf("添加成功\n");
        break;
    }
    }
}
if (flag == 0) {
    printf("添加失败,请重新添加\n");
}

}//添加一个位子
void DeleteSeat(Seat *seat)
{
int num = 0;
char name[20]= “”;
printf(“请输入你要删除的编号\n”);
scanf(“%d”,&num);

// int flag = 0;
for ( int i = 0; i < 12; i++) {
if (seat[i].num == num) {
printf(“请输入你的姓名%s\n”,name);
scanf(“%s”,name);
if (strcmp(seat[i].name, name) == 0) {
seat[i].flage = 0;
strcpy(seat[i].name, “none”);
// flag = 1;
printf(“删除成功\n”);
break;
}
else{
printf(“删除失败,请重新删除\n”);
break;
}
}

}

// if (flag == 0) {
//
// }
}//删除一个位子
void Empty(Seat *seat)
{
for (int i = 0; i < 12; i++) {
seat[i].flage =0;
strcpy(seat[i].name, “none”);
}
printf(“所有的座位被清空”);
}//清空
void Exit()
{
printf(“谢谢使用,再见\n”);
}//退出

主函数定义该结构体的内容,以及调用函数

pragma mark –3

Seat seat[12] = {
    {1,1,"刘"},
    {2,1,"关"},
    {3,1,"张"},
    {4,0," "},
    {5,0," "},
    {6,0," "},
    {7,0," "},
    {8,0," "},
    {9,0," "},
    {10,0," "},
    {11,0," "},
    {12,0," "}
};
SelectFunction(seat);
return 0;

}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:469次
    • 积分:43
    • 等级:
    • 排名:千里之外
    • 原创:4篇
    • 转载:0篇
    • 译文:0篇
    • 评论:1条
    文章分类
    文章存档
    最新评论