餐厅选座系统
如何做到显示文件的座位表且顾客选完座之后修改座位空闲状态程序代码:
#include <stdio.h> #include <stdlib.h> struct room { int id;/*台桌编号*/ int suit;/*适合人数*/ int status;/*台桌状态*/ }; typedef struct room roomstru; int main() { int number,i=0,k,j=0,l; FILE *fp; roomstru a[100]; printf("几人用餐:(1~15)\n"); scanf("%d",&number); if(number<=0||number>=15) printf("抱歉,本餐厅不能提供%d人数的服务",number); fp=fopen("room.txt","a+"); printf("座位编号 合适人数 台桌状态(1已订 0空闲)\n"); while(!feof(fp)) { fscanf(fp,"%d%d%d",&a[i].id,&a[i].suit,&a[i].status); i++; } while(number<=a[j].suit) { j++; } for(;j<15;j++) {printf("%d%14d%14d",a[j].id,a[j].suit,a[j].status); printf("\n"); } printf("请输入预订座位编号:\n"); scanf("%d",&k); fprintf(fp,"%d%d%d",a[k-1].id,a[k-1].suit,"1"); fscanf(fp,"%d%d%d",&a[k-1].id,&a[k-1].suit,&a[k-1].status); printf("你已预定%d号桌子,欢迎前往用餐!\n",a[k-1].id); fclose(fp); return 0; }