学生宿舍管理系统

目        录

前言 C语言程序综合设计任务书----------------------------------------------------2

§1.0任务书--------------------------------------------------------------------------------------------------3

§2.7学生成绩管理系-------------------------------------------------------------------------4

§2.1总体设计-------------------------------------------------------------------------------------------------4 §2.2模块划分-------------------------------------------------------------------------------------------------4

§2.3算法说明--------------------------------------------------------------------------------------------------4

§2.4各函数模块功能及流程图----------------------------------------------------------------------------4

§2.5程序测试-------------------------------------------------------------------------------------------------7

§2.6结论--------------------------------------------------------------------------------------------------------7

§2.7原程序清单----------------------------------------------------------------------------------------------7

§3.0体会及建议-----------------------------------------------------------------------------------------15

§4.0参考文献--------------------------------------------------------------------------------------------15

C语言程序综合设计任务书

(设计性实验)

. 实验目的

1、  进一步掌握计算机程序设计基础基本概念,理解其原理与方法。

2、  进一步理解和巩固所学的理论知识,掌握高级语言程序设计的编程技巧。

3、  培养分析解决实际问题的能力,培养进行高级语言程序设计的实际编程能力。

. 实验任务

1.用C语言设计一个综合应用程序。主要设计内容有数据库管理程序设计、图形设计、科学计算程序设计、简单游戏程序设计等。

  2.学生可以结合自己的专业及兴趣爱好自由命题,也可以从已给几类题目中任选一题,下面题目只是基本要求,鼓励同学自主创新、自由发挥。

. 实验要求

   1. 要求学生自主完成以下工作:

1)  查阅资料,选定题目。

2)制定方案,进行程序总体设计和详细设计。

3)程序详细设计,调试,运行。

4)撰写设计报告。

 2. 实验报告内容包括:封面、实验目的、实验内容、设计方案制定、总体设计、详细设计、源程序清单(要求有详细注释)、总结与体会。

一、任务书

§2.7学生宿舍管理系统设计

功能:实现简单的学生宿舍基本信息管理,宿舍的基本信息包括楼号、房间号、面积、所容纳人数、已入住人数等

基本要求:

1. 设计简单的菜单,能够进行系统功能选择。

2. 实现信息的录入功能。

3. 在已有信息的基础上添加新的记录。

4. 删除指定房间号的记录。

5. 修改指定房间号的记录

6. 实现信息的浏览功能

7. 按房间号查询功能

8. 按已入住人数排序功能

相关知识: 结构体、数组、常用算法(排序、查找、删除)

扩充功能:1)在数据维护(录入、删除、修改、添加)功能时,要求输入用户名和密码,以防信息被非法修改。

    提示:在主菜单界面中,将录入、删除、修改、添加功能合并为数据库维护功能,当选择此选项时,要求用户输入用户名和密码,如设数据库维护人员为2人,则在程序中可相应设置2个用户名和密码,只有正确时,才进入下一级维护菜单。(密码设置参阅字符串操作部分)    

          2)增加查询方式,如可以根据房间号查询,根据书名查询,及多种排序方式

    提示:在查询或排序中加入分支程序,不同的分支采用不同的查询方式,每种查询方式是一个独立的模块(函数)

3)将数据信息以文件的形式存盘,数据库信息的各种操作最后都能被存储,存储前有提示,并且能打开。

    提示:在主菜单中增加文件打开、存储选项,C语言的文件操作都是通过库函数实现的,参考关于文件的库函数使用即可。

       4)采用动态链表的方式进行设计。

提示:要求了解链表的建立、插入、删除原理,掌握C语言的动态内存分配函数的应用。链表编程可参考苏小红编《C语言大学实用教程》P314~325第8.5节动态数据结构和P362~374的例子。

二、学生宿舍管理系统设计

1、总体设计

  实现简单的学生宿舍基本信息管理   

 用动态链表、结构体等相关知识完成如下内容:

1)、简单菜单界面,按1-6键选择选项

2)、实现各个函数的功能

2、模块划分

主模块:main()/*主函数*/

其它模块:Student *load()/*从文件中读数据建立链表*/

save()/*将修改后的链表中的信息存进文件中*/

Add_student()/*添加学生信息*/

del_stu()/*按学号删除学生信息*/

find_student()/*按学号查找学生信息*/

ame_student()/*修改学生信息*/

print_student()/*输出学生信息*/

3、算法说明

   Step 1 输出主菜单

   Step 2 按1-6键选择

   Step 3 实现各个函数的功能

4、各函数功能及流程图

main()/*主函数*/

Student *load()/*从文件中读数据建立链表*/

save()/*将修改后的链表中的信息存进文件中*/

Add_student()/*添加学生信息*/

del_stu()/*按学号删除学生信息*/

find_student()/*按学号查找学生信息*/

ame_student()/*修改学生信息*/

print_student()/*输出学生信息*/

流程图如下:

5、程序测试

   (1)静态检查;

   (2)静态检查无误后,上机调试;

   (3)改正语法错误;运行。

   检查错误方法:

(1)       将程序与流程图仔细对照,如果流程图正确,程序写错了,错误很容易发现;

(2)       采取“分断检查”的方法,不断缩小检查区,就可能发现错误所在。

6、结论:

   此程序可以在TC中正常、正确运行。实现学生宿舍成绩管理。

7、原程序清单

程序原代码

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <malloc.h>

typedef struct student_info

{

 char flour_num;

 int room_num;

 int area;

 int contain_people;

 int reside_people;

 struct student_info *next;

}Student;

Student *head;

Student *load()

{

 FILE *fp;

 Student *head_1,*p,*q;

 head_1=NULL;

 fp=fopen("student","rb");

 if(fp==NULL)

       {fp=fopen("student","wb");fclose(fp);return head_1;}

 p=(Student*)malloc(sizeof(Student));

 if(fread(p,sizeof(Student),1,fp)!=1)return head_1;

 head_1=p;

 while(!feof(fp))

       {

              q=p;

              p=(Student*)malloc(sizeof(Student));

              fread(p,sizeof(Student),1,fp);

              q->next=p;

       }

 q->next=NULL;

 free(p);

 fclose(fp);

 return head_1;

}

int save()

{

 FILE *fp;

 fp=fopen("student","wb");

 while(head!=NULL)

 {

        fwrite(head,sizeof(Student),1,fp);

       head=head->next;

 }

 fclose(fp);

 return 0;

}

int Add_student()

{

Student *p,*q;

Student *stud1;

char flag='y';

stud1=(Student*)malloc(sizeof(Student));

while(flag=='y'||flag=='Y')

       {

       q=p=head;

       printf("Please enter Canada to fill the student information:\n");

       printf("flour_num room_num area contain_people reside_people\n");

       scanf("%d  %d  %d  %d  %d",&stud1->flour_num,&stud1->room_num,&stud1->area,&stud1->contain_people,&stud1->reside_people);

       stud1->next=NULL;

       fflush(stdin);

       if(head==NULL)head=stud1;

       else

              {

              while(p->room_num<stud1->room_num&&p->next!=NULL)

                     {

                            q=p;p=p->next;

                     }

              if(p->room_num>stud1->room_num)

              if(p==head){stud1->next=head;head=stud1;}

              else

              {

                     q->next=stud1;stud1->next=p;

              }

              else p->next=stud1;

              }

              stud1=(Student*)malloc(sizeof(Student));

              printf(" add end,whether or not to continue to add,'y' or 'Y' to continue ,otherwise exit :\n");

              flag=getchar();

              fflush(stdin);

              }

 free(stud1);

 system("cls");

 return 0;

}

int del_stu()

{

 Student *p,*q;

 int room_num;

 char flag='y';

 int tage=0;

 while(flag=='y'||flag=='Y')

 {

 p=head;

 q=NULL;

 printf("\ninput the delete room number!\n");

 scanf("%d",&room_num);

 if(head==NULL)

       {

              printf("There is no student information\n");return 0;

       }

 while(p!=NULL)

 {

        if(p->room_num==room_num)

        {

               tage=1;

               if(p==head)head=head->next;

               else q->next=p->next;

               free(p);break;

        }

     q=p;p=p->next;

 }

 if(tage==0) printf("To delete the student information does not exist\n");

 tage=0;

 printf("To delete the end, whether or not to continue the operation to remove: y or Y to continue, not to end\n");

 fflush(stdin);

 scanf("%c",&flag);

 }

 system("cls");

 return 0;

}

int find_student()

{ Student *p;

 char flag='y';

 int room_num;

 int tage=0;

 while(flag=='y'||flag=='Y')

 { printf("input the finding room number!\n");

 scanf("%d",&room_num);

 p=head;

 if(head==NULL){printf("There is no student information!\n");return 0;}

 else

 while(p!=NULL)

 if(p->room_num==room_num)

 {tage=1;

 printf("You have to find the information students are as follows:\n");

 printf("%d\t%d\t%d\t%d\t%d\n",p->flour_num,p->room_num,p->area,p->contain_people,p->reside_people);

  break;

 }

 else p=p->next;

 if(tage==0)printf("No information on the students\n");

 tage=0;

 printf("Find the end, whether or not to continue the operation to find: y to continue or Y, who has quit!\n");

 fflush(stdin);

 scanf("%c",&flag);

 }

 return 0;

}

int ame_student()

{ Student *p;

 int room_num;

 int tage=0;

 int chiose;

 char flag='y';

 printf("input the change room number!\n");

 scanf("%d",&room_num);

 p=head;

 while(flag=='y'||flag=='Y')

 {if(head==NULL){printf("Students there is no information!\n");return 0;}

 while(p!=NULL)

 {if(p->room_num==room_num)

 {tage=1;

 printf("Requested to amend the electoral code!\n");

 printf("1:<correct the flour number>\n");

 printf("2:<correct the room number>\n");

 printf("3:<correct the area\n");

 printf("4:<correct the contain people>\n");

 printf("5:<correct the reside people>\n");

 printf("please enter 1----5!else illegal!\n");

 scanf("%d",&chiose);

 switch(chiose)

 { case 1:{char flour_num;

 printf("Please enter the flour number changes!\n");

 scanf("%d",&flour_num);

 p->flour_num=flour_num;

 break;

 }

 case 2:{int room_num;

 printf("Please enter the room number changes!\n");

 scanf("%d",&room_num);

 p->room_num=room_num;

 break;

 }

 case 3:{int area;

 printf("Please enter the area!\n");

 scanf("%d",&area);

 p->area=area;

 break;

 }

 case 4:{ int contain_people;

 printf("Please enter the contain_people!\n");

 scanf("%d",&contain_people);

 p->contain_people=contain_people;

 break;

 }

 case 5:{ int reside_people;

 printf("Please enter the reside_people!\n");

 scanf("%d",&reside_people);

 p->reside_people=reside_people;

 break;

 }

 default: {printf("There is no such operation!\n");break;}

 }break;

 }

 else p=p->next;

 }

 if(tage==0)printf("No information on the students!\n");

 tage=0;

 printf("The end of the revision, whether to modify the operation of student information: y to continue or Y, who has quit!\n");

 fflush(stdin);

 scanf("%c",&flag);

 }

 fflush(stdin);

 system("cls");

 return 0;

}

int print_student()

{ Student *p;

 p=head;

 if(head==NULL){printf("No information on the students!\n");return 0;}

 printf("flour number\tRoom number\tarea\tcontain people\treside peple\n");

 printf("============================================\n");

 while(p!=NULL)

 {printf("%d\t%d\t%d\t%d\t%d\n",p->flour_num,p->room_num,p->area,p->contain_people,p->reside_people);

 p=p->next;

 }

 printf("============================================\n");

 printf("The end of the output!\n");

 return 0;

}

int main()

{ int tage;

 head=load();

 while(1)

 {

 printf(">>>>>>>>>>>>>>>>>Welcome to the Student Management System!<<<<<<<<<<<<<<<<<<<<>\n");

 printf(" 1:<<< Add student information <<<<>\n");

 printf(" 2:<<< Delete student information <<<<>\n");

 printf(" 3:<<< Students looking for information <<<<>\n");

 printf(" 4:<<< Amend the Student Information<<<<>\n");

 printf(" 5:<<< Output of information students <<<<>\n");

 printf(" 6:<<< Withdraw from the program<<<<>\n");

 printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");

 printf("please enter 1--6,else illegal!\n");

 scanf("%d",&tage);

 switch(tage)

 {

 case 1:Add_student();break;

 case 2:del_stu();break;

 case 3:find_student();break;

 case 4:ame_student();break;

 case 5:print_student();break;

 case 6:save();exit(0);break;

 default:printf("There is no such operation\n");break;

 }

 }

 }

三、体会及建议

   程序设计是一个长期而又艰苦的过程.它需要经过设计者对课题的理解与接受,找出对应的合理的算法,构建基本框架,上机调试,不断地修改和改进等一系列复杂的过程.尤其是当设计者对做法和相关函数一无所知时,编一个程序的难度可想而知.不过,通过不断的探索和实践,慢慢地克服一个个难题,最终一个虽然简单却又令人感到无比振奋的程序还是诞生了.

   人生总要遇到一些难题,但无论难题有多难,只要我们付出等同于甚至远远超过它的努力,我们就一定能战胜它!

四、参考文献

[1]苏小红等著。C语言大学使用教程。北京:电子工业出版社,2004

[2]苏小红等著。C语言大学使用教程习题与实验指导。北京:电子工业出版社,2004

[3]谭浩强著。C程序设计(第三版)。北京:清华大学出版社,2005

相关推荐