能力测试系统C语言.docx
《能力测试系统C语言.docx》由会员分享,可在线阅读,更多相关《能力测试系统C语言.docx(18页珍藏版)》请在冰豆网上搜索。
![能力测试系统C语言.docx](https://file1.bdocx.com/fileroot1/2023-2/2/3fe95ceb-b830-4b93-b638-68d0d36171dd/3fe95ceb-b830-4b93-b638-68d0d36171dd1.gif)
能力测试系统C语言
/*ThisisaprogramforExamination,inthisprogramyoucandotheexam,andtherehavethreeparts.Thefirstiscount,
secondisfilling,thirdisapp.Youshouldfinishtheexaminthetimeweset.Thelastwillgiveyoutherightanswer.
Theauthor:
Joyce、Davin、Hilary.*/
#include
#include
#include
#include
#include
typedefstruct
{
charname[10];
longintnum[20];
}student;
structclock
{
inthours;
intminutes;
intseconds;
}times;
intpassword(int);/*输入进入系统的密码-1234*/
voidcover();/*系统的封面*/
intstuInf();/*用来记录学生的名字和学号并且写入文件*/
voidtestCover();/*试卷的封面*/
voidcount();/*计算题题目*/
voidfilling();/*填空题题目*/
voidapp();/*应用题题目*/
inttest();/*让学生是否要改答案,并且对正确答案和学生输入的答案进行比较,然后给分数*/
voidDisplayscores();/*接受分数,并且显示分数*/
voidDisplayAnswer();/*在程序的最后给正确的答案*/
voiddisplay();/*获取系统时间在开始进入程序后显示时间,又在结束之前给时间,并比较两者的时间差看是否超出规定时间,判断是否给分*/
voidmain()
{
FILE*fp,*fp2,*fp3;/*fp用来记录试卷,fp2用来记录正确答案,fp3用来记录学生输入的答案*/
FILE*s;/*记录学生的名字和学号以便输出*/
doubletimes,beginTime,endTime;
intscore,ans;
intifright,time=1;
studentstu;
beginTime=clock();
display();
printf("\nPleaseenterpasswordforthesystem:
");
ifright=password(time);
if(ifright==1)
{
cover();
ans=stuInf();
if(ans==1)
{
score=test();
DisplayAnswer();
display();
endTime=clock();
times=(endTime-beginTime)/CLK_TCK;/*刚开始考试和考完后的时间差*/
printf("\nYouuse%fseconds\n",times);
if(times>60)/*如果你做试卷的时间超出了60秒钟那么你的分数只能是0分*/
printf("\nYouusetoomuchtimesoyourscoreis0\n");
else
Displayscores(score);
}
}
getch();
return;
}
voiddisplay()
{
FILE*fp1;
time_tnowtime;
inthour,min,sec;
structtm*timeinfo;
time(&nowtime);
timeinfo=localtime(&nowtime);
hour=timeinfo->tm_hour;
min=timeinfo->tm_min;
sec=timeinfo->tm_sec;
fp1=fopen("time.txt","r");
fscanf(fp1,"\r%02d:
%02d:
%02d",&hour,&min,&sec);
fprintf(stdout,"\r%02d:
%02d:
%02d",hour,min,sec);
fclose(fp1);
return;
}
voidcover()
{
printf("\n------------------------------------------\n");
printf("\n|ExamTest|\n");
printf("\n|Thisisasystemforstudentto|\n");
printf("\n|testtheirabilityafterlearning|\n");
printf("\n|aterm.Youwillhave20secondsto|\n");
printf("\n|finishit,afteryousubmit,thesystem|\n");
printf("\n|willgivetherightanswerandmark.|\n");
printf("\n|goodluck!
|\n");
printf("\n------------------------------------------\n");
return;
}
intpassword(inttime)
{
intch1,ch2,ch3,ch4;
for(time=1;time<=3;time++)
{
ch1=getch();
putch('*');
ch2=getch();
putch('*');
ch3=getch();
putch('*');
ch4=getch();
putch('*');
if(ch1=='1'&&ch2=='2'&&ch3=='3'&&ch4=='4')
{
printf("\nYouareright!
Welcometotheexamtest!
");
return1;
}
else
printf("\nYourpasswordiswrong\n");
if(time==3)
return0;
}
}
intstuInf()
{
FILE*s;
intj;
studentstu;
s=fopen("infor.txt","wb");
printf("\nPleaseenteryourname:
");
scanf("%s",stu.name);
flushall();
for(j=1;j<=3;j++)
{
flushall();
printf("\nEnteryournumber,thenumbermustlikethat8107041**:
");
scanf("%ld",&stu.num[0]);
if(stu.num[0]>=810704101&&stu.num[0]<=810704145)
{
fwrite(&stu,sizeof(stu),1,s);
getchar();
fclose(s);
return1;
}
else
{
printf("\nYournumbercannotfind!
\n");
}
if(j==3)
return0;
}
}
inttest()
{
FILE*fp,*fp2,*fp3;
intm,n,i;
charanswer;
intscore=0;
intstu_ans1[10],stu_ans2[10],stu_ans3[2];
intright_ans1[10],right_ans2[10],right_ans3[2];
fp=fopen("test.txt","a");
fp2=fopen("rightAnswer.txt","a");
fp3=fopen("stuAnswer.txt","a");
testCover();
count();
filling();
app();
clrscr();
printf("\nDoyouwanttoamendyourcountanswer?
(y/n):
");
answer=getch();
putch(answer);
while(answer=='y')
{
begin:
printf("\nPleaseenterthenumberofthesubject:
");
scanf("%d",&m);
if(m<0)
{
printf("\nThenumberyouwanttoamendistoosmall!
Tryagain!
\n");
gotobegin;
}
elseif(m>10)
{
printf("\nThenumberyouwanttoamendistoobig!
\n");
gotobegin;
}
printf("Pleaseenteryouranswer:
");
scanf("%d",&stu_ans1[m-1]);
fprintf(fp3,"\nTheansweryouamendis:
\n",stu_ans1[m-1]);
fprintf(fp3,"NO.%d:
%d\n",m,stu_ans1[m-1]);
fprintf(fp3,"\n%d\n",stu_ans1[m-1]);
printf("\nDoyouwanttoamendagain?
y/n");
answer=getch();
putch(answer);
}
printf("\nDoyouwanttoamendyourfillinganswer?
(y/n):
");
answer=getch();
putch(answer);
while(answer=='y')
{
start:
printf("\nPleaseenterthenumberofthesubject:
");
scanf("%d",&n);
if(n<10)
{
printf("\nThenumberyouwanttoamendistoosmall!
Tryagain!
\n");
gotostart;
}
if(n>30)
{
printf("Thenumberyouwanttoamendistoobig!
\n");
gotostart;
}
printf("\nPleaseenteryouranswer:
");
scanf("%d",&stu_ans2[n-11]);
fprintf(fp3,"\nTheansweryouamendis:
\n",stu_ans2[n-11]);
fprintf(fp3,"NO.%d:
%d\n",n,stu_ans2[n-11]);
fprintf(fp3,"\n%d\n",stu_ans2[n-11]);
printf("\nDoyouwanttoamendagain?
y/n");
answer=getch();
putch(answer);
}
printf("\nDoyouwanttoamendtheappanswer?
(y/n):
");
answer=getch();
putch(answer);
while(answer=='y')
{
printf("\nPleaseentertheansweryouwanttoamend:
");
scanf("\n%d,%d",&stu_ans3[0],stu_ans3[1]);
fprintf(fp3,"\nTheansweryouamendis:
\n",stu_ans3[0],stu_ans3[1]);
fprintf(fp3,"\nNO41:
%d,%d",stu_ans3[0],stu_ans3[1]);
fprintf(fp3,"\n%d,%d\n",stu_ans3[0],stu_ans3[1]);
printf("\nDoyouwanttoamendagain?
(y/n):
");
answer=getch();
putch(answer);
}
fclose(fp2);
fclose(fp3);
fp2=fopen("rightAnswer.txt","r");
fp3=fopen("stuAnswer.txt","r");
for(i=0;i<10;i++)
{
fscanf(fp3,"\n%d\n",&stu_ans1[i]);
fscanf(fp2,"\n%d\n",&right_ans1[i]);
if(stu_ans1[i]==right_ans1[i])
score+=4;
}
for(i=0;i<10;i++)
{
fscanf(fp3,"\n%d\n",&stu_ans2[i]);
fscanf(fp2,"\n%d\n",&right_ans2[i]);
if(stu_ans2[i]==right_ans2[i])
score+=4;
}
fscanf(fp3,"\n%d,%d\n",&stu_ans3[0],&stu_ans3[1]);
fscanf(fp2,"\n%d,%d\n",&right_ans3[0],&right_ans3[1]);
for(i=0;i<2;i++)
{
if(stu_ans3[i]==right_ans3[i])
score+=20;
}
fclose(fp2);
fclose(fp3);
fprintf(fp,"\nYourscoresis%d\n",score);
fclose(fp);
returnscore;
}
voidtestCover()
{
printf("\n----------------------------------------------\n");
printf("\n|Welcometotheexmatest!
|\n");
printf("\n|Thetesthavethreepast,NO1:
the|\n");
printf("\n|count.NO2:
thefilling.NO3;theapp.Each|\n");
printf("\n|subjecthave2scores.Theapphave20scores|\n");
printf("\n----------------------------------------------\n");
return;
}
voidcount()
{
FILE*fp,*fp2,*fp3;
inti,op;
intnum1,num2;
intright_ans1[10];
intstu_ans1[10];
clrscr();
fp=fopen("test.txt","a");
fp2=fopen("rightAnswer.txt","a");
fp3=fopen("stuAnswer.txt","a");
printf("\nNowisthefirstpartofcount!
Eachtitlehave2scores!
\n");
for(i=0;i<10;i++)
{
num1=rand()%200;
num2=rand()%200;
op=rand()%3;
if(op==0)
{
printf("NO.%d:
%d+%d=\n",i+1,num1,num2);
scanf("%d",&stu_ans1[i]);
right_ans1[i]=num1+num2;
fprintf(fp,"NO.%d:
%d+%d=%d\n",i+1,num1,num2,right_ans1[i]);
fprintf(fp2,"\n%d\n",right_ans1[i]);
fprintf(fp3,"\n%d\n",stu_ans1[i]);
}
if(op==1)
{
printf("NO.%d:
%d-%d=\n",i+1,num1,num2);
scanf("%d",&stu_ans1[i]);
right_ans1[i]=num1-num2;
fprintf(fp,"NO.%d:
%d-%d=%d\n",i+1,num1,num2,right_ans1[i]);
fprintf(fp2,"\n%d\n",right_ans1[i]);
fprintf(fp3,"\n%d\n",stu_ans1[i]);
}
if(op==2)
{
printf("NO.%d:
%d*%d=\n",i+1,num1,num2);
scanf("%d",&stu_ans1[i]);
right_ans1[i]=num1*num2;
fprintf(fp,"NO.%d:
%d*%d=%d\n",i+1,num1,num2,right_ans1[i]);
fprintf(fp2,"\n%d\n",right_ans1[i]);
fprintf(fp3,"\n%d\n",stu_ans1[i]);
}
}
printf("\n\n");
fclose(fp);
fclose(fp2);
fclose(fp3);
return;
}
voidfilling()
{
FILE*fp,*fp2,*fp3;
inti;
intchose;
intnum3,num4;
intright_ans2[10];
intstu_ans2[10];
clrscr();
fp=fopen("test.txt","a");
fp2=fopen("rightAnswer.txt","a");
fp3=fopen("stuAnswer.txt","a");
printf("\nNowisthefillingpart!
Eachtitlehave2scores!
\n");
for(i=0;i<10;i++)
{
num3=rand()%200;
num4=rand()%200;
chose=rand()%3;
if(chose==1)
{
printf("\nNO%d:
___plus%dis%d,youransweris:
\n",i+11,num3,num3+num4);
scanf("%d",&stu_ans2[i]);
right_ans2[i]=num4-num3;
fprintf(fp,"\nNO%d:
___plus%dis%d,youransweris:
\n",i+11,num3,num3+num4,right_ans2[i]);
fprintf(fp2,"\n%d\n",right_ans2[i]);
fprintf(fp3,"\n%d\n",stu_ans2[i]);
}
if(chose==0)
{
printf("\nNO%d:
%dminus___is%d,youransweris:
\n",i+11,num3,num3-num4);
scanf("%d",&stu_ans2[i]);
right_ans2[i]=num3-num4;
fprintf(fp,"\nNO%d:
%dminus___is%d,youransweris:
\n",i+11,num3,num3-num4,right_ans2[i]);
fprintf(fp2,"\n%d\n",right_ans2[i]);
fprintf(fp3,"\n%d\n",stu_ans2[i]);
}
if(chose==2)
{
printf("\nNO%d:
%dmultiply%dis___,youransweris:
\n",i+11,num3,num4);
scanf("%d",&stu_ans2[i]);
right_ans2[i]=num3*num4;
fprintf(fp,"\nNO%d:
%dmultiply%dis___,youransweris:
\n",i+11,num3,num4,right_ans2[i]);
fprintf(fp2,"\n%d\n",right_ans2[i]);
fprintf(fp3,"\n%d\n",stu_ans2[i]);
}
}
printf("\n\n");
fclose(fp);
fclose(fp2);
fclose(fp3);
return;
}
voidapp()
{
FILE*fp,*fp2,*fp3;
inti;
intchicken,rabbit;
intright_ans3[2];
intstu_ans3[2];
clrscr();
fp=fopen("test.txt","a");
fp2=fopen("rightAnswer.txt","a");
fp3=fopen("stuAnswer.txt","a");
printf("\nNowistheapppart!
Thisparthave20scores!
Goodluck!
\n");
printf("\n******************************************************\n");
printf("\n*Thisprogramistosolvetheproblemof*\n");
printf("\n*ChickensandRabbitsareinthesamecage.*\n");
printf("\n*It'sknownthattheyhave38headsan