内蒙古科技大学
本科生课程设计说明书
题 目:C语言课程设计
—— 学生成绩管理系统
学生姓名:
学 号:
专 业:计算机科学与技术
班 级:计算机四班
指导教师:
内蒙古科技大学课程设计任务书
目 录
内蒙古科技大学课程设计任务书······························································· 2
第一章 需求分析··················································································· 4
1.1 引言························································································ 4
1.2 任务概述················································································· 4
1.3 数据描述················································································· 4
1.4 功能需求················································································· 4
1.5 性能需求················································································· 4
1.6 运行需求················································································· 5
1.7 任务计划················································································· 5
第二章 概要设计················································································· 5
2.1 总体设计················································································· 5
2.2 数据类型设计(或数据结构设计)·············································· 7
2.3 接口设计 //函数声明······························································ 7
2.4 运行界面设计··········································································· 7
第三章 详细设计················································································· 9
3.1 输入模块设计··········································································· 9
3.2 输出模块设计··········································································· 9
3.3 查找及修改模块设计································································· 9
3.4 排序模块设计·········································································· 11
3.5 保存及读取模块设计································································ 12
第四章 测试分析················································································ 13
4.1 测试程序执行情况··································································· 13
4.2 出现的问题和解决的方法························································· 15
第五章 用户手册(可选)··································································· 16
5.1 使用说明················································································ 16
5.2 运行说明················································································ 16
第六章 课程设计总结········································································· 17
附录:程序代码···················································································· 17
参考文献······························································································ 17
致谢···································································································· 27
第一章 需求分析
1.1 引言
学生成绩管理系统
1.2 任务概述
1.建立学生信息,信息至少包含学生姓名,学号及五门功课的成绩;
2.能够提供录入、浏览、查找、修改、删除及保存信息的功能;
3.能够提供按不同方式查询的功能,如按姓名或学号等查询;
1.3 数据描述
struct student
{
long id;
char name[MAX_NAME];
float Chinese,math,English,chemistry,physical;
float ave;
float tot;
}stu[100]={0};
1.4 功能需求
1、 输入功能:一次可以完成自定义学生人数的学生信息记录的输入。
2、 删除功能:对指定学生的信息进行删除。
3、 修改功能:对指定学生的信息进行修改。
4、 查询功能:选择某种方式并输入该信息查询符合条件的学生信息。
5、 排序功能:以英语课程的分数为依据对学生信息进行排序。
6、 显示功能:将以上功能操作后的学生信息显示出来。
7、 退出主菜单。
1.5 性能需求
1、 输入功能:一次可以完成自定义学生人数的学生信息记录的输入。
2、 删除功能:对指定学生的信息进行删除。
3、 修改功能:对指定学生的信息进行修改。
4、 查询功能:选择某种方式并输入该信息查询符合条件的学生信息。
5、 排序功能:以英语课程的分数为依据对学生信息进行排序。
6、 显示功能:将以上功能操作后的学生信息显示出来。
7、 退出主菜单。
1.6 运行需求
1、 输入完成后,编译时要无误;
2、 链接势无误;
3、 能正确运行且完成要求功能。
1.7 任务计划
熟练掌握学生成绩管理系统的各项功能,并且要在规定的时间内完成代码的输入,还必须能正确的运行出来。
第二章 概要设计
2.1 总体设计
总体结构我们采取模块化方式进行程序设计,要求程序的功能设计、数据结构设计及整体结构设计合理。也可根据自己对题目的理解增加新的功能模块。
系统以菜单界面方式(至少采用文本菜单界面,如能采用图形菜单界面更好)工作,运行界面友好,演示程序以用户和计算机的对话方式进行
2.2 数据类型设计(或数据结构设计)
struct student
{
long id;
char name[MAX_NAME];
float Chinese,math,English,chemistry,physical;
float ave;
float tot;
}stu[100]={0};
2.3 接口设计
表2.1:函数列表
2.4 运行界面设计
while (select=Menu()) {
switch(select)
{
case 1:
ReadScore();
break;
case 2:
ave();
break;
case 3:
find();
break;
case 4:
ReadScore();
break;
case 5:
delete_();
break;
case 6:
writetofile();
break;
default:
printf("%s\n", "输入错误!");
}
第三章 详细设计
3.1 输入模块设计
static short i=0;
char temp='Y';
for(;i<100&&temp=='Y'||temp=='y';i++)
{
printf("请输入学号:");
scanf("%ld",&stu[i].id);
printf("请输入姓名:");
scanf("%s",stu[i].name);
printf("请输入语文成绩:");
scanf("%f",&stu[i].Chinese);
printf("请输入数学成绩:");
scanf("%f",&stu[i].math);
printf("请输入英语成绩:");
scanf("%f",&stu[i].English);
printf("请输入物理成绩:");
scanf("%f",&stu[i].physical);
printf("请输入化学成绩:");
scanf("%f",&stu[i].chemistry);
printf("是否继续输入(Y/N): ");
scanf(" %c",&temp);
stu[i].tot=(stu[i].Chinese+stu[i].math+stu[i].English+stu[i].chemistry+stu[i].physical);
stu[i].ave=stu[i].tot/5;
people++;
3.2 输出模块设计
printf("%ld\t%s\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\n",stu[i].id,stu[i].name,stu[i].Chinese,stu[i].math,stu[i].English,stu[i].chemistry,stu[i].physical,stu[i].tot,stu[i].ave);
3.3 查找及修改模块设计
char temp;
char k[MAX_NAME];
short i;
long n;
short m;
printf("*****************************************************************\n");
printf("*\t\t\t1.按学号查找\t\t\t\t*\n");
printf("*\t\t\t2.按姓名查找\t\t\t\t*\n");
printf("*****************************************************************\n");
printf("Please enter your choice:");
scanf("%d",&m);
if(m==1)
{
printf("请输入学号:");
scanf("%ld",&n);
for(i=0;stu[i].id!=0;i++)
{
if(n==stu[i].id)
printf("%ld\t%s\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\n",stu[i].id,stu[i].name,stu[i].Chinese,stu[i].math,stu[i].English,stu[i].chemistry,stu[i].physical,stu[i].tot,stu[i].ave);
}
}
else if(m==2)
{
printf("请输入姓名:");
scanf("%s",k);
for(i=0;stu[i].id!=0;i++)
{
if((strcmp(k,stu[i].name))==0)
printf("%ld\t%s\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\n",stu[i].id,stu[i].name,stu[i].Chinese,stu[i].math,stu[i].English,stu[i].chemistry,stu[i].physical,stu[i].tot,stu[i].ave);
}
}
else
printf("输入的选项有误!");
printf("是否修改(Y/N):");
fflush(stdin);
scanf("%c",&temp);
if(temp=='Y'||temp=='y')
{
if(m==1)
{
printf("请输入语文成绩:");
scanf("%f",&stu[i].Chinese);
printf("请输入数学成绩:");
scanf("%f",&stu[i].math);
printf("请输入英语成绩:");
scanf("%f",&stu[i].English);
printf("请输入物理成绩:");
scanf("%f",&stu[i].physical);
printf("请输入化学成绩:");
scanf("%f",&stu[i].chemistry);
stu[i].tot=(stu[i].Chinese+stu[i].math+stu[i].English+stu[i].chemistry+stu[i].physical);
stu[i].ave=stu[i].tot/5;
}
if(m==2)
{
printf("请输入学号:");
scanf("%ld",&n);
for(i=0;stu[i].id!=n;i++);
printf("请输入语文成绩:");
scanf("%f",&stu[i].Chinese);
printf("请输入数学成绩:");
scanf("%f",&stu[i].math);
printf("请输入英语成绩:");
scanf("%f",&stu[i].English);
printf("请输入物理成绩:");
scanf("%f",&stu[i].physical);
printf("请输入化学成绩:");
scanf("%f",&stu[i].chemistry);
stu[i].tot=(stu[i].Chinese+stu[i].math+stu[i].English+stu[i].chemistry+stu[i].physical);
stu[i].ave=stu[i].tot/5;
}
}
3.4 排序模块设计
short i=0,j=1;
for(i=0;i<j;i++)
{
for(j=i+1;j<people;j++)
{
if(stu[i].ave>stu[j].ave)
{
stu[people]=stu[i];
stu[i]=stu[j];
stu[j]=stu[people];
}
}
printf("%ld\t%s\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\n",stu[i].id,stu[i].name,stu[i].Chinese,stu[i].math,stu[i].English,stu[i].chemistry,stu[i].physical,stu[i].tot,stu[i].ave);
}
3.5 保存及读取模块设计
FILE *fp;
if((fp=fopen("D:\\student.txt","w"))==NULL)
{
printf("文件打开失败!\n");
exit(0);
}
fwrite(stu,sizeof(struct student),people,fp);
fclose(fp);
第四章 测试分析
4.1 测试程序执行情况
主菜单:
输入信息:
显示学生信息:
按学号查找:
按姓名查找:
修改学生信息:
4.2 出现的问题和解决的方法
在编代码时,编完一个模块,便要对其进行运行,检查是否有错,根据下方提示对错误的地方进行修改,直到运行结果正确。
第五章 用户手册(可选)
5.1 使用说明
(1)用户进入系统后,就会看到学生管理系统的主菜单页面。系统总共有七个模块,分别由0到6表示,在主菜单页面只能输入数字0到6,输入其他字符无效,如果用户输入无效字符,系统仍停留在主菜单页面。
(2)进入到主菜单页面后,用户可以根据自己的需求选择不同的选项,选择后系统就会进入子系统页面,然后用户按系统的提示操作就行了。
5.2 运行说明
1、 编写代码。
2、 对代码进行编译。
3、 编译之后进行链接。
4、 最后运行结果。
第六章 课程设计总结
在我上机调试程序的过程中,我遇到了很多的问题,我总结出在整个过程中,调试时非常重要的。调试程序需要较大的耐心。可能调试程序的时间比自己编写整个程序的时间还要长,下的工夫还要深,但这是一个程序员必须了解,也必须接受的事实。有好几次,几个错误让我很是头疼啊,很想删了,重新来过,可是最后发现,还是得有耐心去调试程序。课程设计不仅让我们巩固了所学的知识,还使得我们学习到了更多平时所忽略的,最重要的是,它磨砺了我们,让我们在大学的下一个阶段能更好的成长。
附录:程序代码
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAXN 35
#define MAX_NAME 256
struct student
{
long id;
char name[MAX_NAME];
float Chinese,math,English,chemistry,physical;
float ave;
float tot;
}stu[100]={0};
short people=0;
short Menu()
{
short select;
printf(" 学生成绩管理系统 \n");
printf("*******************************************************************\n");
printf("* 1.输入信息 *\n");
printf("* 2.按平均分排序 *\n");
printf("* 3.关键字查找,修改 *\n");
printf("* 4.插入 *\n");
printf("* 5.按学号删除 *\n");
printf("* 6.保存到磁盘 *\n");
printf("* 0.退出 *\n");
printf("*******************************************************************\n");
printf("Please enter your choice:");
scanf("%d",&select);
return select;
}
void ReadScore()
{
static short i=0;
char temp='Y';
for(;i<100&&temp=='Y'||temp=='y';i++)
{
printf("请输入学号:");
scanf("%ld",&stu[i].id);
printf("请输入姓名:");
scanf("%s",stu[i].name);
printf("请输入语文成绩:");
scanf("%f",&stu[i].Chinese);
printf("请输入数学成绩:");
scanf("%f",&stu[i].math);
printf("请输入英语成绩:");
scanf("%f",&stu[i].English);
printf("请输入物理成绩:");
scanf("%f",&stu[i].physical);
printf("请输入化学成绩:");
scanf("%f",&stu[i].chemistry);
printf("是否继续输入(Y/N): ");
scanf(" %c",&temp);
stu[i].tot=(stu[i].Chinese+stu[i].math+stu[i].English+stu[i].chemistry+stu[i].physical);
stu[i].ave=stu[i].tot/5;
people++;
}
}
void ave()
{
short i=0,j=1;
for(i=0;i<j;i++)
{
for(j=i+1;j<people;j++)
{
if(stu[i].ave>stu[j].ave)
{
stu[people]=stu[i];
stu[i]=stu[j];
stu[j]=stu[people];
}
}
printf("%ld\t%s\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\n",stu[i].id,stu[i].name,stu[i].Chinese,stu[i].math,stu[i].English,stu[i].chemistry,stu[i].physical,stu[i].tot,stu[i].ave);
}
}
void find()
{
char temp;
char k[MAX_NAME];
short i;
long n;
short m;
printf("*****************************************************************\n");
printf("*\t\t\t1.按学号查找\t\t\t\t*\n");
printf("*\t\t\t2.按姓名查找\t\t\t\t*\n");
printf("*****************************************************************\n");
printf("Please enter your choice:");
scanf("%d",&m);
if(m==1)
{
printf("请输入学号:");
scanf("%ld",&n);
for(i=0;stu[i].id!=0;i++)
{
if(n==stu[i].id)
printf("%ld\t%s\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\n",stu[i].id,stu[i].name,stu[i].Chinese,stu[i].math,stu[i].English,stu[i].chemistry,stu[i].physical,stu[i].tot,stu[i].ave);
}
}
else if(m==2)
{
printf("请输入姓名:");
scanf("%s",k);
for(i=0;stu[i].id!=0;i++)
{
if((strcmp(k,stu[i].name))==0)
printf("%ld\t%s\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\n",stu[i].id,stu[i].name,stu[i].Chinese,stu[i].math,stu[i].English,stu[i].chemistry,stu[i].physical,stu[i].tot,stu[i].ave);
}
}
else
printf("输入的选项有误!");
printf("是否修改(Y/N):");
fflush(stdin);
scanf("%c",&temp);
if(temp=='Y'||temp=='y')
{
if(m==1)
{
printf("请输入语文成绩:");
scanf("%f",&stu[i].Chinese);
printf("请输入数学成绩:");
scanf("%f",&stu[i].math);
printf("请输入英语成绩:");
scanf("%f",&stu[i].English);
printf("请输入物理成绩:");
scanf("%f",&stu[i].physical);
printf("请输入化学成绩:");
scanf("%f",&stu[i].chemistry);
stu[i].tot=(stu[i].Chinese+stu[i].math+stu[i].English+stu[i].chemistry+stu[i].physical);
stu[i].ave=stu[i].tot/5;
}
if(m==2)
{
printf("请输入学号:");
scanf("%ld",&n);
for(i=0;stu[i].id!=n;i++);
printf("请输入语文成绩:");
scanf("%f",&stu[i].Chinese);
printf("请输入数学成绩:");
scanf("%f",&stu[i].math);
printf("请输入英语成绩:");
scanf("%f",&stu[i].English);
printf("请输入物理成绩:");
scanf("%f",&stu[i].physical);
printf("请输入化学成绩:");
scanf("%f",&stu[i].chemistry);
stu[i].tot=(stu[i].Chinese+stu[i].math+stu[i].English+stu[i].chemistry+stu[i].physical);
stu[i].ave=stu[i].tot/5;
}
}
}
void delete_()
{
short i,j,k;
long id;
printf("输入要删除的学号:");
scanf("%ld",&id);
for(i=0;stu[i].id!=0;i++)
{
if(id==stu[i].id)
{
for(j=i+1,k=i;stu[k].id!=0;j++,k++)
{
stu[k]=stu[j];
}
people--;
}
}
}
void writetofile()
{
FILE *fp;
if((fp=fopen("D:\\student.txt","w"))==NULL)
{
printf("文件打开失败!\n");
exit(0);
}
fwrite(stu,sizeof(struct student),people,fp);
fclose(fp);
}
int main()
{
short select;
while (select=Menu()) {
switch(select)
{
case 1:
ReadScore();
break;
case 2:
ave();
break;
case 3:
find();
break;
case 4:
ReadScore();
break;
case 5:
delete_();
break;
case 6:
writetofile();
break;
default:
printf("%s\n", "输入错误!");
}
puts("按任意键继续");
getchar();
getchar();
system("CLS");
}
return 0;
}
致谢
姓名:樊喆
学号:1276807431
班级:12级计算机四班
学院:国际学院