C语言程序设计客房管理系统源码和报告_第1页
C语言程序设计客房管理系统源码和报告_第2页
C语言程序设计客房管理系统源码和报告_第3页
C语言程序设计客房管理系统源码和报告_第4页
C语言程序设计客房管理系统源码和报告_第5页
免费预览已结束,剩余14页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、« C 语言程序设计综合实验报告一、需求分析编写一个客房管理系统,提供键盘式菜单实现功能选择,功能包括:用户登记、 统计、查询和用户信息修改。软件平台:CODEBLOCKS二、整体设计整个客房管理系统被设计为用户登记模块、统计模块、查询模块和修改模块。数 据以TXT格式存储,支持保存信息。三、详细设计客房管理系统(1)用户登记模块数组,通过函数rea问号,判断是登记信息,把dfile卡读 否已袤被 数据卷入坟txt文件用到用,若占用模重却room斫选择Roomi攵组代 追.过readfi四木用户选择想耍入房问号模若没有占savefile 厩etxt用,川示4住的房 俞入加信息到txt

2、块读取用户输入的的房间号调用savefile函数存储登记信息(2)统计模块 读取txt信息到结构体数组room,提示用户选择统计方式,设置计数器,顺序 遍历Room©:组,1、计数器记录数组数,即总客房数2、判断每一个数组中的结构体的时间是否和需要查询的日期相同,若相同,计 数器加一调用readfile函数,读取信息选择统计方式1、统计总客房数(3)查询模块2、按时间统计调用readfile 函数,将信息读入 通过基本查找算法查找Roomft组room结构体数组中,提示用户选择查询方式, 可以按房间号、价格、房间标记、用户姓名、0(4)修改模块调用readfile 函数,读取信息到r

3、oom结构体数组,提示用户输入需要修改的房问号,采用基本查找算法在数组中找到要修改的数据,提示用户重新更改房间信息,最后将结构体数组重新写入文件保存。调用readfile (读取文输入需要查询的房间号遍历每一个结构体 j四、源代码#include <stdio.h>#include <stdlib.h>#include <string.h>#define M 80/客户结构体typedef struct clientchar name12;/姓名int sex;/性别int age;/ 年龄char id20;/身份证号int year;/入住时间int m

4、onth;int date;CLIENT;/客房结构体struct Hotelint roomid;int tel;/ 用户的话int price;/ 价格int sign;/默认标记为空房间CLIENT client_list;/客户信息roomM;void Menu(); / 目录界面void dengji(struct Hotel room);void savefile(struct Hotel room,int i);int readfile(struct Hotel room);void tongji(struct Hotel room);void chaxun(struct Hot

5、el room);void printmessage(struct Hotel room,int n);void xiugai(struct Hotel room);/主函数int main()int n;char reply;Menu();doprintf(" 请输入选项对应的数字: n");scanf("%d",&n);while(n!=1&&n!=2&&n!=3&&n!=4)printf(" 请输入各选项对应的数字! n");scanf("%d",&am

6、p;n);switch (n)case 1:dengji(room);break;case 2:tongji(room);break;case 3:chaxun(room);break;case 4:xiugai(room);break;printf(" 是否还要进入其它选项?(回复Y 或 y 继续) n");scanf(" %c",&reply);while (reply='y'|reply='Y');return 0;/系统目录void Menu()printf("*客房管理系统*n");)

7、;););printf("ttt 1登记n"printf("ttt 2统计n"printf("ttt 3查询n"printf("ttt 4修改 n");printf("*n");/登记客户信息 void dengji(struct Hotel room)int x,j,i,flag;char answer;doi=readfile(room);doflag=0;printf(" 输入您想入住的房间号: (三位数) n");scanf("%3d",&

8、x);for(j=0;j<i;j+)if(roomj.roomid=x)printf(" 该房间已经被占用! n");flag=1;while(flag>0);roomi+1.roomid=x;printf(" 请输入您的电话:(仅支持六位数号码)n");scanf("%d",&roomi+1.tel);printf(" 入住价格 n");scanf("%d",&roomi+1.price);printf(" 请输入您的名字n");scanf(&q

9、uot;%s",roomi+1.client_);printf(" 性别: ( 1 表示女, 0 表示男) n");scanf("%d",&roomi+1.client_list.sex);printf(" 您的年龄: n");scanf("%d",&roomi+1.client_list.age);printf(" 您的 id : n");scanf("%s",roomi+1.client_list.id);printf( &qu

10、ot; 请输入入住年月日(格式: 2015 11 11) n");scanf("%4d%2d%2d",&roomi+1.client_list.year,&roomi+1.client_list.month,&roomi+1.clien t_list.date);savefile(room,i+1);printf(" 是否还要继续登记?(回复Y 或 y 继续) n");scanf(" %c",&answer);while(answer='Y'|answer='y'

11、;);/读取 txt 中的信息int readfile(struct Hotel room)FILE *fp;int i;if(fp=fopen("room.txt","r")=NULL)printf("Failure to open score.txt!n");exit(0);for (i=0;!feof(fp);i+)fscanf(fp,"%5d",&roomi.roomid);fscanf(fp,"%6d",&roomi.price);fscanf(fp,"%15

12、d",&roomi.tel);fscanf(fp,"%12s",roomi.client_);fscanf(fp,"%4d",&roomi.client_list.sex);fscanf(fp,"%6d",&roomi.client_list.age);fscanf(fp,"%20s",roomi.client_list.id);fscanf(fp,"%7d",&roomi.client_list.year);fscanf(fp,&qu

13、ot;%5d",&roomi.client_list.month);fscanf(fp,"%5d",&roomi.client_list.date);fclose(fp);return i;/保存结构体数组信息到文件void savefile(struct Hotel room,int i)FILE *fp;if(fp = fopen("room.txt","a")=NULL)printf("Failure to open score.txt!n");exit(0);fprintf(fp,

14、"%5d%6d%15d%12s%4d%6d%20s%7d%5d%5d",roomi.roomid,roomi.price,roomi.tel,roomi.client_,roomi.client_list.sex,roomi.client_list.age,roomi.client_list.id,roomi.client_list.year,roomi.client_list.month,roomi.client_list.date);fclose(fp);/统计模块void tongji(struct Hotel room)int n,x;int ye

15、ar,month,day,j,count=0;x=readfile(room);printf(" 请选择统计方式: 1统计房客数,2统计某一天的房客数n");scanf("%d",&n);switch (n)case 1:printf(" 客房总数为: %dn",x);break;case 2:printf(" 请输入具体时间: n");scanf("%d%d%d",&year,&month,&day);for(j=0;j<x;j+)if(roomj.cli

16、ent_list.year=year&&roomj.client_list.month=month&&roomj.client_list.date =day)count+;printf("%d 年 %d 月 %d 号的房客数为 %d",year,month,day,count);/查询模块void chaxun(struct Hotel room)int n,x,roomid,price,j;char name12,id20;x=readfile(room);printf(" 按房间号查询请按1 ;按价格查询请按2;按用户姓名查询请

17、按3;按身份证号码查询请按4n");scanf("%d",&n);switch(n)case 1:printf(" 请输入房间号: n");scanf("%d",&roomid);for(j=0;j<x;j+)if(roomj.roomid=roomid)print(room,j);break;case 2:printf(" 请输入价格: n");scanf("%d",&price);for(j=0;j<x;j+)if(roomj.price=pri

18、ce)print(room,j);break;case 3:printf(" 请输入客户姓名: n");scanf("%s",name);for(j=0;j<x;j+)if(strcmp(roomj.client_,name)=0)print(room,j);break;case 4:printf(" 请输入身份证号码: n");scanf("%s",id);for(j=0;j<x;j+)if(strcmp(roomj.client_list.id,id)=0)print(room,j

19、);/打印void print(struct Hotel room,int j)printf("%5d%6d%15d%12s%4d%6d%20s%7d%5d%5dn",roomj.roomid,roomj.price,roomj.tel,roomj.client_,roomj.client_list.sex,roomj.client_list.age,roomj.client_list.id,roomj.client_list.year, roomj.client_list.month, roomj.client_list.date);void print

20、message(struct Hotel room,int n)int j;for(j=0;j<n;j+)printf("%5d%6d%15d%12s%4d%6d%20s%7d%5d%5dn",roomj.roomid,roomj.price,roomj.tel,roomj.client_, roomj.client_list.sex, roomj.client_list.age, roomj.client_list.id, roomj.client_list.year, roomj.client_list.month, roomj.client_l

21、ist.date);/修改模块void xiugai(struct Hotel room)int i, m, roomid;m = readfile(room);printf(" 请选择房间号: n");scanf("%d",&roomid);for(i=0;i<m;i+)if(roomi.roomid=roomid)printf(" 请输入您的电话:n");scanf("%d",&roomi.tel);printf(" 入住价格 n");scanf("%d&qu

22、ot;,&roomi.price);printf(" 请输入您的名字n");scanf("%s",roomi.client_);printf(" 性别: n");scanf("%d",&roomi.client_list.sex);printf(" 您的年龄: n");scanf("%d",&roomi.client_list.age);printf(" 您的 id : n");scanf("%s&quo

23、t;,roomi.client_list.id);scanf("%4d%2d%2d",&roomi.client_list.year,&roomi.client_list.month,&roomi.client_list.da te);saveall(room,m);/保存所有信息到 txt 文件void saveall(struct Hotel room,int m)int j;FILE *fp;if(fp = fopen("room.txt","w")=NULL)printf("Failure t

24、o open score.txt!n");exit(0); for(j=0;j<m;j+) fprintf(fp,"%5d%6d%15d%12s%4d%6d%20s%7d%5d%5d", roomj.roomid,roomj.price,roomj.tel,roomj.client_,Roomj.client_list.sex,roomj.client_list.age,roomj.client_list.id,roomj.client_list.year,roomj.client_list.month, roomj.client_list.date);fclose(fp);

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论