本文实例为大家分享了C语言实现酒店客房管理系统的具体代码,供大家参考,具体内容如下
设计目标:设计一个酒店客房管理系统,用C语言实现。对该系统的要求如下:
一、需求描述
系统角色:
1.总台服务员
能够根据住客需求完成住客登记任务,并完成客房管理功能。
1)登记入住功能
2)结账功能
3)查询房间功能
4)客房信息打印
5)统计功能
2.系统管理员
能够添加、删除和修改系统用户(总台服务员),设置用户权限。包括
1)添加新用户
2)删除用户
3)修改用户权限
二、系统流程描述
系统启动则进入登陆菜单。
1.登陆流程
(1)程序运行,显示登陆界面,请用户输入角色、账号及密码。
(2)用户输入账号密码后,系统校验正确与否,正确则进入功能菜单。错误则提示输入错误,继续显示登陆界面。
2.总台服务员使用流程描述:
1)主界面:
总台服务员登陆成功后,系统显示功能菜单:“1. 登记入住 2. 结账3.查询客房信息 4.客房信息打印6.客房统计7.退出”。
2)登记入住
(1)服务员输入数字1,系统进入登记入住界面,要求总台服务员输入客户信息及房间信息。
(2)总台服务员输入客户姓名、性别、年龄、身份证号、所需房间类型、房间号、房间单价、入住天数。
(3)系统根据输入信息显示应付费用。总台服务员收取费用后输入收费金额。系统在客房记录中添加该客户的记录并写入磁盘。
(4)系统应保证在所需房间不足时报告错误。
3)结账
(1)服务员输入数字2,系统进入结账界面,要求总台服务员输入房间信息。
(2)总台服务员输入房间号,系统显示客户名称、房间单价、入住天数、总金额、应付房款、实付房款、欠费金额或退款额等相关信息。并提示总台服务员收取欠费金额或退还押金。
(3)总台服务员输入补交房款或退还押金数额后,系统将该客户的入住记录放入历史入住记录中。并将该房间设置为空闲。
4)查询客房信息
(1)服务员输入数字3,系统进入查询界面,并显示“1.按顾客名称查询 2.按房间号查询”。
(2)总台服务员输入1.系统提示服务员输入顾客名称,输入后,系统显示该顾客的入住记录,包括顾客信息及入住房间号、房间单价、入住天数、总金额等相关信息。 如无该顾客的信息则打印“没有此客户的入住信息。”
(3)总台服务员输入2.系统提示服务员输入房间号及查询起止时间。输入房间号及起止时间后,系统显示该房间从起始时间到结束时间的入住客户的姓名、身份证号、入住天数等信息。
5)客房信息打印
服务员输入数字4,系统进入客房信息打印界面。系统打印所有房间信息,按房间号排序,包括房间号、房间类型、是否有人入住、入住人数、入住天数等信息。
6)客房统计
服务员输入数字5,系统进入客房统计界面。系统打印本日的入住人数、入住房间数、空置房间数、入住率统计、空房率统计、实收房款。
7)退出
服务员选择退出,则系统返回到登陆界面。
3.系统管理员使用流程
1)主界面:
管理员登陆成功后,系统显示功能菜单:“1.用户资料打印 2.添加用户 3.删除用户 4.修改用户权限 5退出”
2)用户资料打印:
管理员选择用户资料打印功能,则进入用户资料打印界面,提示管理员输入用户账号,管理员输入后,系统打印该用户的账号、密码、角色、权限等信息。
3)添加用户
管理员选择添加用户功能,则进入添加用户界面,提示管理员输入用户账号和初始密码。管理员输入后,系统打印该用户相关信息并返回主界面。
4)删除用户
管理员选择删除用户功能,则进入删除用户界面,提示管理员输入要删除的用户账号。管理员输入后,系统提示已删除该用户信息并返回主界面。
5)修改用户权限
管理员选择修改用户权限功能,则进入修改用户权限界面,提示管理员输入要修改的用户账号。管理员输入后,系统打印该用户的权限,并提示管理员输入要修改后的权限,管理员输入后,系统打印该用户的信息并返回主界面。
6)退出
管理员选择退出,则系统返回到登陆界面。
1)声明部分
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<Windows.h> #include<string.h> #define LEN sizeof(struct hotel) typedef struct hotel { int might1; //管理员访问权限1 int might2; //服务员访问权限2 int might3; //客房访问权限3 char account[20]; //账户 char possword[20]; //密码 char name[20]; //姓名 char sex[5]; //性别 int age; //年龄 char ID[20]; //身份证号 char time [20]; //入住时间 char phone[20]; //联系电话 char room[15]; //房间类型 int numder; //房间号 int price; //房间单价 int day; //入住天数 int cope; //总价 int payment; // int debt; char manage[5]; //是否结账 struct hotel *next; // }LinkList; void menu1( struct hotel *p); void menu22( struct hotel *p); void menu2( struct hotel *p); void menu33( struct hotel *p); void menu3( struct hotel *p); void ADD(LinkList *p); //添加客户 void ADD1(LinkList *p); //添加服务员 void amend(LinkList *p); //修改自己或服务员的密码 void Remove(LinkList *p); //删除服务员 void Seller(LinkList *p); //客房结账 void amend2(LinkList *p); //修改客户信息 void Inquire(LinkList *p); //客房查询 void statistics1(LinkList *p); //某日客房统计 void statistics3(LinkList *p); //客房统计 void statistics2(LinkList *p); //服务员统计 void set(LinkList *p); //设置房间数量 void statistics(LinkList *p); //客房打印 |
2)添加客户
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
void ADD(LinkList *p) { struct hotel *q, *n = p; struct hotel *h = p->next; struct hotel *m = p->next; int flag = 0; system ( "cls" ); q = ( struct hotel *) malloc ( sizeof ( struct hotel)); q->next = NULL; printf ( "请依次输入:客户姓名,性别,年龄,ID,入住时间(年.月.日),联系电话\n" ); scanf ( "%s%s%d%s%s%s" , q->name, q->sex, &q->age, q->ID, q-> time , q->phone); printf ( "请依次输入客户的:房间类型,房间号,房间单价,入住天数,付款\n" ); scanf ( "%s%d%d%d%d" , q->room, &q->numder, &q->price, &q->day, &q->payment); strcpy (q->manage, "NO" ); getchar (); q->cope = q->price *q->day; q->debt = q->cope - q->payment; q->might1 = 0; q->might2 = 0; q->might3 = 3; strcpy (q->account, "0" ); strcpy (q->possword, "0" ); if (q->numder>m->age) { printf ( "超出房间限额!\n" ); Sleep(2000); menu3(p); } while (h != NULL) { if (h->numder == q->numder && strcmp (h->manage, "NO" ) == 0) { flag = 1; printf ( "此房间客户暂未退房" ); Sleep(1000); ADD(p); break ; } h = h->next; } while (n->next != NULL) { n = n->next; } n->next = q; if (flag == 0) { printf ( "\t添加成功\n" ); printf ( "\t请按回车键返回菜单\n" ); } else printf ( "\t添加失败\n" ); getchar (); menu3(p); } |
3)添加服务员
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
void ADD1(LinkList *p) { struct hotel *q, *n = p; struct hotel *h = p->next; int flag = 0; system ( "cls" ); q = ( struct hotel *) malloc ( sizeof ( struct hotel)); q->next = NULL; printf ( "请输入添加的账号\n" ); scanf ( "%s" , q->account); printf ( "请输入添加的密码\n" ); scanf ( "%s" , q->possword); getchar (); q->might1 = 0; q->might2 = 2; q->might3 = 0; strcpy (q->name, "0" ); strcpy (q->sex, "0" ); q->age = 0; strcpy (q->ID, "0" ); strcpy (q->room, "0" ); strcpy (q->manage, "0" ); strcpy (q-> time , "0" ); strcpy (q->phone, "0" ); q->numder = 0; q->price = 0; q->day = 0; q->debt = 0; q->payment = 0; q->cope = 0; while (h != NULL) { if ( strcmp (h->account, q->account) == 0) { flag = 1; printf ( "账号重复!" ); Sleep(1000); menu2(p); break ; } h = h->next; } while (n->next != NULL) { n = n->next; } n->next = q; if (flag == 0) { printf ( "\t添加成功\n" ); printf ( "\t请按回车键返回菜单\n" ); } else printf ( "\t添加失败\n" ); getchar (); menu2(p); } |
4)修改密码或账户
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
void amend(LinkList *p) { struct hotel *q = p->next; char acc[20], poss[20], ac[20]; int flag = 0, i; system ( "cls" ); printf ( "请输入要修改的账号:" ); scanf ( "%s" , acc); while (q != NULL) { if ( strcmp (q->account, acc) == 0) { flag = 1; printf ( "1.仅修改密码\n2.密码账户均修改\n" ); scanf ( "%d" , &i); if (i == 1) { printf ( "请输入新密码:" ); scanf ( "%s" , poss); strcpy (q->possword, poss); break ; } if (i == 2) { printf ( "请输入新账号:" ); scanf ( "%s" , ac); getchar (); printf ( "请输入新密码:" ); scanf ( "%s" , poss); strcpy (q->account, ac); strcpy (q->possword, poss); break ; } } q = q->next; } if (flag == 0) { printf ( "账户错误!\n" ); printf ( "\t请按回车键返回菜单\n" ); } if (flag == 1) { printf ( "修改成功!\n" ); printf ( "\t请按回车键返回菜单\n" ); } getchar (); getchar (); menu2(p); } |
5)修改客户信息
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
void amend2(LinkList *p) { struct hotel *q = p->next; int i, j = 0, k; char na[20], se[5], I[20], ti[20], Ph[20], roo[15]; int ag, nu, pr, da; system ( "cls" ); printf ( "请输入修改内容的房间号:\n" ); scanf ( "%d" , &nu); while (q != NULL) { if (q->numder == nu) { printf ( "请选择将要修改的内容:\n" ); printf ( "1.姓名\n" ); printf ( "2.性别\n" ); printf ( "3.年龄\n" ); printf ( "4.身份证号\n" ); printf ( "5.联系电话\n" ); printf ( "6.入住时间\n" ); printf ( "7.房间号" ); printf ( "8.房间类型\n" ); printf ( "9.房间单价\n" ); printf ( "10.入住天数\n" ); printf ( "11.返回上一层\n" ); scanf ( "%d" , &i); switch (i) { case 1: printf ( "请输入新修改的姓名\n" ); scanf ( "%s" , na); j = 1; strcpy (q->name, na); break ; case 2: printf ( "请输入新修改的性别\n" ); scanf ( "%s" , se); j = 1; strcpy (q->sex, se); break ; case 3: printf ( "请输入新修改的年龄\n" ); scanf ( "%d" , &ag); j = 1; q->age = ag; break ; case 4: printf ( "请输入新修改的身份证号\n" ); scanf ( "%s" , I); j = 1; strcpy (q->ID, I); break ; case 5: printf ( "请输入新修改的联系电话\n" ); scanf ( "%s" , Ph); j = 1; strcpy (q->phone, Ph); break ; case 6: printf ( "请输入新修改的入住时间\n" ); scanf ( "%s" , ti); j = 1; strcpy (q-> time , ti); break ; case 7: printf ( "请输入新修改的房间号\n" ); scanf ( "%d" , &nu); j = 1; q->numder = nu; break ; case 8: printf ( "请输入新修改的房间类型\n" ); scanf ( "%s" , roo); j = 1; strcpy (q->room, roo); break ; case 9: printf ( "请输入新修改的房间单价\n" ); scanf ( "%d" , &pr); j = 1; q->price = pr; q->cope = (q->price)*(q->day); q->debt = q->cope - q->payment; break ; case 10: printf ( "请输入新修改的入住天数\n" ); scanf ( "%d" , &da); j = 1; q->day = da; q->cope = q->price*q->day; q->debt = q->cope - q->payment; break ; case 11:menu3(p); break ; default : printf ( "请输入合法量!\n" ); break ; } } q = q->next; } if (j == 1) { printf ( "修改成功!\n" ); } if (j == 0) { printf ( "修改失败\n" ); } printf ( "按回车键返回\n" ); getchar (); getchar (); menu3(p); } |
6)删除
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
void Remove(LinkList *p) { struct hotel *n = p->next; struct hotel *h = p->next->next; int flag = 0; char acc[20]; system ( "cls" ); printf ( "请输入要删除的账户:" ); scanf ( "%s" , acc); while (h != NULL) { if ( strcmp (h->account, acc) == 0) { n->next = h->next; flag = 1; free (h); break ; } n = h; h = h->next; } if (flag == 1) { printf ( "删除成功!\n" ); printf ( "\t请按回车键返回菜单\n" ); } if (flag == 0) { printf ( "删除失败!\n" ); printf ( "\t请按回车键返回菜单\n" ); } getchar (); getchar (); menu2(p); } |
7)结账
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
void Seller(LinkList *p) { struct hotel *q = p->next; char man[5]; int nu, i; int flag = 0; system ( "cls" ); printf ( "请输入该客户房间号:" ); scanf ( "%d" , &nu); while (q != NULL) { if ((q->numder == nu)&& strcmp (q->manage, "NO" )==0) { flag = 1; printf ( "客户:%s 身份证号:%s 房间号:%d 房间单价:%d 入住天数:%d 实付:%d 再付:%d 共计%d元\n" , q->name, q->ID, q->numder, q->price, q->day, q->payment, q->debt, q->cope); printf ( "再付%d\n" , q->debt); printf ( "1.确定结账\n2.返回\n" ); scanf ( "%d" , &i); switch (i) { case 1:q->debt = 0; q->payment = q->cope; strcpy (q->manage, "YES" ); break ; case 2:menu3(p); break ; } } q = q->next; } if (flag == 0) { printf ( "\t无该客户信息\n" ); printf ( "\t请按回车键返回菜单\n" ); } else { printf ( "结账成功\n" ); printf ( "\t请按回车键返回菜单\n" ); } getchar (); getchar (); menu3(p); } |
8)客房查询
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
void Inquire(LinkList *p) { struct hotel *q = p->next; int nu; char na[20]; int a; int flag = 0; system ( "cls" ); printf ( "1.按照姓名查询;\n2.按照房间号查询;\n" ); scanf ( "%d" , &a); getchar (); if (a == 1) { printf ( "请输入姓名:" ); scanf ( "%s" , na); while (q != NULL) { if ( strcmp (q->name, na) == 0) { flag = 1; printf ( "姓名:%s 性别:%s 年龄:%d 身份证号:%s 入住时间:%s 联系电话:%s" , q->name, q->sex, q->age, q->ID, q-> time , q->phone); printf ( "房间类型:%s 房间号:%d 房间单价:%d 入住天数:%d 总计:%d 实付:%d 再付:%d 是否结账:%s\n" , q->room, q->numder, q->price, q->day, q->cope, q->payment, q->debt, q->manage); } q = q->next; } } if (a == 2) { printf ( "请输入房间号:" ); scanf ( "%d" , &nu); while (q != NULL) { if (q->numder == nu) { flag = 1; printf ( "姓名:%s 性别:%s 年龄:%d 身份证号:%s 入住时间:%s 联系电话:%s" , q->name, q->sex, q->age, q->ID, q-> time , q->phone); printf ( "房间类型:%s 房间号:%d 房间单价:%d 入住天数:%d 总计:%d 实付:%d 再付:%d 是否结账:%s\n" , q->room, q->numder, q->price, q->day, q->cope, q->payment, q->debt, q->manage); } q = q->next; } } if (flag == 0) { printf ( "\t无该客户信息\n" ); printf ( "\t请按回车键返回菜单\n" ); } if (flag == 1) { printf ( "\t查询结束\n" ); printf ( "\t请按回车键返回菜单\n" ); } getchar (); getchar (); menu3(p); } |
9)某日客房统计
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
void statistics1(LinkList *p) { struct hotel *q = p->next; int m = 0, i = 0; float a = 0, b = 0, c = 0,k=0; char tim[20]; system ( "cls" ); printf ( "请输入统计时间:\n" ); scanf ( "%s" , tim); while (q != NULL) { if ( strcmp (q-> time , tim) == 0) { a = a + 1; if (m == 0) { printf ( "%s结账房间有\n" , tim); m = m + 1; } if ( strcmp (q->manage, "YES" ) == 0) { printf ( "%d\n" , q->numder); k= k+1; b = b + 1; } if (b == 0) { printf ( "无\n" ); b = b + 1; } if (i == 0) { printf ( "%s入住房间有\n" , tim); i = i + 1; } if ( strcmp (q->manage, "NO" ) == 0) { printf ( "%d\n" , q->numder); c = c + 1; } if (c == 0) { printf ( "无入住\n" ); } } q = q->next; } if (a != 0) { printf ( "此日结账率:百分之%0.0f %\n" , (k / a) * 100); printf ( "此日入住率:百分之%0.0f %\n\n" , (c / a) * 100); } if (a == 0) { printf ( "\t暂时无客户信息\n" ); } printf ( "\t请按回车键返回菜单\n" ); getchar (); getchar (); menu3(p); } |
10)客房统计
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
void statistics3(LinkList *p) { struct hotel *q = p->next->next; struct hotel *n = p->next; float m = p->next->age; int i, j = 0, k, c = 1; float a = 0, b = 0; system ( "cls" ); printf ( "空置房间有:\n" ); for (i = 1; i <= m; i++) { j = 0; q = p->next; while (q != NULL) { if (i == q->numder&& strcmp (q->manage, "NO" ) == 0) { c++; j = 1; } q = q->next; } if (j == 0) { printf ( "%d " , i); c++; } a++; } q = p->next; printf ( "\n" ); printf ( "暂住房间有:\n" ); while (q != NULL) { if ( strcmp (q->manage, "NO" ) == 0) { printf ( "%d " , q->numder); b++; k = 1; } q = q->next; } if (k = 0) { printf ( "暂无入住!\n" ); } printf ( "\n" ); printf ( "当前空房率:百分之%0.0f\n" , ((m - b) / m) * 100); printf ( "当前住房率:百分之%0.0f\n" , (b / m) * 100); printf ( "按回车键返回主菜单!\n" ); getchar (); getchar (); menu3(p); } |
11)服务员统计
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
void statistics2(LinkList *p) { struct hotel *q = p->next; int c = 0, i = 0; system ( "cls" ); while (q != NULL) { if (i == 0) { printf ( "账号 密码\n" ); i = 2; } if (q->might2 == 2) { printf ( "%s %s\n" , q->account, q->possword); c = c + 1; } q = q->next; } if (c == 0) { printf ( "暂无服务员信息\n" ); } printf ( "\t请按回车键返回菜单\n" ); getchar (); getchar (); menu2(p); } |
12)设置房间数量
1
2
3
4
5
6
7
8
9
10
11
12
13
|
void set(LinkList *p) { struct hotel *q = p->next; system ( "cls" ); printf ( "当前房间数量为:%d\n" , q->age); printf ( "请输入房间数量:\n" ); scanf ( "%d" , &(q->age)); printf ( "设置成功!\n" ); printf ( "按回车键返回菜单!\n" ); getchar (); getchar (); menu2(p); } |
13)客房打印
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
void statistics(LinkList *p) { struct hotel *q = p->next; system ( "cls" ); if (q == NULL) { printf ( "\t暂时无客户信息\n" ); } else { printf ( "姓名 性别 年龄 身份证号 入住时间 联系电话 房间类型 房间号 房间单价 入住天数 共计 实付 再付 是否结账 \n" ); while (q != NULL) { if (q->might3 == 3) { printf ( "%s %s %d %s %s %s %s %d %d %d %d %d %d %s \n" , q->name, q->sex, q->age, q->ID, q-> time , q->phone, q->room, q->numder, q->price, q->day, q->cope, q->payment, q->debt, q->manage); } q = q->next; } } printf ( "\t请按回车键返回菜单\n" ); getchar (); getchar (); menu3(p); } |
14)读入磁盘文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
void saveHotelFile(LinkList *L) { FILE *fp; LinkList *p; p = L->next; fp = fopen ( "hotel.txt" , "w" ); if (fp == NULL) { printf ( "无法打开此文件\n" ); exit (0); } while (p) { fprintf (fp, "%d %d %d %s %s %s %s %d %s %s %s %s %d %d %d %d %d %d %s \n" , p->might1, p->might2, p->might3, p->account, p->possword, p->name, p->sex, p->age, p->ID, p-> time , p->phone, p->room, p->numder, p->price, p->day, p->cope, p->payment, p->debt, p->manage); p = p->next; } fclose (fp); } |
15)开辟节点
1
2
3
4
5
6
7
8
9
10
|
void ListInsert(LinkList *L, LinkList *n) { LinkList *q = L; n->next = NULL; while (q->next != NULL) { q = q->next; } q->next = n; } |
16)向链表读取
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
void readHotelput(LinkList* L) { FILE * fp; LinkList* n; LinkList* m; char ch; char acc[20], po[20], na[20], se[5], I[20], ti[20], Ph[20], roo[15], man[5], a[20], b[20]; int mi1, mi2, mi3, ag, nu, pr, da, co, s, pa, de; fp = fopen ( "hotel.txt" , "r" ); if (fp == NULL) { fp = fopen ( "hotel.txt" , "w" ); } else { if ( fgetc (fp) == -1) { printf ( "此程序为首次使用,请自定义账号和密码\n" ); printf ( "账号:\n" ); scanf ( "%s" , a); getchar (); printf ( "密码:\n" ); scanf ( "%s" , b); getchar (); m = (LinkList*) malloc ( sizeof (LinkList)); strcpy (m->account, a); //初始账户 strcpy (m->possword, b); //初始密码 strcpy (m->name, "0" ); strcpy (m->sex, "0" ); strcpy (m->ID, "0" ); strcpy (m->room, "0" ); strcpy (m->manage, "0" ); strcpy (m-> time , "0" ); strcpy (m->phone, "0" ); m->might1 = 1; m->might2 = 0; m->might3 = 0; m->age = 0; m->numder = 0; m->price = 0; m->day = 0; m->debt = 0; m->payment = 0; m->cope = 0; m->next = NULL; L->next = m; } if ( fgetc (fp) != -1) { fseek (fp, -2L, 1); } while (! feof (fp)) { fscanf (fp, "%d %d %d %s %s %s %s %d %s %s %s %s %d %d %d %d %d %d %s " , &mi1, &mi2, &mi3, acc, po, na, se, &ag, I, ti, Ph, roo, &nu, &pr, &da, &co, &pa, &de, man); n = (LinkList*) malloc ( sizeof (LinkList)); strcpy (n->account, acc); strcpy (n->possword, po); strcpy (n->name, na); strcpy (n->sex, se); strcpy (n->ID, I); strcpy (n-> time , ti); strcpy (n->phone, Ph); strcpy (n->room, roo); strcpy (n->manage, man); n->might1 = mi1; n->might2 = mi2; n->might3 = mi3; n->age = ag; n->numder = nu; n->price = pr; n->day = da; n->debt = de; n->payment = pa; n->cope = co; ListInsert(L, n); /*n=n->next;*/ } } fclose (fp); } |
17)判断是否为服务员
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
void menu33( struct hotel *p) { int i = 0; struct hotel *h = p->next->next; char a[20], b[20]; system ( "cls" ); printf ( "请输入账户:" ); scanf ( "%s" , a); getchar (); printf ( "请输入密码:" ); scanf ( "%s" , b); getchar (); while (h != NULL) { if (( strcmp (h->account, a) == 0) && ( strcmp (h->possword, b) == 0) && h->might2 == 2) { i = 1; menu3(p); break ; } h = h->next; } if (i == 0) { Sleep(1500); printf ( "密码或账号错误!\n" ); menu1(p); } } |
18)页面3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
void menu3( struct hotel *p) { int i; system ( "cls" ); while (1) { printf ( "\t--------------------------\n" ); Sleep(50); printf ( "\t **欢迎登陆酒店管理系统** \n" ); Sleep(50); printf ( "\t| 1.登记入住 |\n" ); Sleep(50); printf ( "\t| 2.结账 |\n" ); Sleep(50); printf ( "\t| 3.修改客户信息 |\n" ); Sleep(50); printf ( "\t| 4.查询客房信息 |\n" ); Sleep(50); printf ( "\t| 5.某日客房信息统计 |\n" ); Sleep(50); printf ( "\t| 6.客房统计 |\n" ); Sleep(50); printf ( "\t| 7.客房信息打印 |\n" ); Sleep(50); printf ( "\t| 8.返回上一层 |\n" ); Sleep(50); printf ( "\t| 9.退出(保存) |\n" ); Sleep(50); printf ( "\t--------------------------\n" ); printf ( "\t请选择您要进行的操作:\n" ); scanf ( "%d" , &i); switch (i) { case 1:ADD(p); break ; case 2:Seller(p); break ; case 3:amend2(p); break ; case 4:Inquire(p); break ; case 5:statistics1(p); break ; case 6:statistics3(p); break ; case 7:statistics(p); break ; case 8:menu1(p); break ; case 9:saveHotelFile(p); exit (0); default : printf ( "\t输入不合法量\n" ); Sleep(1500); system ( "cls" ); } } } |
19)判断是否为管理员
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
void menu22( struct hotel *p) { struct hotel *h = p->next; char a[20], b[20]; int i = 0; system ( "cls" ); printf ( "请输入账户:" ); scanf ( "%s" , a); getchar (); printf ( "请输入密码:" ); scanf ( "%s" , b); getchar (); while (h != NULL) { if (( strcmp (h->account, a) == 0) && ( strcmp (h->possword, b) == 0) && h->might1 == 1) { i = 1; menu2(p); break ; } h = h->next; } if (i == 0) { Sleep(1500); printf ( "密码或账号错误!\n" ); menu1(p); } } |
20)页面2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
void menu2( struct hotel *p) { int c; system ( "cls" ); while (1) { printf ( "\t---------------------------\n" ); Sleep(50); printf ( "\t **请选择您要进行的操作** \n" ); Sleep(50); printf ( "\t| 1.添加服务员 |\n" ); Sleep(50); printf ( "\t| 2.修改账户或密码 |\n" ); Sleep(50); printf ( "\t| 3.删除服务员 |\n" ); Sleep(50); printf ( "\t| 4.统计服务员信息 |\n" ); Sleep(50); printf ( "\t| 5.返回上一层 |\n" ); Sleep(50); printf ( "\t| 6.设置房间数量 |\n" ); Sleep(50); printf ( "\t| 7.退出(保存) |\n" ); printf ( "\t---------------------------\n" ); printf ( "\t请选择您要进行的操作:\n" ); scanf ( "%d" , &c); switch (c) { case 1:ADD1(p); break ; case 2:amend(p); break ; case 3:Remove(p); break ; case 4:statistics2(p); break ; case 5:menu1(p); break ; case 6:set(p); break ; case 7:saveHotelFile(p); exit (0); default : printf ( "请输入合法量!\n" ); Sleep(1500); system ( "cls" ); } } } |
21)页面1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
void menu1( struct hotel *p) { int a; system ( "cls" ); while (1) { printf ( "\t_________________________\n" ); Sleep(50); printf ( "\t| 欢迎进入酒店管理系统 |\n" ); Sleep(50); printf ( "\t| **请选择您的身份** |\n" ); Sleep(50); printf ( "\t| 1.管理员 |\n" ); Sleep(50); printf ( "\t| 2.服务员 |\n" ); Sleep(50); printf ( "\t| 3.退出 |\n" ); Sleep(50); printf ( "\t_________________________\n\n" ); printf ( "\t请选择您要进行的操作:\n" ); scanf ( "%d" , &a); switch (a) { case 1:menu22(p); break ; case 2:menu33(p); break ; case 3:saveHotelFile(p); exit (0); default : printf ( "请输入合法量!\n" ); Sleep(1000); menu1(p); } } } |
22)主函数
1
2
3
4
5
6
7
8
9
10
11
|
int main() { LinkList *p; p = ( struct hotel *) malloc ( sizeof ( struct hotel)); p->next = NULL; readHotelput(p); menu1(p); /*saveHotelFile(p);*/ system ( "pause" ); return 0; } |
稍微改了一下,管理员初始账号和密码可以自定义,有了管理员的密码和账号之后才可以添加服务员哦。
这个代码使用传首地址的方法,也可以通过设置静态指针存首尾地址,这样会更简单。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/weixin_46020325/article/details/106745983