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

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

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

C 语言程序设计报告

课题:学生成绩管理

时间:2010/7/15

一、需求分析

任务要求:

自学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并赋值给结构体*\

}

p=q;

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->av e,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->av e,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:"); \*报错功能*\

}

相关主题
相关文档
最新文档