| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 533 人关注过本帖
标题:求高手解答??我也是想了很久呀,旅店信息管理程序
取消只看楼主 加入收藏
吴晓鸿
Rank: 1
来 自:福建龙岩永定
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-9-14
结帖率:0
收藏
已结贴  问题点数:20 回复次数:0 
求高手解答??我也是想了很久呀,旅店信息管理程序
//我程序都打出来了,但就是不知道怎么运行,运行错误说没有struct.h文件,不明白?
//MainBody.c文件

# include<Structs.h>
extern int GuestNumber;
int GuestNumber=0;
void main(void){
    LoadHotelInfo(rooms);
    LoadGuestInfo();
    LoadGARInfo();
    handlemenu();
}
void printMenu(){
    printf(
        "1 查看旅店信息\n"
        "2 查看某一房间信息\n"
        "3 查看旅客信息\n"
        "4 查找某一旅客信息\n"
        "5 旅客入住\n"
        "6 旅客换房\n"
        "7 旅客退房\n"
        "8 退出\n"
        );
}
void handlemenu(){
    int i=0;
    do{
        printMenu();
        printf("请选择\n");
        scanf("%d",&i);
        fflush(stdin);
        switch(i){
        case 1:
            ViewAllHotel();
            printf("\n\n");
            break;
        case 2:
            ViewOneRoom();
            printf("\n\n");
            break;
        case 3:
            ViewAllGuest();
            printf("\n\n");
            break;
        case 4:
            ViewOnGuet();
            printf("\n\n");
            break;
        case 5:
            GuestCheckIn();
            printf("\n\n");
            break;
        case 6:
            GustChangeRoon();
            printf("\n\n");
            break;
        case 7:
            GuestCheckOut();
            printf("\n\n");
            break;
        case 8:
            SaveGARInfo();
            SaveGuestInfo();
            SaveHotelInfo(rooms);
            exit(0);

        }
    }while(1);
}
# include<stdio.h>
# include<stdlib.h>
# include<conio.h>
# include<string.h>
# include<time.h>
# define FLOORNUMBER 4
# define ROOMNUMBER 5
typedef enum RommType{Single=1,Double=2,Triangle=3}RoomType;//房间类型
typedef struct room{
    int RoomNumber;        //房间号
    RoomType roomtype;    //房间类型
    int CheckInNumbre;    //入住几人
    int RoomPrice;       //房间价格
}Room;                   //房间相关成员的定义
typedef struct guestandroom{
    char GuestID[20];    //旅客身份证号
    int GuestInRoom;     //旅客入住的房间
    char CheckInTime[30];//入住时间
    char CheckOutTime[30];//退房时间
}Guest And Room;          //房间相关的成员定义
typedef struct guest{
    char Name[10];    //姓名
    char sex[3];     //性别
    char ID[20];     //身份证号
}Guest;               //旅客的相关属性的定义
void menu();
void LoadHotelInfo(Room pararoom[FLOORNUMBER][]);
void ViewAllHotel();
void SaveHotelInfo(Room pararoom[FLOORNUMBER][]);
void LoadGuestInfo();
void SaveGuestInfo();
void ViewOneGuest();
void ViewAllGuest();
void AppendGustInfo();
void GuestCheckIn();
void GuestChangeInfo();
void GustCheckOut();
void ChangeBookDay();
void AppendGARInfo();
void LoadGARInfo();
void SaveGARInfo();
void AppendGuestHistoryInfo(int Guesti,int GARj);
void handlemenu();
void printMenu();
void ViewOneRoom();
int IsOldGuest();
int DelGuest(charID[]);
int CountGuest(Room pararoom[FLOORNUMBER][]);
int CheckRAGIndex(char ID[]);
int CheckFreeRom(char Sex[]);
int FindOneGuest();
char *CheckRoomSex(int RoomNumbr);
Room rooms[FLOORNUMBER][ROOMNUMBER];       //存房间信息的结构数组
Guest ptoguest[55];                       //存旅客信息的数组
GuestAndRoom GAR[55]; }
 //存旅客入住房间的数组
