你好,欢迎来到电脑编程技巧与维护杂志社! 杂志社简介广告服务读者反馈编程社区  
合订本订阅
 
 
您的位置:杂志经典 / 编程语言
2.6 VC++万能网考系统(下)
 

    CString strItem;  strItem.Format("SelectMoreItem%d", iMore);

              int ResultA = ::GetPrivateProfileInt(strItem,"A",0,".\\Temp.ini");

              int ResultB = ::GetPrivateProfileInt(strItem,"B",0,".\\Temp.ini");

              int ResultC = ::GetPrivateProfileInt(strItem,"C",0,".\\Temp.ini");

              int ResultD = ::GetPrivateProfileInt(strItem,"D",0,".\\Temp.ini");

                if(ResultA==1) { RedioA->SetCheck(1); iA=1; }

                if(ResultB==1) { RedioB->SetCheck(1); iB=1; }

                if(ResultC==1) { RedioC->SetCheck(1); iC=1; }

                if(ResultD==1) { RedioD->SetCheck(1); iD=1; }

           //根据多选题序号标记,从INI配置中获得相应的题库索引并启动出题目显示在文本框中

CString strItemName; strItemName.Format("Item%d", iMore);

             ::GetPrivateProfileString("SelectMoreTitle",strItemName,NULL,strFileName.GetBuffer(128),128,strCurrentINI);

              ReadFile(strFileName);

}

第三步:添加列表单击响应函数LBN_SELCHANGE并在各类选题中作好相应的选项标记与题目序号后去调用各自的配置处理函数来完成相应的单击功能,具体代码如下。

void CIEExamSysDlg::OnSelchangeList1()

{  //设置单选题选项的单击代码响应功能

       if( m_List.GetCurSel()>0 && m_List.GetCurSel()<=iSingleCount )

{ iListSelPos = m_List.GetCurSel(); iSingle = m_List.GetCurSel(); SelectSingleConfig(); }

   //设置判断题选项的单击代码响应功能

       if(m_List.GetCurSel()>iSingleCount+1 && m_List.GetCurSel()<=iSingleCount+iJudgeCount+1)

{ iListSelPos= m_List.GetCurSel(); iJudge = m_List.GetCurSel()-(iSingleCount+1); JudgeConfig(); }

   //设置多选题选项的单击代码响应功能

       if ( iJudgeCount == 0 ) 

{//判断是否设置有判断题,如果有则要再增加一个标题项

if(m_List.GetCurSel()>iSingleCount+iJudgeCount+1) if(m_List.GetCurSel()<=iSingleCount+iJudgeCount+iMoreCount+1)

{ iListSelPos= m_List.GetCurSel();iMore =m_List.GetCurSel()-

(iSingleCount+iJudgeCount+1);

SelectMoreConfig();

}   

}

else

{  if(m_List.GetCurSel()>iSingleCount+iJudgeCount+2)

if(m_List.GetCurSel()<=iSingleCount+iJudgeCount+iMoreCount+2)

{  iListSelPos= m_List.GetCurSel();

iMore=m_List.GetCurSel() - (iSingleCount+iJudgeCount+2); SelectMoreConfig();

}         

   }

}

第四步:为Redio答案组添加一个答案配置处理函数,其中主要是依据单击列表选题时留下的选题类型序号标记是否为0来进行自动识别且分类处理,最后在各个Redio单击响应函数中调用该函数来完成答案处理功能。所要完成的主要功能是对已选择过答案的选题赋予OK!完成标志;将当前的答案写入Temp.ini文件中;将当前答案与标准答案进行对比并将所得分数写入Temp.ini文件中。需要注意的是如果处于多选题状态时则还应将Redio按钮组的单选特性处理成具有多选与取消选中的功能。

先为所有的Redio答案组添加一个配置函数RedioConfig()并在其中添加如下代码来完成有关功能。

  void CIEExamSysDlg::RedioConfig()

{ //处于单选题状态时所完成的有关功能如下////////////////////////////////////////////////////////////

if( iSingle != 0 )

{ //从总表中获得小题的规定分数并从选中的那套题中获得该题的标准答案

         CString strResult; CString strKey; CString strSel; CString ItemPoints;

         strSel.Format("Item%d", iSingle);

         ::GetPrivateProfileString("CONFIG","SelectSinglePoints",NULL,ItemPoints.GetBuffer(128),128,".\\CONFIG.INI");

               ::GetPrivateProfileString("SelectSingleResult",strSel,NULL,strResult.GetBuffer(128),128,strCurrentINI);

        //在选择答案的同时给出OK提示

          CString strListItem; strListItem.Format( " 单选题%d       OK!", iSingle );

m_List.DeleteString(iListSelPos); m_List.InsertString(iListSelPos, strListItem );

        //将单选题序号所对应的答案以及与标准答案对比后的所得分写入Temp.ini文件 

             if(iRedio == 1) strKey = "A";  if(iRedio == 2) strKey = "B";

             if(iRedio == 3) strKey = "C";  if(iRedio == 4) strKey = "D";

           if(strKey == strResult)

           ::WritePrivateProfileString("SelectSingleItemPoints",strSel,ItemPoints,".\\Temp.ini");

           else ::WritePrivateProfileString("SelectSingleItemPoints",strSel,"0",".\\Temp.ini");   

               ::WritePrivateProfileString("SelectSingleResult",strSel,strKey,".\\Temp.ini");  return;

       }

//处于判断题状态时所完成的有关功能如下

if( iJudge != 0 )

{ //从总表中获得小题的规定分数并从选中的那套题中获得该题的标准答案

      CString strResult; CString strKey; CString strSel; CString JudgeItemPoints;

         strSel.Format("Item%d", iJudge);

          ::GetPrivateProfileString("CONFIG","JudgePoints",NULL,JudgeItemPoints.GetBuffer(128),128,".\\CONFIG.INI");

        ::GetPrivateProfileString("JudgeResult",strSel,NULL,strResult.GetBuffer(128),128,strCurrentINI);

       //在选择答案的同时给出OK提示

        CString strListItem; strListItem.Format( " 判断题%d       OK!", iJudge );

m_List.DeleteString(iListSelPos ); m_List.InsertString(iListSelPos, strListItem );

       //将判断题序号所对应的答案以及与标准答案对比后的所得分写入Temp.ini文件

            if(iRedio == 1) strKey = "Y";  if(iRedio == 4) strKey = "N";

        if(strKey == strResult)

        ::WritePrivateProfileString("JudgeItemPoints",strSel,JudgeItemPoints,".\\Temp.ini");

        else ::WritePrivateProfileString("JudgeItemPoints",strSel,"0",".\\Temp.ini");   

           ::WritePrivateProfileString("JudgeResult",strSel,strKey,".\\Temp.ini");  return;

}

//处于多选题状态时所完成的有关功能如下

if(iMore != 0)

{ //从总表中获得小题的规定分数并从选中的那套题中获得该题的标准答案

         CString strItem;  CString strSelectItem;  CString strMoreItemPoints;

         strItem.Format("Item%d", iMore); strSelectItem.Format("SelectMoreItem%d", iMore);

             int ResultA = ::GetPrivateProfileInt(strSelectItem,"A",0,strCurrentINI);

             int ResultB = ::GetPrivateProfileInt(strSelectItem,"B",0,strCurrentINI);

             int ResultC = ::GetPrivateProfileInt(strSelectItem,"C",0,strCurrentINI);

             int ResultD = ::GetPrivateProfileInt(strSelectItem,"D",0,strCurrentINI);

       ::GetPrivateProfileString("CONFIG","SelectMorePoints",NULL,strMoreItemPoints.GetBuffer(128),128,".\\CONFIG.INI");

        CString str1 = "0";  CString str2 = "0";  CString str3 = "0";  CString str4 = "0";

        if(iRedio == 1)  //多选题中第1Redio单选按钮的单击响应功能

        { //先判断一下是否有答案,有则给出OK提示,否则取消OK标志

CString strList;

               if(iA==0 || iB!=0 || iC!=0 || iD!=0)

              {  strList.Format(" 多选题%d       OK!",iMore);      

                 m_List.DeleteString(iListSelPos); m_List.InsertString(iListSelPos,strList);

         }

              else

              {  strList.Format(" 多选题%d",iMore);    

                 m_List.DeleteString(iListSelPos); m_List.InsertString(iListSelPos,strList);

              }

//将多选题序号所对应的答案以及与标准答案对比后的所得分写入Temp.ini文件

              if(iA == 0) { RedioA->SetCheck(1); str1 = "1"; }

              if(iB == 1) { RedioB->SetCheck(1); str2 = "1"; }

              if(iC == 1) { RedioC->SetCheck(1); str3 = "1"; }

              if(iD == 1) { RedioD->SetCheck(1); str4 = "1"; }

            if(iA!=ResultA && iB==ResultB && iC==ResultC && iD==ResultD)

            ::WritePrivateProfileString("SelectMoreItemPoints",strItem,strMoreItemPoints,".\\Temp.ini");

            else ::WritePrivateProfileString("SelectMoreItemPoints",strItem,"0",".\\Temp.ini");

                ::WritePrivateProfileString(strSelectItem,"A",str1,".\\Temp.ini");

                ::WritePrivateProfileString(strSelectItem,"B",str2,".\\Temp.ini");     

                ::WritePrivateProfileString(strSelectItem,"C",str3,".\\Temp.ini");

                ::WritePrivateProfileString(strSelectItem,"D",str4,".\\Temp.ini");

          //设置第一个Redio单选按钮选中与取消功能

                 if(iA == 0) { RedioA->SetCheck(1); iA = 1; return; }

                 else { RedioA->SetCheck(0); iA = 0; return; }

        }

        if(iRedio == 2)  //多选题中第2Redio单选按钮的单击响应功能

        { //先判断一下是否有答案,有则给出OK提示,否则取消OK标志

CString strList;

               if(iA!=0 || iB==0 || iC!=0 || iD!=0)

              {  strList.Format(" 多选题%d       OK!",iMore);      

                 m_List.DeleteString(iListSelPos); m_List.InsertString(iListSelPos,strList);

         }

              else

              {  strList.Format(" 多选题%d",iMore);    

                 m_List.DeleteString(iListSelPos); m_List.InsertString(iListSelPos,strList);

              }

          //将多选题序号所对应的答案以及与标准答案对比后的所得分写入Temp.ini文件

               if(iA == 1) { RedioA->SetCheck(1); str1 = "1";}

               if(iB == 0) { RedioB->SetCheck(1); str2 = "1";}

               if(iC == 1) { RedioC->SetCheck(1); str3 = "1";}

               if(iD == 1) { RedioD->SetCheck(1); str4 = "1";}

            if(iA==ResultA && iB!=ResultB && iC==ResultC && iD==ResultD)

            ::WritePrivateProfileString("SelectMoreItemPoints",strItem,strMoreItemPoints,".\\Temp.ini");

            else ::WritePrivateProfileString("SelectMoreItemPoints",strItem,"0",".\\Temp.ini");     

                 ::WritePrivateProfileString(strSelectItem,"A",str1,".\\Temp.ini");

                 ::WritePrivateProfileString(strSelectItem,"B",str2,".\\Temp.ini");     

                 ::WritePrivateProfileString(strSelectItem,"C",str3,".\\Temp.ini");

                 ::WritePrivateProfileString(strSelectItem,"D",str4,".\\Temp.ini");

           //设置第二个Redio单选按钮选中与取消功能

                if(iB == 0) { RedioB->SetCheck(1); iB = 1; return; }

                else { RedioB->SetCheck(0); iB = 0; return; }

        }

        if(iRedio == 3)  //多选题中第3Redio单选按钮的单击响应功能

        {  //先判断一下是否有答案,有则给出OK提示,否则取消OK标志

CString strList;

              if(iA!=0 || iB!=0 || iC==0 || iD!=0)

              { strList.Format(" 多选题%d       OK!",iMore);   

                m_List.DeleteString(iListSelPos); m_List.InsertString(iListSelPos,strList);

         }

              else

              { strList.Format(" 多选题%d",iMore);     

                m_List.DeleteString(iListSelPos); m_List.InsertString(iListSelPos,strList);

              }

//将多选题序号所对应的答案以及与标准答案对比后的所得分写入Temp.ini文件

               if(iA == 1) { RedioA->SetCheck(1); str1 = "1";}

               if(iB == 1) { RedioB->SetCheck(1); str2 = "1";}

               if(iC == 0) { RedioC->SetCheck(1); str3 = "1";}

               if(iD == 1) { RedioD->SetCheck(1); str4 = "1";}

            if(iA==ResultA && iB==ResultB && iC!=ResultC && iD==ResultD)

            ::WritePrivateProfileString("SelectMoreItemPoints",strItem,strMoreItemPoints,".\\Temp.ini");

            else  ::WritePrivateProfileString("SelectMoreItemPoints",strItem,"0",".\\Temp.ini");

                    ::WritePrivateProfileString(strSelectItem,"A",str1,".\\Temp.ini");

                    ::WritePrivateProfileString(strSelectItem,"B",str2,".\\Temp.ini");     

                    ::WritePrivateProfileString(strSelectItem,"C",str3,".\\Temp.ini");

                    ::WritePrivateProfileString(strSelectItem,"D",str4,".\\Temp.ini");

          //设置第三个Redio单选按钮选中与取消功能

              if(iC==0) { RedioC->SetCheck(1); iC=1; return; }              

              else { RedioC->SetCheck(0); iC=0; return; }

         }

         if(iRedio == 4)  //多选题中第4Redio单选按钮的单击响应功能

         { //先判断一下是否有答案,有则给出OK提示,否则取消OK标志

CString strList;

               if(iA!=0 || iB!=0 || iC!=0 || iD==0)

              {  strList.Format(" 多选题%d       OK!",iMore);      

                 m_List.DeleteString(iListSelPos); m_List.InsertString(iListSelPos, strList);

         }

              else

              {  strList.Format(" 多选题%d", iMore);   

                 m_List.DeleteString(iListSelPos); m_List.InsertString(iListSelPos, strList);

              }

//将多选题序号所对应的答案以及与标准答案对比后的所得分数写入Temp.ini文件

             if(iA == 1) { RedioA->SetCheck(1); str1 = "1";}

             if(iB == 1) { RedioB->SetCheck(1); str2 = "1";}

             if(iC == 1) { RedioC->SetCheck(1); str3 = "1";}

             if(iD == 0) { RedioD->SetCheck(1); str4 = "1";}

           if(iA==ResultA && iB==ResultB && iC==ResultC && iD!=ResultD)

           ::WritePrivateProfileString("SelectMoreItemPoints",strItem,strMoreItemPoints,".\\Temp.ini");

           else ::WritePrivateProfileString("SelectMoreItemPoints", strItem, "0", ".\\Temp.ini");

                  ::WritePrivateProfileString(strSelectItem, "A", str1, ".\\Temp.ini");

                  ::WritePrivateProfileString(strSelectItem, "B", str2, ".\\Temp.ini");     

                  ::WritePrivateProfileString(strSelectItem, "C", str3, ".\\Temp.ini");

                  ::WritePrivateProfileString(strSelectItem, "D", str4, ".\\Temp.ini");

          //设置第四个Redio单选按钮的选中与取消功能

            if(iD == 0) { RedioD->SetCheck(1); iD = 1; return; }

            else { RedioD->SetCheck(0); iD = 0; return; }

        }

}

}

然后依次为四个Redio单选按钮添加单击响应函数,其中作好Redio按钮标记后,直接调用答案配置函数即可。具体代码如下:

     void CIEExamSysDlg::OnRadio1() { iRedio = 1 ; RedioConfig(); }

         void CIEExamSysDlg::OnRadio2() { iRedio = 2 ; RedioConfig(); }

         void CIEExamSysDlg::OnRadio3() { iRedio = 3 ; RedioConfig(); }

           void CIEExamSysDlg::OnRadio4() { iRedio = 4 ; RedioConfig(); }

第五步:在交卷结束考试按钮的单击响应函数中添加如下代码来结束网考。

       //这段代码主要是根Temp.ini中的记载将单选题、判断题、多选题各段分数汇总起来

              int tSingleCount=::GetPrivateProfileInt("CONFIG","SelectSingleCount",0,".\\CONFIG.INI");

              int tJudgeCount=::GetPrivateProfileInt("CONFIG","JudgeCount",0,".\\CONFIG.INI");

              int tMoreCount=::GetPrivateProfileInt("CONFIG","SelectMoreCount",0,".\\CONFIG.INI");

CString strCord; CString strAll; CString strSingle; CString strJudge; CString strMore;

int iSingeTotal=0; int  iJugeTotal=0; int iMoreTotal=0;

for(int i=0;i<=tSingleCount;i++)

{  strSingle.Format("Item%d",i);

           iSingeTotal=iSingeTotal+::GetPrivateProfileInt("SelectSingleItemPoints",strSingle,0,".\\Temp.ini");

}

for(int ii=0;ii<=tJudgeCount;ii++)

{  strJudge.Format("Item%d",ii);

                 iJugeTotal=iJugeTotal+::GetPrivateProfileInt("JudgeItemPoints",strJudge,0,".\\Temp.ini");

}

for(int iii=0;iii<=tMoreCount;iii++)

{  strMore.Format("Item%d",iii);

             iMoreTotal=iMoreTotal+::GetPrivateProfileInt("SelectMoreItemPoints",strMore,0,".\\Temp.ini");

}

//下面这段代码主要将总分与各段分数写入考号为文件名的INI文件中以便上传服务器

                strAll.Format("%d",iSingeTotal+iJugeTotal+iMoreTotal);

                strSingle.Format("%d",iSingeTotal);

                strJudge.Format("%d",iJugeTotal);

                strMore.Format("%d",iMoreTotal);

::GetPrivateProfileString("TestCord","TestCord",NULL,strCord.GetBuffer(128),128,".\\Temp.ini");

                  strCord.Format("%s.ini",strCord); strCord=".\\"+strCord;

::WritePrivateProfileString("TotalPoints","AllToalPoints",strAll,strCord);

::WritePrivateProfileString("TotalPoints","SingleToalPoints",strSingle,strCord);

::WritePrivateProfileString("TotalPoints","JudgeToalPoints",strJudge,strCord);

::WritePrivateProfileString("TotalPoints","MoreToalPoints",strMore,strCord);

//下面这段代码主要作为软件检测之用,检测时注意与当前选中那套题中的标准答案作比较

//观察是否是在标准答案中给规定分且答案变化后相应那段分数与总分是否会随着变化

                 CString strTest;  strTest = "总分:"+strAll+"\n";

strTest = strTest+"单选题分数:"+strSingle+"\n";

                                strTest = strTest+"判断题分数:"+strJudge+"\n";

                                strTest = strTest+"多选题分数:"+strMore;

                 AfxMessageBox(strTest);

          // 最后将考号为文件名的INI文件上传服务器(这部分略去)

最后由传统的网考监控系统从服务器中将所有考生成绩汇总在一起,从而结束网考机的全部考试功能。

 

四、结语

由于整个程序实现的关键是对INI文件的读写,所以特别要注意相关的三个函数GetPrivateProfileInt( )GetPrivateProfileString( )WritePrivateProfileString( )的用法,这在网考试卷制作机部分的第二步和第三步中带*号的注解中有详细的说明。在网考机这部分中特别要注意的是RedioConfig()函数,由于同时要对三种类型的答案进行识别和处理,再加上多选题类型还要允许多选与取消选中的功能,所以在阅读时要注意分段去理解,最后不要忘了对所有数据加密的安全性问题进行处理。

  推荐精品文章

·2024年9月目录 
·2024年8月目录 
·2024年7月目录 
·2024年6月目录 
·2024年5月目录 
·2024年4月目录 
·2024年3月目录 
·2024年2月目录 
·2024年1月目录
·2023年12月目录
·2023年11月目录
·2023年10月目录
·2023年9月目录 
·2023年8月目录 

  联系方式
TEL:010-82561037
Fax: 010-82561614
QQ: 100164630
Mail:gaojian@comprg.com.cn

  友情链接
 
Copyright 2001-2010, www.comprg.com.cn, All Rights Reserved
京ICP备14022230号-1,电话/传真:010-82561037 82561614 ,Mail:gaojian@comprg.com.cn
地址:北京市海淀区远大路20号宝蓝大厦E座704,邮编:100089