c语言学生管理系统(C language student management system)_第1页
c语言学生管理系统(C language student management system)_第2页
c语言学生管理系统(C language student management system)_第3页
c语言学生管理系统(C language student management system)_第4页
c语言学生管理系统(C language student management system)_第5页
已阅读5页,还剩47页未读 继续免费阅读

下载本文档

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

文档简介

1、c语言学生管理系统(C language student management system)# includes stdio.h # define len sizeof (struct guest)/ * 结构体定义 * /struct guestchar name 20; / * 客户姓名 * /char num 19; / * 身份证号 * /char as 20; / * 开始入住时间 * /char go 20; / * 退房时间 * /int number; / * 入住房间号码 * /int tianshu 入住天数; / * * /float price; / * 入住价格 *

2、 /float 住宿费用 pay; / * * /struct guest * next; guests 10.struct roomint number;float price; rooms 10 = 101100, 102100, 103100, 104100, 105100,106100, 107100, 108100, 109100, 110100;struct dates 定义日期保存年、月、日 / * * /int year 2.int month 2.int day 2.int days 2. in 10.struct guest * head = null; / * 定义头指针

3、 * /struct dates * q;int n = 0; / * 入住人数 * /int m 20.int z = 1;int writeinflag = 0;void load (); / * 从磁盘中导入客户信息 * /void create (); / * 新建记录 * /int judgenumber (char b ); / * 判断房间号 * /void judgenum (char str ); / * 判断身份证号是否合法 * /int judgedate (int m, int y, char s ); / * 判断时间是否合法 * /void num (int y);

