您的位置:首页 > 其它

四六级考试评分程序

2015-12-09 19:01 295 查看
#include<iostream>
#include<cstring>
#include<stdlib.h>
#include<time.h>
#define MAXSIZE 55         //选择题的数量
#define MAXSIZE2 60        //卷子的数量
using namespace std;
float count;                 //计数
int main()
{
    cout<<"  * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl;
    cout<<"  *  试卷说明:                                   *"<<endl;
    cout<<"  *  共65道选择题,其中1~25为听力,每题7.1分;    *"<<endl;
    cout<<"  *  26~35为完型填空,每题3.55分;                *"<<endl;
    cout<<"  *  36~45为快速匹配,每题7.1分;                 *"<<endl;
    cout<<"  *  46~55为阅读,每题14.2分;                    *"<<endl;
    cout<<"  * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl;
    int i,k,score;
    char a[MAXSIZE+1],b[MAXSIZE+1];
    count=0.0;k=1;
    srand((unsigned)time(0));    //时间不同,产生的种子也不同
    FILE *fp=fopen("d:\\siliuji.txt","w");
    //生成随机标准答案
    char str[17]="Z";
    char *p;
    int y=1;
    for(i=0;i<55;i++)
    {
        if(i>=35&&i<=44)
           a[i]=rand()%12+65;
           else if(i>=25&&i<=34)
          {
            while(1)
            {
              a[i]=rand()%15+65;             
               p=strchr(str,a[i]);  //检测生成的答案是否重复 
              if(!p)
              {
				   str[y++]=a[i];
                   break;
              }
            }
          }
        else
            a[i]=rand()%4+65;
    }
    //输出标准答案
    for(i=0;i<55;i++)
    {
	   fprintf(fp,"%c ",a[i]);
	   cout<<a[i]<<" ";
       if((i+1)%11==0)
       {
       	   fprintf(fp,"\n");
		   cout<<endl;
       }
    } 
    fprintf(fp,"\n");
    cout<<endl;
    //循环生成60套试卷
     while(k<=60)
     {
         count=0;
		 score=0;
		 char string[17]="Z";
         char *ptr;
         int x=1;
         //生成55道选择题,并与标准答案进行比对
         for(i=0;i<55;i++)
       {
          if(i>=35&&i<=44)
            b[i]=rand()%12+65;
            else if(i>=25&&i<=34)
          {
            while(1)
            {
              b[i]=rand()%15+65;
               ptr=strchr(string,b[i]);
              if(!ptr)
              {
				   string[x++]=b[i];
                   break;
              }
            }
          }
          else
            b[i]=rand()%4+65;
       if(b[i]==a[i])
        {
           count++;
           if(i>=25&&i<=34)
            score+=3.55;
            else if(i>=45)
                score+=14.2;
            else
                score+=7.1;
        }
       }
       //结果输出
     for(i=0;i<55;i++)
       {
         fprintf(fp,"%c ",b[i]);
		 cout<<b[i]<<" ";
         if((i+1)%11==0)
         {
         	fprintf(fp,"\n");
         	cout<<endl;
         }
       }
    fprintf(fp,"第%d套卷子的正确率为:%f%\n",k,(count/55)*100);
    cout<<"第"<<k++<<"套卷子的正确率为:"<<((float)count/55)*100<<"%"<<endl;
    fprintf(fp,"分值为:%d\n",score);
    cout<<"分值为:"<<score<<endl;
    cout<<endl;
     }
   system("pause");
   return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: