温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

C语言如何实现简单酒店管理系统

发布时间:2022-03-18 09:23:29 来源:亿速云 阅读:174 作者:iii 栏目:开发技术

今天小编给大家分享一下C语言如何实现简单酒店管理系统的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

一、问题描述

系统应具有以下主要功能:登记入住:从键盘输入住信息:房间层数,房间号码等;查询入住情况,查询当前费用,退房、退出系统等功能。

二、基本要求

(1)、登记入住。可以输入多个信息,实现本系统数据的初始化。
(2)、列出所有的入住情况,用于顾客查询以及办理入住手续。
(3)、查询当前费用:显示顾客实时费用,便于顾客查询和退房时进行付费。
(4)、退房:办理退房手续,修改系统内信息,将此顾客的住房置空。
(5)、退出系统:对此次操作中信息的增删改后的数据写入文件中,保存后退出。

#include<stdio.h>
#include<stdlib.h>
#include<time.h>   //调用系统的时间,通过时间的增减计算费用
#include<string.h>
#include<windows.h>
#define N 10
#define HOURROOM 10
#define NORMALROOM 120
#define BIGROOM 300
#define WORTHROOM 500
#define GREATROOM 800
struct room_message{
    int number;        //房间号
    int people;        //有无入住
    int floor;        //楼层数(不同楼层房间类型不同)
    time_t time;        //入住时间,无人住则置空
}ROOM[100];
void BuildRoom()
{    //创建房间 的函数,对系统进行数据的初始化
    FILE *fp=NULL;
    int i,j;
    if((fp=fopen("roommessage.dat","r"))==NULL)
        {
            fp=fopen("roommessage.dat","w");
            for(i=0;i<N;i++)
                {
                    for(j=0;j<N;j++)
                        {
                            ROOM[i*    10+j].number= j;
                            ROOM[i*    10+j].floor= i;
                            ROOM[i*    10+j].people= 0;
                            ROOM[i*    10+j].time= 0;
                            fwrite(&ROOM[i*    10+j],sizeof(struct room_message),1,fp);
                        }
                }
        }
    else {    
        for(i=0;i<N;i++)    
            {
                for(j=0;j<N;j++)
                    {
                        fread(&ROOM[i*    10+j],sizeof(struct room_message),1,fp);
                    }
            }
        }
    fclose(fp);
}
void Printpay(int floor,int room,int fee,int people)
{    //打印所需费用,根据时间计算费用
        time_t time1,time2;
        int a;
        time1 = ROOM[floor*10+room].time;
        time2 = time(NULL);
        if(people==0){
            printf("该房间没有人\n");}
        else {    
            if(floor<2){
                a = ((time2-time1)/3600)+1;
                printf("该房间的费用为%d元\n",a*fee);}
        else{
            a=(((time2-time1)/3600)/24)+1;
            printf("该房间的费用为%d元\n",a*fee);}
    }
}
void CheckOut()
{    //退房函数,引用计算费用函数,并更改入住情况
    int roomnuber,choose,a,b,floor,room,fee;
    FILE *fp=NULL;
    do{
        printf("\n请输入您想退房的房间的房间号:");
        scanf("%d",&roomnuber);
        floor=(roomnuber / 100) - 1;
        room=roomnuber%100;
        floor = (roomnuber/100)-1 ;
        room = (roomnuber%100)-1;
        if(floor>9||floor<0||room<0||room>9){
            printf("您的输入有误,请重新在1-9之间输入\n");
        }
    }while(floor>9||floor<0||room<0||room>9);
    printf("您要退的房间号为%d,它是",roomnuber);
    if(floor==0||floor==1){            
        printf("钟点房\n");
        fee=HOURROOM;
    }
    if(floor==2||floor==3){            
        printf("标准间\n");
        fee=NORMALROOM;
    }
    if(floor==4||floor==5){            
        printf("商务间\n");
        fee=BIGROOM;
    }
    if(floor==6||floor==7){            
        printf("行政套房\n");
        fee=WORTHROOM;
    }
    if(floor==8||floor==9){            
        printf("豪华套房\n");
        fee=GREATROOM;
    }
    do{
        printf("\n您是否确定要退房。\n");
        printf("1.是\n");
        printf("2.不是\n");
        scanf("%d",&choose);
        if(choose!=1&&choose!=2){
            printf("\n您的输入有误,请在1-2之间重新输入\n");
        }
    }while(choose!=1&&choose!=2);
    if(choose==1){
        Printpay(floor,room,fee,ROOM[floor*10+room].people);
        ROOM[floor*10+room].people=0;
        ROOM[floor*10+room].time=0;
        fp=fopen("roommessage.dat","w"); 
        for(a=0;a<N;a++){
            for(b=0;b<N;b++){
                fwrite(&ROOM[a*    10+b],sizeof(struct room_message),1,fp);
            }
        }
        printf("\n退房成功\n");
    }
    fclose(fp);
    system("pause");
}
void PrintRoomFee(int a){                 //打印房间价格
    if(a==1||a==2){
        printf("\n钟点房的费用为每小时%d元\n",HOURROOM);
    }
    if(a==3||a==4){
        printf("\n标准间的费用为每天%d元\n",NORMALROOM);
    }
    if(a==5||a==6){
        printf("\n商务间的费用为每天%d元\n",BIGROOM);
    }
    if(a==7||a==8){
        printf("\n行政套房的费用为每天%d元\n",WORTHROOM);
    }
    if(a==9||a==10){
        printf("\n豪华套房的费用为每天%d元\n",GREATROOM);
    }
}
void CalFee()
{
    int roomnuber,floor,room,fee;
    do{
    printf("\n请输入您想查询费用的房间的房间号(例如101,代表钟点房1号):");
    scanf("%d",&roomnuber);
    floor = (roomnuber/100)-1 ;
    room = (roomnuber%100)-1;
    if(floor>9||floor<0||room<0||room>9){
        printf("您的输入有误,请在1-9之间重新输入\n");
    }
    }while(floor<0||floor>9||room<0||room>9);
    printf("您要找的%d号房为",roomnuber);
    if(floor==0||floor==1){            
        printf("钟点房\n");
        fee=HOURROOM;
    }
    if(floor==2||floor==3){            
        printf("标准间\n");
        fee=NORMALROOM;
    }
    if(floor==4||floor==5){            
        printf("商务间\n");
        fee=BIGROOM;
    }
    if(floor==6||floor==7){            
        printf("行政套房\n");
        fee=WORTHROOM;
    }
    if(floor==8||floor==9){            
        printf("豪华套房\n");
        fee=GREATROOM;
    }
    Printpay(floor,room,fee,ROOM[floor*10+room].people);
}
void ScanRoom(){    //查询入住的函数,读取入住情况
    int a,i,j;
    FILE *fp=NULL;
    void PrintRoomFee(int a);
    printf("\n请选择您要查询的房间种类\n");
    printf("1.钟点房\n");
    printf("2.标准间\n");
    printf("3.商务间\n");
    printf("4.行政套房\n");
    printf("5.豪华套房\n");
    scanf("%d",&a);
    if((fp=fopen("roommessage.dat","r"))!=NULL)//判断文件是否为空{
        for(i=0;i<N;i++)
        {
            for(j=0;j<N;j++)
                {
                    fread(&ROOM[i*10+j],sizeof(struct room_message),1,fp);
                }
        }
            if(a == 1){
            PrintRoomFee(a);
            for(i=0;i<=1;i++){
                for(j=0;j<10;j++){
                    printf("\n第%d层",ROOM[i*10+j].floor+1);
                    printf("第%d号房",ROOM[i*10+j].number+1);
                    if(ROOM[i*10+j].people){
                        printf("房间已入住,请重新选择");
                    }
                    else{
                        printf("房间未入住,可以选择");
                    }
                }
            }
            }
            if(a == 2){
            PrintRoomFee(a);
            for(i=2;i<=3;i++){
                for(j=0;j<10;j++){
                    printf("\n第%d层",ROOM[i*10+j].floor+1);
                    printf("第%d号房",ROOM[i*10+j].number+1);
                    if(ROOM[i*10+j].people){
                        printf("房间已入住,请重新选择");
                    }
                    else{
                        printf("房间未入住,可以选择");
                    }
                }
            }
            }
            if(a == 3){
            PrintRoomFee(a);
            for(i=4;i<=5;i++){
                for(j=0;j<10;j++){
                    printf("\n第%d层",ROOM[i*10+j].floor+1);
                    printf("第%d号房",ROOM[i*10+j].number+1);
                    if(ROOM[i*10+j].people){
                        printf("房间已入住,请重新选择);
                    }
                    else{
                    printf("房间未入住,可以选择");
                    }
                }
            }
            }
            if(a == 4){
            PrintRoomFee(a);
            for(i=6;i<=7;i++){
                for(j=0;j<10;j++){
                    printf("\n第%d层",ROOM[i*10+j].floor+1);
                    printf("第%d号房",ROOM[i*10+j].number+1);
                    if(ROOM[i*10+j].people){
                        printf("房间已入住,请重新选择");
                    }
                    else{
                        printf("房间未入住,可以选择");
                    }
                }
            }
            }
            if(a == 5){
            PrintRoomFee(a);
            for(i=8;i<=9;i++){
                for(j=0;j<10;j++){
                    printf("\n第%d层",ROOM[i*10+j].floor+1);
                    printf("第%d号房",ROOM[i*10+j].number+1);
                    if(ROOM[i*10+j].people){
                        printf("房间已入住,请重新选择");
                    }
                    else{
                        printf("房间未入住,可以选择");
                    }
                }
            }
        }
    }
}
void CheckIn(){      //入住函数,记录时间,更改入住情况
    int a,b,c,i,j;
    FILE *fp=NULL;
    do{
        printf("\n请输入您想入住的房间层数(1~10)");
        printf("\n1~2为钟点房");
        printf("\n3~4为标准间");
        printf("\n5~6为商务间");
        printf("\n7~8为行政套房");
        printf("\n9~10为豪华套房\n");
        scanf("%d",&a);
        if(a<1||a>10){
            printf("您的输入有误,请在1-10之间重新输入\n");
        }
    }while(a<1||a>10);
    PrintRoomFee(a);
    do{
        printf("\n请输入您想入住的房间号(1~10):");
        scanf("%d",&b);    
        if(b<1||b>10){
            printf("您的输入有误,请在1-10之间重新输入\n");    }
    }while(b<1||b>10);
    if((fp=fopen("roommessage.dat","rb"))!=NULL){            //打开文件
    if(ROOM[(a-1)*10+(b-1)].people==0){        //判断房间是否可住
    for(i=0;i<N;i++)
        {
            for(j=0;j<N;j++)
                {
                    fread(&ROOM[i*10+j],sizeof(struct room_message),1,fp);
                }
        }
        fclose(fp);
        printf("\n请输入计划入住的人数:");
        scanf("%d",&c);
        ROOM[(a-1)*10+b-1].people=c;
        ROOM[(a-1)*10+b-1].time=time(NULL);
        fp=fopen("roommessage.dat","w");
        for(a=0;a<N;a++){
            for(b=0;b<N;b++){
                fwrite(&ROOM[a*    10+b],sizeof(struct room_message),1,fp);
            }
        }
    }
    else{
        printf("\n抱歉,该房间已经有人入住\n");
        printf("请选择其他的房间入住\n");
    }
    }
    fclose(fp);
}
int ChangeRoom(){    //酒店管理系统的菜单
    int step;
    BuildRoom();
    do{                //主程序循环
        do{                //选择界面循环
        system("cls");
        printf("\n请输入您想执行的步骤序号\n");
        printf("1.登记入住\n");
        printf("2.查询入住情况\n");
        printf("3.查询当前费用\n");
        printf("4.退房\n");
        printf("5.返回主界面菜单\n");
        scanf("%d",&step);
        if(step<1||step>5)
            {
            printf("\n您的输入有误,请在1-5之间重新输入\n");
            system("pause");
            }
        }while(step<1||step>5);
        switch(step){
        case 1:CheckIn();break;
        case 2:ScanRoom();break;
        case 3:CalFee();break;
        case 4:CheckOut();break;
        case 5:return 0;
    }
    printf("\n请问你还需要执行其他的管理操作吗?\n");
    printf("1.是\n");
    printf("2.否\n");
    do{
        scanf("%d",&step);
        if(step<1||step>2)
            {
                printf("\n您的输入有误,请在1-2之间重新输入\n");
            }
    }while(step<1||step>2);
    }while(step==1);
    return 0;
}
int main()
{
    int step;
    BuildRoom();
    do{                //主程序循环
        do{          //选择界面循环
        system("cls");
        printf("\t\t  *  欢迎使用酒店管理系统  * \n");
        printf("\t\t_____________________________\n");
        printf("\n\t\t||\t1.登记入住\t  ||\n");
        printf("\t\t||\t2.查询入住情况\t  ||\n");
        printf("\t\t||\t3.查询当前费用\t  ||\n");
        printf("\t\t||\t4.办理退房    \t  ||\n");
        printf("\t\t||\t5.退出系统\t  ||\n");
        printf("\t\t_____________________________\n");
        scanf("%d",&step);
        if(step<1||step>5)
            {
            printf("\n您的输入有误,请在1-10之间重新输入\n");
            system("pause");
            }
        }while(step<1||step>5);
        switch(step){
        case 1:CheckIn();break;
        case 2:ScanRoom();break;
        case 3:CalFee();break;
        case 4:CheckOut();break;
        case 5:exit(0);
    }
    printf("\n请问你还需要执行其他的管理操作吗?\n");
    printf("1.是\n");
    printf("2.否\n");
    do{
        scanf("%d",&step);
        if(step<1||step>2)
            {
                printf("\n您的输入有误,请在1-2之间重新输入\n");
            }
    }while(step<1||step>2);
    }while(step==1);
    return 0;
}

以上就是“C语言如何实现简单酒店管理系统”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI