700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > C语言课程设计任务书(酒店房间登记与计费管理系统)

C语言课程设计任务书(酒店房间登记与计费管理系统)

时间:2019-05-10 03:12:13

相关推荐

C语言课程设计任务书(酒店房间登记与计费管理系统)

C语言课程设计任务书(酒店房间登记与计费管理系统)

题目:酒店房间登记与计费管理系统

功能: 1、屏幕上出现一个界面,让操作员能够方便的选择所需要进行的操作,包括登记入住、查询房间的入住情况、查询当前费用、结账退房等操作。

2、对不同标准的房间实施不同的收费标准,也可以按天收费或按小时收费,可根据顾客需要在登记的入住的时候进行选择。

3、在结账退房时,根据入住的时间,计费方式和房间单价计算出总费用。

**随便写了下,就献丑啦**

/1/20已更新,使用visual studio 无报错,功能正常

/11/12更新,Xcode 13 无报错,功能正常​​​​​​​

//头文件#include <stdio.h>#include <stdlib.h>#include<string.h>#include <time.h>#include <memory.h>//定义宏#define N 100//酒店房间容量#define nice_Day 2000 //豪华房间一天多少钱?(住不起)#define nice_Hour 100 //豪华房间一小时多少钱?(住不起)#define poor_Day 1000 //普通房间一天多少钱?(也住不起)#define poor_Hour 50 //普通房间一小时多少钱?(看起来住得起)static int roomNumber = 0; //已开房间数(含正在开)static int localTime; //房间持续时间/*自定义函数声明*/int createRoom();//登记入住int checkRoom(); //查询房间入住情况int checkMoney(); //查询当前费用int getout();//结账退房void menu();//菜单打印int clearNext();//清屏打印菜单下一步int comTime(struct time newT, struct time old);//计算时间差int comMoney(int s, int i); //计算金钱int scanRoom(int x);//查找房间/*自定义函数声明*//*结构体部分*/struct time { //时间结构体int year;int month;int date;int hour;int minute;};static struct time nowTime;//现在时间struct room { //房间结构体int roomNum; //房间号码char level[5]; //房间规格char moneyType[5]; //计费方式char sTime[20]; //字符串形式的时间struct time inTime; //入住时间struct time outTime;//退房时间}room[N + 1];/*结构体部分*//*主函数部分*/int main() {int x;menu(); //打印菜单scanf("%d", &x);while (1) {switch (x) {//选择结构case 0:; break;case 1:x = createRoom(); break;case 2:x = checkRoom(); break;case 3:x = checkMoney(); break;case 4:x = getout(); break;default:printf("输入错误,请重新输入\n");scanf("%d", &x);}}return 0;}/*主函数部分*//*自定义函数部分*///菜单打印函数void menu() {printf("---------------欢迎来到XXXX酒店------------\n\n");printf("---今日特价:豪华房间(%d一天/%d一小时)---\n", nice_Day, nice_Hour);printf("---今日特价:标准房间(%d一天/%d一小时)----\n\n", poor_Day, poor_Hour);printf("------------------1.登记入住-------------------\n\n");printf("------------------2.查询房间入住情况-----------\n\n");printf("------------------3.查询当前费用---------------\n\n");printf("------------------4.结账退房-------------------\n\n");printf("请选择要进行的操作:");}//时间打印函数void showTime(struct time x) { //按格式打印时间printf("%d年%d月%d日%d时%d分", x.year, x.month, x.date, x.hour, x.minute);}//清屏打印菜单下一步int clearNext() {int x;system("cls");menu();scanf("%d", &x);return x;}//金额计算函数(返回金额)int comMoney(int s, int i) {float t;int mt;char nice_Level[10] = "豪华";char poor_Level[10] = "标准";char day_MonetType[5] = "天";char hour_MoneyType[10] = "小时";if (strcmp(room[i].level, nice_Level) == 0) { //豪华房间if (strcmp(room[i].moneyType, day_MonetType) == 0) { //比较字符串t = s / (3600 * 24);if (s % (3600 * 24) != 0)//不满一天算一天mt = (int)t + 1;elsemt = (int)t;localTime = mt;return nice_Day * mt;}if (strcmp(room[i].moneyType, hour_MoneyType) == 0) {t = s / 3600;if (s % 3600 != 0)mt = (int)t + 1; //不满一小时算一小时elsemt = (int)t;localTime = mt;return nice_Hour * mt;}}if (strcmp(room[i].level, poor_Level) == 0) { //标准房间if (strcmp(room[i].moneyType, day_MonetType) == 0) { //比较字符串t = s / (3600 * 24);if (s % (3600 * 24) != 0)//不满一天算一天mt = (int)t + 1;elsemt = (int)t;return poor_Day * mt;}if (strcmp(room[i].moneyType, hour_MoneyType) == 0) {t = s / 3600;if (s % 3600 != 0)mt = (int)t + 1; //不满一小时算一小时elsemt = (int)t;return poor_Hour * mt;}}return 0;}//房间查找函数(返回房间数组号)int scanRoom(int x) {int i;for (i = 0; i < N; i++) {if (room[i].roomNum == x)return i;}return N + 1;}//时间差计算函数(返回时间差(单位s))int comTime(struct time NewT, struct time old) {time_t t1;time_t t2;struct tm OldTime;struct tm NewTime;memset(&OldTime, 0x0, sizeof(OldTime)); //分配内存空间OldTime.tm_year = old.year - 1900;// 年表示为 - 1900 = 119OldTime.tm_mon = old.month;OldTime.tm_mday = old.date;OldTime.tm_hour = old.hour;OldTime.tm_min = old.minute;memset(&NewTime, 0x0, sizeof(NewTime));//分配内存空间NewTime.tm_year = NewT.year - 1900;NewTime.tm_mon = NewT.month;NewTime.tm_mday = NewT.date;NewTime.tm_hour = NewT.hour;NewTime.tm_min = NewT.minute;t1 = mktime(&NewTime);t2 = mktime(&OldTime);return (t1 - t2); //返回时间差(单位s)}//1、登记入住int createRoom() { //登记入住int num, i, x;char sTime[20];printf("请输入您要登记的房间数\n");scanf("%d", &num);roomNumber += num;if (roomNumber > N) { //确认是否超出容量printf("对不起,我们无法提供那么多房间\n");roomNumber -= num;}else {printf("我们能提供那么多房间\n请录入房间信息\n");for (i = 0; i < num; i++) {printf("请输入房间规格(豪华or标准)\n");scanf("%s", &room[i].level);printf("请输入计费方式(天or小时)\n");scanf("%s", &room[i].moneyType);printf("请输入入住时间(06月24日15时17分示例-06-24-15-17)\n");scanf("%s", &sTime);sscanf(sTime, "%4d-%2d-%2d-%2d-%2d", &room[i].inTime.year, &room[i].inTime.month, &room[i].inTime.date, &room[i].inTime.hour, &room[i].inTime.minute);printf("请输入房间号码\n");scanf("%d", &room[i].roomNum);printf("此房间为%d号房间,请牢记\n", room[i].roomNum);}}return clearNext();}//2、查询房间入住情况int checkRoom() {int x, i;printf("您要查询的房间号为");scanf("%d", &x);do {i = scanRoom(x);if (i == N + 1) {printf("对不起,没有此房间的相关登记信息\n是否退回主菜单,是请输入999,否请输入您要查询的房间号");scanf("%d", &x);}else {printf("\n%d号房间,房间类型%s,计费方式%s\n是否退回主菜单,是请输入999,否请输入您要查询的房间号", x, room[i].level, room[i].moneyType);scanf("%d", &x);}} while (x != 999);return clearNext();}//3、查询当前费用int checkMoney() {int x, money, i = 101;char sTime[20];printf("请输入您要查询的房间号码");scanf("%d", &x);do {i = scanRoom(x);if (i == N + 1) {printf("对不起,没有此房间的相关登记信息\n是否退回主菜单,是请输入999,否请输入您要查询的房间号");scanf("%d", &x);}else {printf("%d号房间,登记入住时间为", x);showTime(room[i].inTime);printf("请输入当前时间(格式同前)\n");scanf("%s", &sTime);sscanf(sTime, "%4d-%2d-%2d%2d-%2d", &nowTime.year, &nowTime.month, &nowTime.date, &nowTime.hour, &nowTime.minute);x = comTime(nowTime, room[i].inTime);money = comMoney(x, i);printf("当前费用为%d元\n是否退回主菜单,是请输入999,否请输入您要查询的房间号", money);scanf("%d", &x);}} while (x != 999);return clearNext();}//4、结账退房int getout() {int x, money, i = 101, t;char sTime[20];printf("请输入您要退的房间号");scanf("%d", &x);do {i = scanRoom(x);if (i == N + 1) {printf("对不起,没有此房间的相关登记信息\n是否退回主菜单,是请输入999,否请输入您要退的房间号");scanf("%d", &x);}else {printf("请输入当前时间(格式同前)\n");scanf("%s", &sTime);sscanf(sTime, "%4d-%2d-%2d-%2d-%2d", &nowTime.year, &nowTime.month, &nowTime.date, &nowTime.hour, &nowTime.minute);t = comTime(nowTime, room[i].inTime);money = comMoney(x, i);printf("%d号房间,房间类型%s,计费方式%s,计费时长%d,共计%d元\n感谢您的入住!\n", x, room[i].level, room[i].moneyType, localTime, money);for (i; i < N + 1; i++)room[i] = room[i + 1];printf("是否退回主菜单,是请输入999,否请输入您要退的房间号");scanf("%d", &x);}} while (x != 999);return clearNext();}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。