当前位置:文档之家› c语言课程设计报告书--学生成绩管理

c语言课程设计报告书--学生成绩管理

c语言课程设计报告书--学生成绩管理
c语言课程设计报告书--学生成绩管理

C 语言程序设计报告

课题:学生成绩管理

时间:

一、需求分析

任务要求:

自学C语言中有关链表及外部文件的内容,设计出学生成绩管理。具体要求如下:

1.主要功能:

(1)能按学期、按班级完成对学生成绩的录入、修改

(2)能按班级统计学生的成绩,求学生的总分及平均分,并能根据学生的平均成绩进行排序

(3)能查询学生成绩,不及格科目及学生名单

(4)能按班级输出学生的成绩单

系统功能需求分析:

1、定义一个结构体类型,成员包括学期、班级、各科成绩、建立链表,定义该结构体类型的指针,用于指向各结点;

2、分别建立具有添输入、修改、查询、总分及平均分、排序等功能的子函数,完成相应功能,对程序实现模块化。

二、概要设计

系统总体设计框架:

对程序进行模块化,建立输入、修改、查询、查找和显示功能的子函数,各子函数中运用链表存储数据。

系统功能模块图:

三、详细设计

主要功能模块的算法设计思路如下:

1、输入信息函数

(1)定义指向结构体变量的指针; (2)移动指针,找到插入结点; (3)在要插入的结点输入信息; (4)返回头指针。 2、修改信息

(1)定义指向结构体变量的指针;

(2)用指针检验链表中是否有记录,若没记录,出现报错,然后要求重新输入; (3)根据要修改的编号查找对应结点; (4)修改信息;

(5)修改成功。

3、排序函数

(1)定义所要排序的班级和链表的头指针为形参;

(2)调用排序函数,把班级和链表的头指针赋给形参;

(3)在子函数中进行排序;

(4)输出排序结果。

4、显示学生成绩信息(void Disp(Link l))

(1)选择想要查询的项目(学生各科成绩、不及格科目、班级成员);(2)用指针检验是否有记录;

(3)若无记录,输出提示信息,返回主函数;

若有记录,移动指针,依次输出记录;

5、查询班级成绩信息(void Find(Link l))

(1)选择所要查询的班级;

(2)输入班级:

(3)在链表中寻找相应结点;

(4)输出结点信息。

以上各个函数的流程图如下:

子函数排序:

求和:

求平均数:

四、主要源程序代码

#include

#include

#include

#define NULL 0

#define LEN sizeof (struct student)

#define PRINT printf("======================main menu=======================\n")

#define PRIN printf("Please chose the number:\n")

#define PRI printf("Sorry,the number you chose is error,please chose again\n")

struct student \*定义一个结构体*\

{

int term; \*学期*\

int class; \*班级*\

char name[20]; \*姓名*\

int score_1; \*科目一*\

int score_2; \*科目二*\

int score_3; \*科目三*\

float ave; \*平均分*\

int sum; \*总分*\

struct student *next;

};

int n;

struct student *creat(void) \*创建信息链表*\

{

struct student *head;

struct student *p1,*p2;

n=0;

p1=p2=(struct student *)malloc(LEN);

printf("Please input the student information:\n");

printf("Term Class Name Score_1 Score_2 Score_3\n");

scanf("%d%d%s%d%d%d",&p1->term,&p1->class,p1->name,&p1->score_1,&p1->score_2,&p1-> score_3);

head=NULL;

while(p1->term!=0)

{

n=n+1;

if(n==1) head=p1;

else p2->next=p1;

p2=p1;

p1=(struct student *) malloc(LEN);

scanf("%d%d%s%d%d%d",&p1->term,&p1->class,p1->name,&p1->score_1,&p1->score_2,&p1-> score_3);

}

p2->next=NULL;

return(head);

}

void sort(struct student *p,int f) \*排序(形参为链表的头指针和想要排序的班级)*\ {

int a,b,c,e;

float d;

char z[20];

struct student *r,*s;

while(f!=p->class) \*判断是否是想要排序的班级*\

p=p->next;

for(r=p;f==p->class&&r;r=r->next)

for(s=p;s->next&&f==s->next->class;s=s->next)

if(s->ave<(s->next)->ave)

{ \*交换结构体各个成员*\

d=s->ave; s->ave=s->next->ave; s->next->ave=d;

a=s->score_1; s->score_1=s->next->score_1; s->next->score_1=a;

b=s->score_2; s->score_2=s->next->score_2; s->next->score_2=b;

c=s->score_3; s->score_3=s->next->score_3; s->next->score_3=c;

e=s->sum; s->sum=s->next->sum; s->next->sum=e;

strcpy(z,s->name); strcpy(s->name,s->next->name); strcpy(s->next->name,z);

}

}

int add(int i,struct student *p) \*求和(形参为想要求和的班级和链表的头指针)*\ {

int sum;

if(i==p->class)

sum=p->score_1+p->score_2+p->score_3;

return(sum);

}

float average(int i,struct student *p) \*求平均分(形参为想要求和的班级和链表的头指针)*\ {

float ave;

int sum;

sum=add(i,p); \*调用add函数求和*\

ave=sum/3.0;

return(ave);

}

void main() \*主函数*\

{

int i,m;

struct student *p,*q;

printf("================Now begin to set up===================\n");

p=creat(); \*调用creat函数,并创建一个信息链表*\

q=p;

do

{

PRINT;

printf(" 1:correct the student information\n"); \*修改学生信息*\

printf(" 2:calculate the students' score and then sort\n"); \*统计学生成绩并排序*\ printf(" 3:search the students' information\n"); \*查找学生信息*\ printf(" 4:output the score of student\n"); \*输出学生成绩*\ PRIN;

do

scanf("%d",&i);

if(i!=1&&i!=2&&i!=3&&i!=4) PRI; \*报错功能*\

}

while(i!=1&&i!=2&&i!=3&&i!=4);

if(i==1)

{

char x[20];

printf("Please input the name of student you want to correct:");

do

{

scanf("%s",x); \*输入你要修改学生成绩的姓名*\ for(p=q;p!=NULL;p=p->next)

{

if(strcmp(x, p->name)==0) \*查找学生*\

{

printf("Now,please input the new score of the student:\n"); \*输入新的成绩*\

printf("Score_1 Score_2 Score_3\n");

scanf("%d%d%d",&p->score_1,&p->score_2,&p->score_3);

printf("Information correct succeed\n");

printf("Now,%s's score is %-6d%-6d%-6d\n",x,p->score_1,p->score_2,p->score_3);

break;

}

}

if(p==NULL)

printf("Can't find the student,please input again:"); \* 报错功能*\

}

while(p==NULL);

p=q;

}

if(i==2)

{

int j;

printf("Please input which class you want to count:");

scanf("%d",&j); \*输入你想要统计的班级*\

printf("The score information of %d class is:\n",j);

printf("Name Score_1 Score_2 Score_3 Average Sum\n");

for(p=q;p!=NULL;p=p->next)

{

p->sum=add(j,p); \* 调用函数add并赋值给结构体*\

p->ave=average(j,p); \*调用函数average并赋值给结构体*\

}

printf("Before sorted,the student score is:\n");

for(p=q;p!=NULL;p=p->next)

if(j==p->class)

printf("%-9s%-9d%-9d%-9d%-9.2f%-9d\n",p->name,p->score_1,p->score_2,p->score_3,p->ave,p->sum); \*输出排序前的学生成绩*\ p=q;

sort(p,j); \*调用函数sort*\

printf("After sorted,the student score is:\n");

for(p=q;p!=NULL;p=p->next)

if(j==p->class)

printf("%-9s%-9d%-9d%-9d%-9.2f%-9d\n",p->name,p->score_1,p->score_2,p->score_3,p->ave,p->sum); \*输出排序后的成绩*\ p=q;

}

if(i==3)

{

int a;

char y[20];

PRINT;

printf(" 1:search the score of student\n"); \*查询学生的各科分数*\

printf(" 2:search the score of fail lesson\n"); \*查询不及格科目*\

printf(" 3:search the name of student\n"); \*查询每个班级的成员*\

printf("What's do you want to do?"); PRIN;

scanf("%d",&a); \*输入你想要执行的操作的序号*\ if(a==1)

{

printf("Please input the student name:");

do

{

scanf("%s",y); \*输入你想要查询的学生的姓名*\

for(p=q;p!=NULL;p=p->next)

{

if(strcmp(y,p->name)==0) \*查找学生*\

{

printf("%s's score is %d %d %d\n",p->name,p->score_1,p->score_2,p->score_3);

break; \*输出学生的成绩*\

}

}

if(p==NULL)

printf("Can't find the student,please input again:"); \*报错功能*\

while(p==NULL);

p=q;

}

else if(a==2)

{

for(p=q;p!=NULL;p=p->next)

{

if(p->score_1<60)

printf("%s's lesson 1 is failed and the score is %d\n",p->name,p->score_1);

if(p->score_2<60)

printf("%s's lesson 2 is failed and the score is %d\n",p->name,p->score_2);

if(p->score_3<60)

printf("%s's lesson 3 is failed and the score is %d\n",p->name,p->score_3);

}

p=q;

}

else if(a==3)

{

int c;

printf("Please input the number of class:\n");

scanf("%d",&c); \*输入你想要输出成绩的班级*\ printf("The %d class have these student:\n",c);

for(p=q;p!=NULL;p=p->next)

if(c==p->class)

printf("%-10s",p->name);

printf("\n");

p=q;

}

}

if(i==4)

{

int b;

printf("Please input which class:\n"); \*输入你想要输出成绩的班级*\ scanf("%d",&b);

printf("Now,the score of the student of %d class is:\n",b);

printf("Name Score_1 Score_2 Score_3\n");

for(p=q;p!=NULL;p=p->next)

if(b==p->class)

printf("%-12s%-12d%-12d%-12d\n",p->name,p->score_1,p->score_2,p->score_3);

} 输出成绩

PRINT;

printf("Do you want to going on?\n"); \*是否想要继续操作*\ printf(" 1:YES 2:NO \n");

scanf("%d",&m);

}

while(m!=2);

}

五、调试分析过程描述

运行情况如下:

输入学生的基本信息:

修改指定学生的成绩:

统计并排序一班成绩:

统计并排序二班的成绩:

查询指定学生的成绩:

查询学生不及格的成绩:

查询班级成员:

输出一班的成绩:

输出二班的成绩:

调试过程中的主要问题及解决方法:

1、执行排序函数时出错,指针指向不确定。

2、编译时无出错警告,连接时出现错误。

3、表格输出时,格式不能对齐。未运用格式控制字符。

六、课程设计小结

通过这次课程设计,我对C语言有了更深刻的了解,增强了程序的编写能力,巩固了专业知识,对程序的模块化观念也又模糊逐渐变的清晰了。在程序的运行与调试过程中出现了很多错误,通过反复地复习课本上的相关知识,不停地修改与调试,我终于完成了这段程序。在调试过程中,我认识到了C语言的灵活性与严谨性,同一个功能可以由不同的语句来实现,但编写程序时要特别注意细节方面的问题,因为一个小小的疏忽就能导致整个程序不能运行。当然我也认识到了自己的薄弱之处,如对链表相关知识的欠缺,文件运用的不熟练,在以后的学习中我要集中精力、端正态度,争取把知识学得更扎实、更全面。

相关主题
文本预览
相关文档 最新文档