# include"Structs.h"
extern int GuestNumber;
//向guestandroom文件中添加信息
void AppendandGARInfo(){
    FILE *fp;
    if((fp=fopen("guestandroom.txt","a"))==NULL){
        printf("文件读取失败\n");
        exit(0);
    }
    fprintf(fp,"%d\t%s\t\t%s\n",GAR[GuestNumber-1].GuestInRoom,
        GAR[GuestNumber-1].GuestID,GAR[GuestNumber-1].CheckInTime);
    fclose(fp);
}
//初始化GAR数组
void LoadGARInfo(){
    //动态建立存储旅客信息的数组
    FILE *fp;
    char temp[10]="";
    if((fp==fopen("guestandroom.txt","r"))==NULL){
        printf("文件读取失败!\n");
        exit(0);
    }
    fscanf(fp,"%*s %*s %*s %*s",temp,temp,temp,temp\n);
    for(iCount=0;iCount<GuestNumber;iCount++){
        fscanf(fp,"%d %s\t\t\t",&GAR[iCount].GuestInRoom,
            GAR[iCount].GuestID);
        fgets(GAR[iCount].CheckInTime,25,fp);
        strcpy(GAR[iCount].CheckOutTime," ");
    }
    fclose(fp);
}

void SaveGARInfo(){
    FILE *fp;
    int iCount=0;
    if((fp=fopen("guestandroom.txt","w"))==NULL){
        printf("文件读取失败\n");
        exit(0);
    }
    fprintf(fp,"%s%t%s%t%s\n","房间","身份证","入住时间","退房时间",);
    for(iCount=0;iCount<GuestNumber;iCount++)
        fprintf(fp,"%d\t\t%s\t\t\t%\t\t\t%s\n",GAR[iCount].GuestInRoom,
        GAR[iCount].GuestID,GAR[iCount].CheckInTime,
        GAR[iCount].CheckOutTime);
    fclose(fp);
}
//检验满足ID的GAR数组的位置
int CheckRAGIndex(char ID[]){
    int gindex=-1;
    int garindex=-1;
    int icount;
    for (icount=0;icount<GuestNumber;icount++){
        if(!strcmp(ID,ptoguest[icount].ID)){
            gindex=icount;
            break;
        }
    }
    if(gindex!=-1){//如果有
        for(icount=0;icount<GuestNumber;icount++){
            if(!strcmp(ptoguest[gindex].ID,GAR[icount].GuestID)){
                garindex=gindex;
                break;
            }
        }
    }
    return garindex;
}
//旅客入住
void GuestCheckIn(){
    int NewRoomNumber;
    int NewGuestSexN;
    int i;
    int j;
    int CheckSex=0;
    time_t t;
    t=time(NULL);
    printf("请输入旅客姓名:\n");
    scanf("%s",ptoguest[GuestNumber].Name);
    do{
        printf("请选择旅客性别\n");
        printf("1 男\n 2 女\n");
        scanf("%d",&NewGuestSexN);
        switch(NewGuestSexN){
        case 1:
            strcpy(ptoguest[GuestNumber].sex,"男");
            break;
        case 2:
            strcpy(ptoguest[GuestNumber].sex,"女");
            break;
        }
    }
    while(NewGuestSexN!=1&&NewGuestSexN!=2);
    printf("请输入旅客身份证号码:\n");
    scanf("%s",ptoguest[GuestNumber].ID);
    CheckSex=CheckFreeRoom(ptoguest[GuestNumber].sex);
    if(!CheckSex){
        //处理数组
        strcpy(ptogust[GuestNumber].ID,"");
        strcpy(ptogust[GuestNumber].Name,"");
        strcpy(ptogust[GuestNumber].sex,"");
        return;
    }
    printf("请输入旅客选择入住房间号码:\n");
    scanf("%d",&NewRoomNumber);       //如何保证选的是正确的呢
    //更改房间状态,新房间
    for(i=0;i<4;i++){
        for(j=0;j<5;j++){
            if(rooms[i][j].RoomNumber==NewRoonNumber){
                rooms[i][j].CheckInRoom=rooms[i][j].CheckInNumber+1;
            }
        }
    }
    GuestNumber+=1;  //人数增加
    strcpy(GAR[GuestNumber-1].CheckInTime,ctime(&t));
    printf("入住时间为%s\n",GAR[GuestNumber-1].CheckInTime);
    strucp(GAR[GuestNumber-1].GuestID,ptoguest[GuestNubmer-1].ID);
    GAR[GuestNumber-1].GuestInRoom=NewRoomNumber;
    //将信息添加到文件中
    AppendGuestInfo();
    AppendGARInfo();
    SaveHotelInfo(rooms);
}
//旅客退房
void GustCheckOut(){
    float discount=0,money=0;
    int Days=0,i;
    char ID[20]="";
    do{
        printf("请输入旅客身份证:\n");
        scanf("%s",ID);
        for(i=0;i<=GuestNumber-1;i++){
            if(!strcmp(ID,ptoguest[i].ID)){
                break;
            }
        }
        if(i==GuestNumber){
            printf("您输入的用户不存在!\n");
            i=-1;
        }
    }while(i==-1);
    discount=(IsOldGuset(ID)<=2)?1:(IsOldGuest(ID)
            <4?0.9:(IsOldGuest(ID)          <=6)?0.8:0.7;
    printf("此为顾客此次为第%d次住店,
        打折率为:%f\n",IsOldGuest(ID)+1,discount);
        money=(float)DelGuest(ID);
    printf("请输入入住天数:\n");
    scanf("%d",&Days);
    money=money*Days*discount;
    printf("应付%f元.\n",money);
    SaveGARInfo();
    SaveGuestInfo();
    SaveHotelInfo(rooms);
}
//旅客换房
//旅客换房,只能换到空房(结账)
void GuestChangeRoom(){
    char name[10]="";
    char ID[19]="";
    int GARindex=-1;
    int GuestIndex=-1;
    char choice='\0';
    int day=0;
    int i=0,j=0;
    int sum=0;
    int roomnumber=0;
    //输入旅客信息
    printf("请输入旅客的姓名:\n");
    gets(name);
    //找到旅客在旅客结构体中的下标
    printf("请输入需要换房的旅客的身份证:\n");
    gets(ID);
    RAGindex=CheckRAGIndex(ID);
    for(i=0;i<=GuestNumber;i++){
        if(!strcmp(ID.ptoguest[i].ID))  {    //要是有同名的就麻烦了
            printf("该旅客的信息如下\n"
                "姓名\t性别\t入住的房间\t入住的时间\n");
            printf("%s\t%s\t%d\t%s\n",ptogust[i].Name,ptoguest[i].
            sex,
                    GAR[RAGindex].agauestInRoom,GAR[RAGindex].CheckIn
                    time);
            GuestIndex=i;
            break;
        }
    }
    printf("确认以上信息?(y/n)\n");
    choice=getchare();
    if(choice=='N'||choice=='n'){
        return;
    }
    //结账
    printf("请输入该旅客的入住天数:\n");
    scanf("%d",&day);
    for(i=0;i<FLOORNUMBER;i++){
        for(j=0;j<ROOMNUMBER;j++){
            if(rooms[i][j].RoomNumber==GAR[RAGindex].GuestInRoom){
                sum=day*rooms[i][j].RoomPrice;
                break;
            }
        }
        if(sum){
            break;
        }
    }
    printf("请旅客缴纳前面的房款%d.\n",sum);
    //打印能换入的房间
    CheckRAGIndex(ptoguest[GuestIndex].sex);
    printf("请输入要换人的房间号:\n");
    scanf("%d",&roomnumber);
    //放入
    if(roomnumber==GAR[RAGindex].GuestInRoom){
       printf("不能换如愿房间\n");
       return;
    }
    //状态更改
    //原房间
    GAR[RAGindex].GuestInRoom=roomnumber;
    rooms[i][j].CheckInNumber--;
    for(i=0;i<FLOORNUMBER;i++)
        for(j=0;j<ROOMNUMBER;J++){
           if(rooms[i][j].RoomNumber==roomnumber){
              rooms[i][j].CheckInNumber++;
              break;
           }
       }
    SaveGARInfo();
    SaveGuestInfo();
    SaveHotelInfo(rooms);
}
Guests.c:
# include<Structs.h>
extern int GuestNumber;
//添加旅客信息
void AppendGuestInfo(){
    FILE *fp;
    if((fp=fopen("guest.txt","a"))==NULL){
        printf("文件读取失败\n");
        exit(0);
    }
    fprintf(fp,"%s\t%s\t%s\t\n",ptoguest[GuestNumber-1].Name,
        ptogust[GuestNumber-1].sex,ptoguest[GuestNumber-1].ID);
    fclose(fp);
}

int CountGuest(Room pararoom[FLOORNUMBER][ROOMNUMBER]){
    int iFloor=0;
    int jRoom=0;
    int sum=0;
    for (iFloor=o;iFloor<Floornumbr;iFloor++)
        for(jRoom=0;jRoom<ROOMNUMBER;jRoom++){
            if(pararoom[iFloor][jRoom].CheclInNumber>0){
                sum+=pararoom[iFloor][jRoom].CheckInNumber;
            }
        }
    return sum;
}
//载入客人信息
void LoadGuestInfo(){
    FILE *fp;
    int iCount=0;
    char temp[10]="";
    if((fp=fopen("guest.txt","r"))==NULL){
        printf("文件读取失败!\n");
        exit(0);
    }
    GuestNumber=CountGuest(rooms);
    fscanf(fp,"%*s %*s %*s",temp,temp,temp\n);
    for(iCount=0;iCount<GuestNumber;iCount++){
    fscanf(fp,"%s\t%s\t%s",ptoguest[iCount].Name,ptoguest[iCount].sex,
        ptoguest[iCount].ID);
        //strcpy(GAR[iCount].GuestID,ptoguest[iCount].ID);
    }
    fclose(fp);
}
//储存旅客信息
void SaveGuestInfo(){
    FILE *fp;
    int iCount=0;
    if((fp=fopen("guest.txt","w"))==NULL){
        printf("文件读取失败\n");
        exit(0);
    }
    fprintf(fp,"%s\t%s\t%s\n","姓名","性别","身份证"\n);
    for(iCount=0;iCount<GuestNumber;iCount++)
    fprintf(fp,"%s\t%s\t%s\n",ptoguest[iCount].Name,ptoguest[iCount].
    sex,ptoguest[iCount].ID);
    fclose(fp);
}
//查找旅客信息
void ViewOneGuest(){
    int i=FindOneGuest();
    int GARNUM;
    if(i!=-1){
        GARNUM=CheckGARIndex(ptoguest[i].ID);
        printf("姓名\t性别\t身份证\t\t房间\t入住时间\n");
        printf("%s\t%s\t%s\t\t%d\t%s\t\n",ptoguest[i].Name,ptoguest[i].
        sex,ptoguest[i].ID,GAR[GARNUM].GuestInRoom,GAR[GARNUM].CheckIn
        Time);
        return;
    }
    else{
        printf("没有此用户信息!\n");
        return;
    }
}
//查找旅客信息可以做成一个函数
int FindOneGuest(){
    int i;
    char GuestID[25];
    printf("\n请输入旅客的身份证:\n");
    scanf("%s",GuestID);
    fflush(stdin);
    for(i=0;ii<GuestNumber;i++){
        if(!strcpy(GuestID,ptoguest[i].ID)){
            return i;
        }
    }
    printf("没有此名顾客!\n");
    rturn -1;
}
//查看所有旅客的信息
void ViwAllGuest(){
    int i=0;
    int GARNUM;
    printf("——————所有旅客信息——————\n");
    printf("姓名\t性别\t身份证\t房间\t入住时间\n");
    for(i=0;i<GuestNumber;i++){
    GARNUM=ChckRAGIndex(ptoguest[i].ID);//找下标
    printf("%s\t%s\t%s\t%d\t%s\t\n",ptoguest[i].Name,ptoguest[i].sex,
        ptoguest[i].ID,GAR[GARNUM].GustInRoom,GAR[GARNUM].ChecnIn
        Time);
    }
    printf("打印结束!\n");
}
//判断是否是以前的旅客
int IsOldGuest(char NewID[]){
    FILE *fp;
    char temp[20]="";
    char name[10]="";
    char ID[20]="";
    int Room=0;
    char CheckInTime[30]="";
    char CheckOutTime[30]="";
    int a=0;
    if((fp=fopen("guesthistory.txt","r"))==NULL){
        printf("文件读取失败\n");
        exit(0);
    }
    fscanf(fp,"%*s %*s %*s %*s %*s",temp,temp,temp,temp,temp\n);
    while(!feof(fp)){
        fscanf(fp,"%s %s %d %s %s",name,ID,&Room,CheckInTime,CheckOut
        Time);
        if(!strcpy(NewID,ID)){
            a++;
        }
    }
    return a;
}
//添加新的历史记录
void AppendGustHistoryInfo(int Guesti,int GARj){
    FILE *fp;
    if((fp=fopen("guesthistory.txt","a"))NULL){
        printf("文件读取失败\n");
        exit(0);
    }
    fprintf(fp,"%s\t%s\t%d\t\t\t%\t\t\t%s\n",ptoguest[Guesti].Name,
        ptoguest[Guesti].ID,GAR[GARj].GuestInRoom,GAR[GARj].CheckIn
        Time,GAR[GARj].ChechOutTime);
}
//打印入住记录
void ViewOldGuest(){
    FILE *fp;
    char name[10];
    int ID;
    int Room;
    char CheckInTime[30];
    char CheckOutTime[30];
    if((fp=fopen("guesthistory.txt","r"))==NULL){
        printf("文件读取失败\n");
        exit(0);
    }
    printf("姓名\t\t身份证\t\t房间号\t\t入住时间\t\t退房时间\t\t\n");
    do{
        fscanf(fp,"%s %d %d %s %s\n",name,
            &ID,&Room,CheckInTime,CheckOutTime);
        printf("%s\t\t %d\t\t %d\t\t %s\t\t %s\t\t\n",
            name,ID,Room,CheckInTime,CheckOutTime);
    }
    while(!feod(fp));
}
//删除Guest数组中的一个信息,同时删除对应的GAR
int DelGuest(char ID){
    int i=0,j=0,GARj=0,roomi=0,roomj=0;
    int money=0;
    int out=1;
    time_t t;
    t=time(NULL);
    for(i=0;i<GuestNumber;i++){
        if(!strcpy(ID,ptoguest[i].ID)){
            GARj=CheckRAGIndex(ptoguest[i].ID);
            printf("入店时间为%s\n",GAR[RAGj].CheckInTime);
            strcpy(GAR[GARj].CheckOutTime,ctime(&t));
            printf("退店时间为%s\n",GAR[GARj].CheckOutTime);
            for(roomi=0;roomi<4&&out;roomi++){
                for(roomj=0;roomj<5;roomj++){
                    if(GAR[GARj].GuestInRoom==
                                 rooms[roomi][roomj].RoomNumber){
                        money=rooms[roomi][roomj].RoomPrice;
                        rooms[roomi][roomj],CheckInNumber=
                            rooms[roomi][roomj].CheckInNumber-1;
                        SaveHotelInfo(rooms);
                        out=0;
                        break;
                    }
                }
            }
            AppendGuestHistoryInfo(i,GARj);
            GuestNumber=GuestNumber-1;
            for(j=i;j<GuestNumber;j++){
                ptoguest[j]=ptoguest[j+1];
            }
            for(j=GARj;j<GuestNumbr;j++){
                GAR[j]=GAR[j+1];
            }
            break;
        }
    }
    return money;
}
Hotels.c:
# include<Structs.h>
extern int GuestNumber;
//检查房间应住的性别
char *CheckRoomSex(int RoomNumber){
    int i,j;
    for(i=0;i<GuestNumber;i++)   {//添加那有问题 GuestNumber
        if(RoomNumber==GAR[i].GuestInRoom){//得到房间客人所在数组的下标
            for(j=o;j<GuestNumber;j++){
                if(!strcmp(GAR[i].GuestID,ptoguest[j].ID))
                                     //找到对应的客人
                    return ptoguest[j].sex;
            }
            break;
        }
    }
    return NULL;
}
//检查空房
int CheckFreeRoom(char Sex[]){
    int i,j,find=0;
    char roomsex[3];
    printf("能入住的房间:\n");
    for(i=0;i<4;i++){
        for(j=0;j<5;j++){
            if(!rooms[i][j].CheckInNumber){  //房间为空
                printf("%d\t",rooms[i][j].RoomNumber);
                find=1;
            }
            else{  //房间有人
                strcpy(roomsex,CheckRoomSex(rooms[i][j].RoomNumber));
                if(( rooms[i][j].roomtype>rooms[i][j].CheckInNumber
                    //入住的人数少于房间类型
                    && (strcmp(Sex,roomsex)==0)  //入住的是相同性别的人
                    )
                )
                {    printf("%d\t",rooms[i][j].RoomNumber);
                     find=1;
                }
                else{
                    printf("\t");
                }
            }
        }
        printf("\n");
    }
    if(!find){
        printf("没有合适房间!\n房间已满.\n");
    }
    return find;
}
//载入所有房间入住情况信息
void LoadHotelInfo(Room innerroom[FLOORNUMBER][ROOMNUMBER]){
 FILE *fp;
 int iFloor=0;
 int jRoom=0;
 char temp[9];
 if ((fp=fopen("hotel.txt","r"))==NULL){
  printf("文件读取失败");
  exit(0);
 }
 fscanf(fp,"%*s %*s %*s\n",temp,temp,temp,temp);
 for(iFloor=0;iFloor<FLOORNUMBER;iFloor++)
  for(jRoom=0;jRoom<ROOMNUMBER;jRoom++){
   fscanf(fp,"%d %d %d %d\n",&innerroom[iFloor][jRoom].RoomNumber,
    &innerroom[iFloor][jRoom].roomtype,
                &innerroom[iFloor][jRoom].CheckInNumber,
                &innerroom[iFloor][jRoom].RoomPrice);
  }
  fclose(fp);
}
//打印所有房间入住情况
void ViewAllHotel(){
 int i,j;
 printf("房间号码\t房间类型\t入住人数\t房间价格\t\n");
 for(i=0;i<4;i++){
  for(j=0;j<5;j++){
   printf("%d\t\t",rooms[i][j].RoomNumber);
   switch(rooms[i][j].roomtype){
   case 1:
    printf("单人房\t\t");break;
   case 2:
      printf("双人房\t\t");break;
            case 3:
    printf("三人房\t\t");break;
   }printf("%d\t\t%d\t\t\n",rooms[i][j].CheckInNumber,
    rooms[i][j].RoomPrice);
  }
  printf("\n");
 }
}
//储存所有房间信息
void SaveHotelInfo(Room pararoom[FLOORNUMBER][ROOMNUMBER]){
 FILE*fp;
 int iFloor=0;
 int jRoom=0;
 if((fp=fopen("hotel.txt",'w"))==NULL){
  printf("文件读取失败");
  exit(0);
 }
    fprintf(fp,"房间号码\t房间类型\t入住人数\t房间价格\t\n");
    for(iFloor=0;iFloor<FLOORNUMBER;iFloor++){
  for(jRoom=0;jRoom<ROOMNUMBER;jRoom++){
   fprintf(fp,"%d\t\t%d\t\t%d\t\t%d\t\n",
    pararoom[iFloor][jRoom].RoomNumber,
                pararoom[iFloor][jRoom].roomtype,
                pararoom[iFloor][jRoom].CheckInNumber,
                pararoom[iFloor][jRoom].RoomPrice);
  }
  fprintf(fp,"\n");
 }
 fclose(fp);
}
//打印谋一房间情况
void ViewOneRoom(){
 int RoomNum,i,j,IsNull=0;
 printf("请输入房间号码:\n");
 scanf("%d",&RoomNum);
 for(i=0;i<GuestNumber;i++){
  if(RoomNum==GAR[i].GuestInRoom){
   for(j=0;j<GuestNumber;j++){
    if(strcmp(ptoguest[j].ID,GAR[i].GuestID)==0){
     printf("",ptoguest[j].Name,ID,ptoguest[j].sex,GAR[i].CheckInTime);
    IsNull=1;
    }
   }
  }
 }
 if(!IsNull){
 printf("房间为空!\n");
 }
}            



搜索更多相关主题的帖子: 信息 void 管理程序 include 
2012-03-13 22:32
快速回复:求高手解答??我也是想了很久呀,旅店信息管理程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.039992 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved