一、课程设计目的
加深对C语言课程所学知识的理解,进一步巩固C语言语法规则。学会编制结构清晰、风格良好、数据结构适当的C语言程序,从而具备解决综合性实际问题的能力,使学生通过系统分析、系统设计、编程调试,写实验报告等环节,初步掌握软件系统设计的方法和步骤,训练灵活运用程序设计语言进行软件开发的能力,提高分析问题和解决问题的能力,提高程序设计水平,培养必要的工程实践动手能力
二、课程设计内容
学生学籍管理系统
1,输入并验证密码;
2,设计菜单进行选择相应的操作;
3,用链表录入并输出数据,包括学生的户籍、成绩、奖惩信息;
4,将录入的数据存放在文件里面并读取文件;
5,对录入的数据进行修改;
6,删除个人信息;
7,查找个人信息;
8,对录入的成绩进行排序;
9,统计不及格的成绩;
10,释放链表;
三、需求分析
对所开发系统功能、性能的描述,想要实现的目标。
输入并验证密码的正确性,定义结构体类型来存放学生的基本信息(包括学生的姓名、学号、性别、出生日期等),然后建立链表存放信息,将信息存入文件中,以便以后的各个功能模块调试时直接调用,对数据进行修改、删除、查找、排序操作,然后对输入的数据进行统计,查出不及格的学生成绩。实现的目标是对学生的学籍进行管理,更新并统计数据。
四、概要设计
功能模块说明:
输入密码:从键盘输入密码,判断输入的密码是否与系统设定的密码相同,若相同则进入主菜单,不相同则继续输入;
主菜单:显示系统的各项功能与相对应的数字选项。 输入数据函数:从键盘输入数据,并将数据存入链表。 输出数据函数:对存储的数据进行输出。
查找数据函数:对存储的数据进行查询并显示查询结果。 删除数据函数:对存入的数据进行删除。 修改数据函数:对存入的数据进行修改。
保存数据函数:将从键盘输入的数据存入到文件中 读取数据函数:从文件中读取个人信息。
排序函数:对平均成绩进行排序并显示排序结果 统计函数:对不及格成绩进行统计并显示统计结果。 退出系统:退出系统
五、详细设计及运行结果
通过两周的课程设计,我对学过的C语言基本知识进行了巩固,并且还对知识进行了扩展。在本次实习时,刚开始完全没有头绪,不知道从何入手,感觉难度很大.但是逐渐开始编写程序慢慢发现,原来不是想象中的那么难.在一个个模块成功编写出来的同时,获得了巨大的成就感,并且掌握的许多上课遗漏和不很了解的知识.。对一些细节以前不太注意,常常忽略,真正操作起来时发现一些小问题也会导致程序无法进行。要想运行正常,必须保证零错误。
同时,这两周的实习使我对链表更熟悉了。以前总感觉链表很难,这次程序设
计中,我用链表存取数据,并进行删除修改等操作,慢慢对链表熟悉。另外,在程序运行编译的过程中出现一些错误,需要耐心的去检查错误,调试程序。
七、参考文献
《C语言程序设计》谭浩强清华大学出版社
《C语言程序设计教程》张毅坤曹锰张亚玲西安交通大学出版社
《C语言程序设计》王曙燕曹锰科学出版社
#include
#include
#include
#include
#include
#include
#include
#define LEN sizeof(struct student)
typedef struct
{ int year;
int month;
int day;
} DATE;
struct student
{ int num;
char name[10];
char sex;
DATE birthday;
int math;
int C;
int physic;
int English;
float average;
DATE time;
char reason[50];
char result[50];
char unit[50];
struct student *next;
};
struct student * read_file(); /*读取文件*/
void save_file(); /*保存*/
void input(); /*创建链表,输入数据*/
void output(struct student *head); /*输出*/
void seek(struct student *h); /*查找*/
void del() ; /*删除*/
void change (); /*修改*/
void sort() ; /*对成绩进行排序*/
void summarise(); /*对不及格成绩进行统计*/
void free_linklist(void); /*释放链表*/
void print(struct student *p); /*输出函数*/
void menu(); /*菜单*/
void password(); /*密码*/
struct student *head=NULL;
int number=0;
main()
{ password();
getch();
system("cls");
printf("\n\n\n\n\n\t\t\t*******欢迎进入学生学籍管理系统*******\n\n\n");
getch();
menu();
}
void password()
{
char s[8],ch;
int i;
s[0]='0';s[1]='4'; s[2]='0'; s[3]='8' ;
s[4]='2'; s[5]='0'; s[6]='4'; s[7]='1' ;
printf("\n\n\n\n\n\t\t\t**************************\n\n");
printf("\t\t\t**************************\n\n");
printf("\t\t\t**************************\n\n\n\n\n");
do{
printf("\t\t\t\tplease input password: \n\t\t\t\t\t");
for(i=0;i<8;i++)
{ ch=getch();
if(ch!=s[i])
break;
printf("*");
}
printf("\n\n");
if(i!=8)
{
printf("It's error!!\n");
printf("please input again!\n");
}
else break;
}while(1);
}
void menu()
{
int select=-1;
head=NULL;
while (select!=0)
{ system("cls");
printf("\t\t\t*************************************\n");
printf("\t\t\t *1 Input \n");
printf("\t\t\t *2 Output \n");
printf("\t\t\t *3 seek \n");
printf("\t\t\t *4 delete \n");
printf("\t\t\t *5 change \n");
printf("\t\t\t *6 save \n");
printf("\t\t\t *7 read \n");
printf("\t\t\t *8 sort \n");
printf("\t\t\t *9 summarise \n");
printf("\t\t\t *0 Exit \n");
printf("\t\t\t************************************\n");
printf("Please input select(0-8):");
scanf("%d",&select);
switch(select)
{
case 1:
input();
break;
case 2:
output( head);
break;
case 3:
seek(head);
break;
case 4:
del();
break;
case 5:
change();
break;
case 6:
save_file();
break;
case 7:
head=read_file();
break;
case 8:
sort();
break;
case 9:
summarise();
break;
case 0:
free_linklist();
break;
}
}
}
void input() /*创建链表,输入数据*/
{
struct student *p1,*p2;
p1=(struct student *)malloc (LEN);
printf ("please input the student's information:\n");
printf ("address information:\n");
printf ("num name sex year month day \n");
scanf("%d", &p1->num);
fflush(stdin);
scanf ("%s",p1->name);
fflush(stdin);
scanf ("%c",&p1->sex);
fflush(stdin);
scanf
("%d%d%d",&p1->birthday.year,&p1->birthday.month,&p1->birthday.day);
printf ("score information:\n");
printf ("math C physic English\n");
scanf ("%d%d%d%d",&p1->math,&p1->C,&p1->physic,&p1->English);
p1->average=((float)(p1->math+p1->C+p1->physic+p1->English))/4;
printf(" rewards and punishments:\n");
printf (" time(year month day )\n");
scanf ("%d%d%d",&p1->time.year,&p1->time.month,&p1->time.day);
printf ("reason: ");
fflush(stdin);
scanf ("%s",p1->reason);
printf ("result: ");
fflush(stdin);
scanf ("%s",p1->result);
printf ("unit: ");
fflush(stdin);
scanf ("%s",p1->unit);
p1->next=NULL;
number++;
if(head==NULL)
{
head=p1;
}
else
{
p2=head;
while (p2->next )
p2=p2->next;
p2->next=p1;
}
getch();
}
void output(struct student *head) /*输出链表*/
{
struct student *p;
int kind,flag=1;
char choice='a';
if (head==NULL)
{
printf("Not Input before!\n");
getch();
return;
}
while (flag)
{
printf ("students' information input before as fowllow:\n");
printf ("1:address; 2:score; 3:rewards and punishments 0:exit\n");
printf ("please choice: ");
scanf ("%d",&kind);
p=head;
do
{
switch(kind)
{ case 1:
printf ("address information:\n");
printf ("num name sex year month day \n");
printf ("%d %s %c ",p->num,p->name,p->sex);
printf
(" %d %d %d\n",p->birthday.year,p->birthday.month,p->birthday.day);
break;
case 2:
printf ("score information:\n");
printf ("num name math C physic English averag\n");
printf ("%d %s %d %d %d %d ",p->num ,p->name ,
p->math,p->C,p->physic,p->English);
printf ("%2.2f\n",p->average);
break;
case 3:
printf(" rewards and punishments:");
printf ("num : %d name %s \n",p->num,p->name);
printf ("time: year/%d month/%d day/%d \n",p->time.year,p->time.month,p->time.day);
printf("reason: %s\n",p->reason);
printf("result: %s\n",p->result);
printf ("unit: %s\n",p->unit);
break;
}
p=p->next;
}while(p);
printf ("continue to choice (y/n) ");
fflush(stdin);
choice=getchar();
if(choice=='n')
flag=0;
}
printf("Display finish!\n");
getch();
}
void seek(struct student *h) /*查找链表*/
{ struct student *p;
int seeknum;
printf ("please input the num what you look for :");
scanf ("%d",&seeknum);
p=h;
while (p&&seeknum!=p->num)
p=p->next;
if(!p)
printf ("the num you look for don't exist!\n");
else
{
print(p);
}
getch();
}
void del () /*删除链表*/
{
int delnum;
struct student *p1,*p2;
p1=head;
printf("input delete num:\n");
scanf("%d",&delnum);
while (delnum!=p1->num&&p1->next!=NULL)
{ p2=p1;
p1=p1->next;
}
if (delnum==p1->num)
{
if (p1==head)
head=p1->next;
else
p2->next=p1->next;
printf ("the student's information you input have been deleted!\n");
number--;
}
else
printf ("the student you what to delete don't exist!\n");
getch();
}
void change() /*修改链表*/
{
int changenum,kind;
int choice,flag=1;
char select=1;
struct student *p;
p=head;
while (flag!=0)
{ printf ("please input the num you want to change:\n");
scanf ("%d",&changenum);
while (changenum!=p->num)
p=p->next;
if (changenum==p->num)
{
printf ("input the new information:\n");
printf ("1:address ; 2:score ;3: rewards and punishments; 0:exit;\n");
printf("input the kind you want to change:");
fflush(stdin);
scanf("%d",&kind);
switch(kind)
{ case 1:
printf ("1: name; 2:sex; 3:birthday;");
printf ("please choice :");
fflush(stdin);
scanf ("%d",&choice);
switch (choice)
{ case 1:
printf ("input the new name:");
fflush(stdin);
scanf ("%s",p->name);
break;
case 2:
printf ("input the new sex:");
fflush(stdin);
scanf("%c",&p->sex);
break;
case 3:
printf ("input the new birthday:");
fflush(stdin);
scanf("%d%d%d",&p->birthday.year,&p->birthday.month,&p->birthday.day);
break;
}
break;
case 2:
printf ("1:math; 2:C; 3: physics; 4:English;");
printf ("please choice :");
fflush(stdin);
scanf ("%d",&choice );
switch (choice)
{ case 1:
printf ("input the new math:");
fflush(stdin);
scanf ("%d",&p->math);
break;