C语言考试系统.docx
《C语言考试系统.docx》由会员分享,可在线阅读,更多相关《C语言考试系统.docx(12页珍藏版)》请在冰豆网上搜索。
C语言考试系统
数据结构
课程设计报告
设计题目:
设计一个C语言考试系统
专业软件工程
班级0911
学生彭仕剑
学号20091828
指导教师邓松
起止时间2010-6-15至2010-7-8
一、实验目的
1、加深对授课内容的理解
2、通过设计,熟练上机调试程序
3、提高C语言综合程序设计能力
二、实验题目与相关说明
题目:
设计一个C语言考试系统
功能:
该考试系统主要针对客观题(单选题)进行自动出题与答题。
首先要根据章节,难度录入试题,即每道题目有章节也有难度。
要设计一个教师试卷设计模块,让教师选择考试的章节与每个章节要多少道题目,题目由难度系数为多少。
系统根据教师的选择,随机选择题目组成一试卷,让学生答题
要求:
1)界面友好,函数功能要划分好
2)总体设计应画一流程图
3)程序要加必要的注释
4)要提供程序测试方案
5)程序一定要经得起测试,宁可功能少一些,也要能运行起来,不能运行的程序是没有价值的。
三、程序功能简介
该考试系统主要针对客观题(单选题)进行自动出题与答题。
它具有录入试题,选题测验等功能。
“录入试题”为教师试题设计模块,在该模块中教师可以输入相应的C语言试题,系统会自动将输入的试题存入一个相关文件中。
“选题测验”为教师试卷设计模块,在该模块中教师可以规定考试要多少道题目,,系统将根据教师的需要,随机选择题目组成一份试卷,让学生答题,但模块中试题的章节和难度系数设计我还未完成。
此外,我在该系统中添加了试卷评分功能。
它能够根据试卷题目的数量,以及考生做对的试题数来评分。
四、程序相关函数及说明
intMenuChoice(void);
该函数主要负责进入系统主界面,教师可以在此界面选择相应的功能。
structquestion*InsertList(structquestion*fst,conststructquestion*ad);
该函数用于实现试题的存储,它用的是动态存储方式。
structquestion*ListSeek(structquestion*seek,longlen,longmax);
该函数用于试题的搜索,即“选题测验”模块中对试题的选择。
voidGetQuestion(structquestion*src);
该函数用于实现试题的录入,函数中还调用了intGetAnswer(void)。
voidSaveFile(conststructquestion*ed,FILE*saf);
该函数用于打开系统文件,此文件中为考试试题。
structquestion*LoadFile(structquestion*td,FILE*laf);
该函数用于创建文件,函数返回值为数据的存放地址。
intGetAnswer(void);
该函数用于存储各试题的正确答案,答案只限A、B、C、D。
voidExplainQuestion(conststructquestion*que,intn);
该函数用于对考生答题后的试卷评分,即实现系统评分功能。
五、程序源码
#include
#include
#include
#include"conio.h"
structquestion{
charask[200];
charanswer[4][80];
intright;
structquestion*next;
};
intMenuChoice(void);
structquestion*InsertList(structquestion*fst,conststructquestion*ad);
structquestion*ListSeek(structquestion*seek,longlen,longmax);
voidGetQuestion(structquestion*src);
voidSaveFile(conststructquestion*ed,FILE*saf);
structquestion*LoadFile(structquestion*td,FILE*laf);
intGetAnswer(void);
voidExplainQuestion(conststructquestion*que,intn);
structquestion*ListSeek(structquestion*seek,longlen,longmax)
{
inti;
srand(time(NULL));
while(i=rand()%max+len;
while(i--)
seek=seek->next;
returnseek;
}
structquestion*InsertList(structquestion*fst,conststructquestion*ad)
{
structquestion*newPtr=(structquestion*)malloc(sizeof(structquestion));
if(newPtr==NULL)
exit(0);
*newPtr=*ad;
newPtr->next=fst;
returnnewPtr;
}
voidGetQuestion(structquestion*src)
{
inti=0;
printf("输入题干:
\n");
scanf("%s",src->ask);
while(i<4){
printf("输入备选答案%c:
\n",i+'A');
scanf("%s",src->answer[i++]);
}
src->right=GetAnswer();
}
structquestion*LoadFile(structquestion*td,FILE*laf)
{
structquestiontemp;
while(fread(&temp,1,sizeof(structquestion),laf))
td=InsertList(td,&temp);
returntd;
}
voidSaveFile(conststructquestion*ed,FILE*saf)
{
fclose(saf);
if((saf=fopen("kstm.txt","w"))==NULL)
return;
while(ed){
fwrite(ed,1,sizeof(structquestion),saf);
ed=ed->next;
}
}
intGetAnswer(void)
{
intc=0;
fflush(stdin);
printf("输入正确答案:
");
scanf("%s",&c);
while(c<'A'||c>'D')
{
fflush(stdin);
printf("输入有误,请重输:
");
scanf("%s",&c);
}
returnc;
}
voidExplainQuestion(conststructquestion*que,intn)
{
inti=0,t=n;
charresult[1001],*p=result;
for(i=0;n--;que=que->next){
printf("%s\nA.%s\nB.%s\nC.%s\nD.%s\n\n",que->ask,que->answer[0],que->answer[1],
que->answer[2],que->answer[3]);
if((*p=que->right)==(*(p+1)=GetAnswer()))
++i;
p+=2;
}
*p='\0';
printf("\n%-13s%-13s%s\n","正确答案","你的回答","评价");
for(p=result;*p!
='\0';p+=2)
printf("%-13c%-13c%s\n",*p,*(p+1),*p==*(p+1)?
"正确":
"错误");
printf("\n你回答了%d题,正确%d题,错误%d题,最后得分%f\n",t,i,t-i,(float)i/t*100.00);
}
intMenuChoice(void)
{
intvalue;
system("color0a");
printf("\n\t*********************************\n");
printf("\t*\t*C语言考试系统**\n");
printf("\t*\t***\n");
printf("\t*\t**********************\n");
printf("\t*\t*1.录入试题**\n");
printf("\t*\t***\n");
printf("\t*\t***\n");
printf("\t*\t*2.选题测验**\n");
printf("\t*\t***\n");
printf("\t*\t***\n");
printf("\t*\t*3.退出系统**\n");
printf("\t*********************************\n");/*输出提示信息*/
printf("选择功能(1-3):
[]\b\b");
scanf("%d",&value);
returnvalue;
}
main()
{
structquestion*start=NULL,temp;
intchoice,line=0,c;
FILE*fp=fopen("kstm.txt","a+");
//clrscr();
start=LoadFile(start,fp);
while((choice=MenuChoice())!
=3)
if(choice==1){
GetQuestion(&temp);
start=InsertList(start,&temp);
line++;
}
elseif(choice==2){
c=600;
while(c>500)
{
printf("输入试题数目(数字):
");
scanf("%d",&c);
while(c<=0)
{
printf("输入有误,请重输:
");
scanf("%d",&c);
}
while(line{
printf("试题不足,请重输:
");
scanf("%d",&c);
while(c<=0)
{
printf("输入有误,请重输:
");
scanf("%d",&c);
}
}
}
line=c;
ExplainQuestion(start,line);
}
elseif(choice!
=1||choice!
=2||choice!
=3)
{
printf("输入有误,请重输!
");}
SaveFile(start,fp);
fclose(fp);
return0;
}
六、程序测试
说明:
检测程序是否运行正常,并浏览系统界面。
七、系统各功能测试
1、录入试题
说明:
输入“1.aaaaaaaaaaaaaaaaaaaaaa
A.1111B.2222C.3333D.4444
2.bbbbbbbbbbbbbbbbbbbbbb
A.1111B.2222C.3333D.4444
3.ccccccccccccccccccc
A.1111B.2222C.0D.-111111
”。
正确答案分别为B、C、D。
2.选题测验
说明:
选择功能后,输入需要的试题数。
(在此为3)
3.评分功能
说明:
输入试题答案分别为B、C、C。
(此处试题顺序随机)
4.退出系统
说明:
若所有操作完成,可在主菜单中输入“3”退出系统。
八、实验心得
通过本次C语言上机实验,我对这个介于人类与非人类之间的计算机编程语言有了较上学期进一步的认识。
其间开心过、郁闷过、无奈过、彷徨过……随着实验的胜利成功与实验报告的顺利完成,有点微微的自豪感使人难忘。
感谢邓松老师的高标准、严要求,感谢实验课上邓老师的耐心指点,也感谢我在实验中经历过的点点滴滴……伴随着学习的深入,我发现高深的东西还有很多很多,等待着我自己去挖掘。
对C语言,我会更加努力。