资源描述
C语言课程设计实验报告
学 院 计算机学院
专 业 软件工程
年 级
姓 名
学 号
教 师
C语言课程设计实验报告
设计名称:学生成绩管理查询系统
实验项目性质:综合性
所涉及课程:C语言程序设计
计划学时:实验学时12
一、设计目的
灵活使用C语言进行程序编写,巩固有关语句,指针,结构体,链表,文件操作等概念和方法。提高调试程序的技能,提高软件编写的能力。
二、设计内容和要求
1. 学生数据包括:学号,姓名,性别,成绩(自定3到5门课程)
2. 使用链表或结构体数组处理的方法。
3. 实现功能:
l 添加数据
l 删除数据
l 查询数据
l 修改数据
l 对数据进行排序
l 链表数据可以保存在文件中
l 链表数据可从文件中读出
l 有命令菜单提示
4. 编写的程序要求完整实现功能,用户界面友好,程序运行可靠。
三、实验(设计)仪器设备和材料清单
1.硬件:PC机
2.软件:Dos,Turbo C 2.0/Turbo C++ 3.0
四、设计说明
l 程序系统的结构:运用了结构体和多个自定义函数结合。
l 程序描述:本程序的特点就是简单易懂。
l 该程序应具有的功能:可以保存输入的学生数据,可以修改,可以删除,可以查找,可以显示。
l 接口: 用图的形式说明本程序所隶属的上一层模块及隶属于本程序的下一层模块、子程序,说明参数赋值和调用方式,说明与本程序相直接关联的数据结构(结构体等)。
l 注释,加在模块首部的注释,加在各分枝点处的注释,对各变量的功能、范围、缺省条件等所加的注释,对使用的逻辑所加的注释等等。
l 限制条件:知识的限制。
l 尚未解决的问题:不可以输出文字,要用拼音或者英语来代替。
五、程序清单和注释
#include "stdio.h" /*I/O函数*/
#include "stdlib.h" /*其它说明*/
#include "string.h" /*字符串函数*/
#include "conio.h" /*屏幕操作函数*/
#include "mem.h" /*内存操作函数*/
#include "ctype.h" /*字符操作函数*/
#include "alloc.h" /*动态地址分配函数*/
struct score
{
int mingci;
char xuehao[8];
char mingzi[20];
char sex[2];
float score[6];
}data,info[1000];
int i,j,k=0;
char temp[20],ch;
FILE *fp,*fp1;
void shuru() /*输入学生的成绩和其他信息*/
{
if((fp=fopen("s_score.txt","ab+"))==NULL)
{
printf("cannot open this file.\n");
getch();exit(0);
}
for(i=0;i<=1000;i++)
{
printf("\nPlease shuru xuehao:");
gets(data.xuehao);
printf("Please shuru mingzi:");
gets(data.mingzi);
printf("Please shuru sex:");
gets(data.sex);
printf("Please shuru yuwen score:");
gets(temp);data.score[0]=atof(temp);
printf("Please shuru shuxue score:");
gets(temp);data.score[1]=atof(temp);
printf("Please input yingyu score:");
gets(temp);data.score[2]=atof(temp);
printf("Please shuru wuli score:");
gets(temp);data.score[3]=atof(temp);
printf("Please shur huaxue score:");
gets(temp);data.score[4]=atof(temp);
data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4];
fwrite(&data,sizeof(data),1,fp);
printf("another?y/n");
ch=getch();
if(ch=='n'||ch=='N')
break;
} fclose(fp);
}
void xianshi()
{
float s;int n;
if((fp=fopen("s_score.txt","rb+"))==NULL)
{
printf("Cannot reading this file.\n");
exit(0);
}
for(i=0;i<=1000;i++)
{
if((fread(&info[i],sizeof(info[i]),1,fp))!=1)
break;
}
printf("\n xuehao mingzi sex yuwen shuxue yingyu wuli huauxue zhongfen\n");
for(j=0,k=1;j<i;j++,k++)
{
info[j].mingci=k;
printf("%6s %8s %2s %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f\n",info[j].xuehao,info[j].mingzi,info[j].sex,info[j].score[0],info[j].score[1],info[j].score[2],info[j].score[3],info[j].score[4],
info[j].score[5]);
}
getch();
fclose(fp);
}
void xiugai() /*修改学生的成绩和信息*/
{
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
{
printf("Cannot open this file.\n");
exit(0);
}
printf("\nPLease shuru xiugai xuehao:");
scanf("%d",&i); getchar();
while((fread(&data,sizeof(data),1,fp))==1)
{
j=atoi(data.xuehao);
if(j==i)
{
printf("xuehao:%s\nmingzi:%s\n",data.xuehao,data.mingzi);
printf("Please shuru mingzi:");
gets(data.mingzi);
printf("Please shuru yuwen score:");
gets(temp);data.score[0]=atof(temp);
printf("Please shuru shuxue score:");
gets(temp);data.score[1]=atof(temp);
printf("Please input yingyu score:");
gets(temp);data.score[2]=atof(temp);
printf("Please input wuli score:");
gets(temp);data.score[3]=atof(temp);
printf("Please input huaxue score:");
gets(temp);data.score[4]=atof(temp);
data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4];
} fwrite(&data,sizeof(data),1,fp1);
}
fseek(fp,0L,0);
fseek(fp1,0L,0);
while((fread(&data,sizeof(data),1,fp1))==1)
{
fwrite(&data,sizeof(data),1,fp);
}
fclose(fp);
fclose(fp1);
}
void chazhao()/*查找学生的成绩和信息*/
{
if((fp=fopen("s_score.txt","rb"))==NULL)
{
printf("\nCannot open this file.\n");
exit(0);
}
printf("\nPLease shuru xuehao chakan:");
scanf("%d",&i);
while(fread(&data,sizeof(data),1,fp)==1)
{
j=atoi(data.xuehao);
if(i==j)
{
printf(" xuehao:%s\n mingzi:%s\n sex:%s\n yuwen:%3.1f\n shuxue:%3.1f\n yingyu:%3.1f\n wuli:%3.1f\n huaxue:%3.1f\n ",data.xuehao,data.mingzi,data.sex,data.score[0],data.score[1],data.score[2],data.score[3],data.score[4],data.score[5]);
}getch();
}
}
void shanchu()/*删除学生的成绩和信息*/
{
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
{
printf("\nopen score.txt was failed!");
getch();
exit(0);
}
printf("\nPlease input ID which you want to del:");
scanf("%d",&i);getchar();
while((fread(&data,sizeof(data),1,fp))==1)
{
j=atoi(data.xuehao);
if(j==i)
{
printf("Anykey will delet it.\n");
getch();
continue;
}
fwrite(&data,sizeof(data),1,fp1);
}
fclose(fp);
fclose(fp1);
remove("s_score.txt");
rename("temp.txt","s_score.txt");
printf("Data delet was succesful!\n");
printf("Anykey will return to main.");
getch();
}
main()/*主界面*/
{
while(1)
{
clrscr(); /*清屏幕*/
gotoxy(1,1); /*移动光标*/
textcolor(YELLOW); /*设置文本显示颜色为黄色*/
textbackground(BLUE); /*设置背景颜色为蓝色*/
window(1,1,99,99); /* 制作显示菜单的窗口,大小根据菜单条数设计*/
clrscr();
printf("**************welcome to use student manage******************\n");
printf("*************************menu****************************\n");
printf("* ================================================= * \n");
printf("* 1>shuru 2>xiugai \n");
printf("* 3>shanchu 4>chazhao \n");
printf("* 5>xianshi 6>exit \n");
printf("* ================================================= * \n");
printf(" Please input which you want(1-6):");
ch=getch();
switch(ch)
{
case '1':shuru();break;
case '2':xiugai(); break;
case '3':shanchu(); break;
case '4':chazhao(); break;
case '5':xianshi(); break;
case '6':exit(0);
default: continue;
}
}
}
六.实验感想:完成这个实验后我收获了很多,学会了很多课外的知识,认识到自己还有很多不足,还有很多自己解决不了的东西,但是通过上网查询和请教其他人,我可以把一些我自己不能解决的知识都解决了,并且学会了自己独立研究。这次课程设计真的使我获益匪浅!
7
展开阅读全文