4、 / * 判断是否有人入住 * /void search (); / * 查询 * /void insert (); / * 插入记录 * /void delete (); / * 删除记录 * /void baocun (); / * 保存 * /void money (); / * 统计房间产生的住宿费用 * /int menuselect (); / * 主菜单 * /void tuichu ();void main ()while (1)switch (menuselect ()case 0: system (cls); load (); break;Case 1: System (C

5、LS); create(); break;Case 2: System (CLS num); (Z); break;Case 3: System (CLS); (Search); break;Case 4: System (CLS); Insert (); break;Case 5: System (CLS); delete(); break;Case 6: System (CLS); Money (); break;Case 7: System (CLS); baocun (); break;Case 8: System (CLS); tuichu (); exit (0);Break; d

6、efault:/ * * * * * * * * * * * 主函数 * * * * * * * * * * * /Menuselect (INT)int m;Char s 20;Printf ( n n n n n n);Printf ( t t t欢迎来到酒店管理系统 n);Printf ( t t * * * * * * 主菜单 * * * * * n);Printf ( t t 0、从磁盘中导入客户信息 n);Printf ( t t 1、新建客户信息 n);Printf ( t t 2、房间入住情况 n);Printf ( t t 3、查询客户信息 n);Printf ( t t 4

7、、新增客户 n);Printf ( t t 5、客户退房 n);Printf ( t t 6、统计房间产生的住宿费用 n);Printf ( t t 7、保存 (年、月、日及客户信息) n);Printf ( t t 8、退出 n);Printf ( t t * * * * * * * * * * * * n);Printf ( t t 请选择 (0至8之间的整数):);Gets (S);While (1)If (strlen (S)! = 1 | | s 0 8)printf ( t t 输入错误, 请重新选择 (0至8之间的整数):); gets (S);Else break;M = (I

8、NT) s 0;Return (m-48);/ * * * * * * * * 从磁盘中导入客户信息 * * * * * * * * * /Void Load ()Int i = 0;Char s 20;File * * FP1, FP2.Struct Guest * * P1, P2;If (Head! = null)printf (对不起, 客户记录已存在链表中, 请进行其他操作!) Getchar (;); System (CLS); return;ElsePrintf ( n n n t t t请输入导入链表信息地址:);Gets (S);If (1 = fopen (S, r) =

9、= null)Printf ( n n n t t t文件不存在或无法打开!) ;Printf ( n n n t t t按enter返回.);Getchar ();System (CLS);Return;While (! Feof() FP1)(struct Guest * p1 = malloc (LEN);P1 - NEXT = null;Fscanf (FP1, % d% s% s% s% s% d% F% f n, & P1 - - Name Number, P1, P1 - Num, P1 - - GO EAT, P1, P1 - tianshu &, & P1 - Price,

10、& P1 - pay);M n = P1 - Number;/如果(P1 -数110 | | P1 -数101)自由(P1);getchar();break;如果(头= = null)头= P1;其他-下= P1 P2;P1 P2 = n + +;如果(fclose(FP1)printf(“无法关闭文件!”);返回;printf(“n n nn T T T请输入导入日期信息地址:”);得到(S);如果(FP2 = fopen(S,R)= = null)printf(“n n n nn T T T文件不存在或无法打开!”);printf(“n n nn T T T按进入返回.”);getchar

11、();系统(“华彩”);返回;Q =日期;而(!外汇经营资金(FP2)fscanf(FP2,“%d %d %d %dn”,及问我年 0 ,我和Q。月 0 ,我和Q。天 0 ,我和Q。天 0 );fscanf(FP2,“%d %d %d %dn”,及问我年 1 ,我和Q。月 1 ,我和Q。天 1 ,我和Q。天 1 );我+ +;如果(我= = n)打破;如果(fclose(FP2)printf(“T T无法关闭文件!”);返回;printf(“n n n n nn T T T已导入信息,请返回!”);printf(“n T T T按进入返回.”);getchar();系统(“华彩”);返回;wr

12、iteinflag = 0;/ *新建记录* /无效create()一个字符 19 20 ,S,H 20 ,叫 20 ;结构客体P2,P1 *;结构室* R;中断标志,X,I,K = 0时,y = 0,M = 0,G = 1;如果(头!= null) printf(“T T对不起,客户记录已存在链表中,请进行其他操作!”);getchar();系统(“华彩”);返回;Q =日期;而(1) printf(“n n n n”);printf(“T T T各房间的信息如下!n”);printf(“房间号:”);为(R =室;R房间+ 10;r + +)printf(“% 6d”,R 号码);prin

13、tf(“n”);printf(“价格:”);为(R =室;R房间+ 10;r + +)printf(“%。1F”,R价格);printf(“n n nn T请输入第%d名客户的信息,当房间号码为100时输入结束 n,n + 1);P1 =(struct客人*)malloc(LEN);P1 -数= judgenumber(H);如果(P1 -数= = 100)自由(P1);printf(“n T T按进入返回.”);getchar();系统(“华彩”);返回;printf(“n”);printf(“不请输入姓名:”);获取(名字);而(G)而(1)旗= 0;X = strlen(名称);为(i

14、= 0;i = 0)旗+ +;如果(旗!= 0) printf(“不输入的不为汉字,请重新输入:”);获取(名称);break;G = 0;突破;strcpy(P1 -名称,名称);judgenum(STR);Strcpy (P1 - Num, str);Printf ( n);Flag = 1;While (FLAG)While (1)Judgedate (M and S); M + +; strcpy (P1 - come, S);Printf ( n);Judgedate (M and S); M + +; strcpy (P1 - GO, S);If (Q - Year 1. Q -

15、Year = 0)printf ( t输入错误, 退房时间应入住时间年份应相同! n ); Q -; break;P1 - - Days tianshu = Q - Q - 1 Days 0;If (P1 - tianshu = 0)printf ( n t输入错误, 退房时间应大于入住时间!) ; Q -; break;Flag = 0; break;Q + +;For (R = r Number = = P1 - Number) break;P1 - R - Price = price;Pay (P1 = P1 - - tianshu) * (P1 - Price);P1 - NEXT =

16、 null;If (HEAD = = null) head = P1;Else P2 = P1 - Next;P2 = P1;Writeinflag = 1;N + +;System (CLS getchar (););Q -;Return;/ * * * * * * * * * * * 判断房间号 * * * * * * * * * * * /Judgenumber (char , int H)Int a, B, C, D, J, flag = 0, F = 1;Getchar ();Printf ( t请输入入住房间号码 (101 - 110):);Gets (H);While (f)Wh

17、ile (1)If (strlen (H). = 3)printf ( n t输入错误, 房间号位三位数字, 请重新输入 (101 - 110); (H) gets); break;B = (INT) - 48 h 0;C = (INT) - 48 h 1;D = (INT) - 48 h 2;If (B C 0 9 | | | | d 9)printf ( n t输入错误, 房间号只能为数字, 请重新输入 (101 - 110); (H) gets); break;A = 100 * 10 * (B + C + D;If (a! = 100 & a! = 101 &! = 102 &! &

18、= 103. = 104 &! = 105 &! & = 106. = 107 &! & = 108! & = 109. = 110)printf ( n t输入错误, 该房间不存在, 请重新输入 (101 - 110); (H) gets); break;Flag = 0;For (J = 0; J n; J + +)If (A = j = M + +) Flag; break;If (Flag! = 0)printf ( n t输入错误, 该房间已入住, 请重新输入 (101 - 110); (H) gets); break;If (a! M = 100) n = a;F = 0; bre

19、ak;Return to;/ * * * * * * * * * * * 判断身份证号 * * * * * * * * * * * /Void judgenum (char str )Int a 18, I, Count, H = 1;Getchar ();Printf ( t请输入身份证号:);Gets (STR);While (H)While (1)If (strlen (STR). 15 & & = strlen (STR). = 18)printf ( t输入错误, 身份证号位为15或18, 请重新输入:); gets (STR); break;if (strlen (str) = =

20、 15)(i = 0; i 15; i + +)a i = (int) str in - 48;count = 0;for (i = 0; i 15; i + +)if (a i 9) count + +;if (count! = 0)printf ( t输入错误, 身份证号位位纯数字, 请重新输入:); gets (str); break;if (strlen (str) = = 18)(i = 0; i 18; i + +)a i = (int) str in - 48;count = 0;for (i = 0; i 18; i + +)if (a i 9) count + +;if (c

21、ount! = 0)printf ( t输入错误, 身份证号位位纯数字, 请重新输入:); gets (str); break;h = 0; break;/ * * * * * * * * * * * * * * * * * * * 判断时间 * * * * * * * * * * * * * * * * * * * * * * * * * * * /int judgedate (int m, int y, char s )hour _ t tval;int a 8 in, count, flag day = 0, h = 1;int b = 0, c = 0, d = 0;struct tm

22、 * now;char y 5, m 3, d 3;int loss 2 13 = 0,31,28,31,30,31,30,31,31,30,31,30,31,0,31,29,31,30,31,30,31,31,30,31,30,31 ;s 0 = 0;if (y% 2! = 0)if (m% 2 = = 0)printf ( t请输入开始统计时间, 形式为 (yyyy mm dd):);elseprintf ( t请输入结束统计时间, 形式为 (yyyy mm dd):);gets (s);if (y% 2 = = 0)if (m% 2 = = 0)tval = hour (null);no

23、w = localtime (& tval);b = the now tm _ year + 1900;c = now - tm _ mon + 1;d = the now tm _ mday;if (c = = 10 | | c = = 11 | | c = = 12)sprintf (y, % d, (b);sprintf (m, % d, (c);sprintf (d, % d, d);strcat (s, y);strcat (s, );strcat (s, m);strcat (s, );if (d = 1 & & d = 1 & & d = 9)strcat (s, 0);strc

24、at (s, d);getchar ();printf ( t取系统时间为:); putts (s);elseprintf ( t请输入客户退房时间, 形式为 (yyyy mm dd):); gets (s);while (h)while (1)if (strlen (s)! = 10)printf ( t输入错误, 形式为10位, 请重新输入:); gets (s); break;if (s 4. = - | | s 7. = -)printf (t input error, fifth bit and seventh bit is -, please input again:); gets

25、 (s); break;For (i=0; i=3; i+)Ai= (int) si-48;For (i=4; i=5; i+)Ai= (int) si+1-48;For (i=6; i=7; i+)Ai= (int) si+2-48;Count=0;For (i=0; i=7; i+)If (ai9) count+;If (count =0!)printf (t input error, digital input is not correct, please input again:); gets (s); break;B=a0*1000+a1*100+a2*10+a3;C=a4*10+a

26、5;D=a6*10+a7;If (c12)printf (t input error is not greater than 12 months, please input again:); gets (s); break;If (c=1|c=3|c=5|c=7|c=8|c=10|c=12) &d31)printf (t input error,%d month can not exceed 31 days, please input again:, c); gets (s); break;If (c=2|c=4|c=6|c=9|c=11) &d30)printf (t input error

27、,%d month can not exceed 30 days, please input again:, c); gets (s); break;Flag=0;If (b%4=0&b%100 =0|b%400=0!)Flag=1;If (flag=0&c=2&d27)printf (t input error,%d is a February, not more than 28 days, please input again:, b); gets (s); break;For (i=0; iyear0=b; q-month0=c; q-day0=d; q-days0=day;If (m%

28、2 =0!)q-year1=b; q-month1=c; q-day1=d; q-days1=day;Else;H=0; break;Return day;/* determine whether people stay, check the ID card */Void Num (int z)Struct guest *p;Int j, K, flag;P=head;If (head=NULL)printf (nnnn no room:);For (k=101; knumber);P=p-next;Printf (n room no admission number:);For (k=101

29、; k111; k+)flag=0;For (j=0; jnumber);P=p-next;Printf (n room no admission number:);For (k=101; k111; k+)flag=0;For (j=0; jnumber100&p-numbernumber);P=p-next;Printf (nttt a total of%d customers in n, n);Printf (ttt output of the%d rooms for customer specific information as follows: nnnn, n);Printf (r

30、eal name, ID number, check-in time check-out time days price cost n);P=head;While (P =NULL!)Printf (%d%s%s%s%s%d%.1f%.1fn p-number, p-name, p-num, p-come, p-go, p-tianshu, p-price, p-pay);P=p-next;Printf (nttt press Enter to return.);(getchar); system (CLS); return;/* delete records */Void (Delete)i

31、nt number, I, h=1;Struct guest *p1, *p2;P1=p2=head;If (head=NULL)Printf (t no record, select the 1 key new record nnn!);Elsez=0;Num (Z);Printf (please enter nnnttt to delete the room number:);Scanf (%d, &number);While (P1 =NULL&p1-number =number!)P2=p1; p1=p1-next; h+;If (p1=NULL)Printf (t Im sorry,

32、 the room did not check the customer!);ElsePrintf (nnnnttt has been deleted in room%d for customer information! n, number);If (p1=p2)Head=p1-next;ElseP2-next=p1-next;If (H =n!)For (i=h; i N);(我在下;i+;printf(“T T T各房间的信息如下!n”);printf(“房间号:”);为(R =室;R房间+ 10;r + +)printf(“% 6d”,R 号码);printf(“n”);printf(

33、“价格:”);为(R =室;R房间+ 10;r + +)printf(“%。1F”,R价格);Z = 0;Num(Z);printf(“n n nn T T T请输入第%d名客户的信息 n,n + 1);P2 =(struct客人*)malloc(LEN);printf(“n”);P2 -数= judgenumber(H);printf(“n”);printf(“不请输入姓名:”);获取(名字);而(G)而(1)旗= 0;X = strlen(名称);为(i = 0;i = 0)旗+ +;如果(旗!= 0) printf(“不输入的不为汉字,请重新输入:”);获取(名称);break;G =

34、0;突破;strcpy(P2 -名称,名称);judgenum(STR);strcpy(P2 - num,STR);printf(“n”);标志= 1;而(标志)而(1)judgedate(M,Y,S);M + +;strcpy(P2 - 来,S);printf(“n”);judgedate(M,Y,S);M + +;strcpy(P2 -去,S);如果(Q年 1 != Q -年 0 ) printf(“不输入错误,退房时间应入住时间年份应相同!n”);Q;break;P2 -天枢= Q -天 1 - Q - 天 0 ;如果(P2 -天枢数= = P2 -数)打破;P2 -价格= r 价格;P

35、2 -工资=(P2 -天枢)*(P1 -价格);P2 -下= P1 -下;P1 -下= P2;n + +;Writeinflag=1;Printf (ntt press Enter to return.);(getchar); system (CLS); return;/* room accommodation expenses */ statisticsVoid (Money)Struct guest *p;Char s10;Int i, a, B, y=1;Int m=0;Float sum=0;P=head;If (n=0)Printf (t no record!);Elseprintf

36、 (nnnn);A=Judgedate (m, y, s); m+;Printf (n);B=Judgedate (m, y, s); m+;For (q=date; qdate+n; q+)If (adays0&b=q-days1)Sum+= (q-days1-q-days0) * (p-price);If (aq-days0&bq-days1&adays1)Sum+= (q-days1-a) * (p-price);If (adays0&q-days0b&bdays1)Sum+= (b-q-days0) * (p-price);If (aq-days0&bdays1)Sum+= (B-A)

37、 * (p-price);P-next;Q+;Printf (nnnttt statistical time income is%.1f, sum);Printf (nnnttt press Enter to return.);(getchar); system (CLS); return;/* save */Void (Baocun)Int m;Char s20;Struct guest *p;FILE *fp1, *fp2;If (head=NULL)printf (nnnnnttt information is empty!);Printf (nnnttt press Enter to return.);(getchar);System (CLS);Return;ElsePrintf (nnnttt please enter a list of information stored address:);Gets (s);While (1)M=0;If (fp1=fopen (s, w) =NULL)Printf (the file

温馨提示

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

评论

0/150

提交评论