本文主要是介绍练习题多选题程序,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
#include<iostream>
using namespace std;
#define QUESTION_MAX (100) // 最多100道题
static QustionItem_t Qustion[QUESTION_MAX];
static int JudgeMethod = 0;
static int ScoreMethod = 0;
int main()
{
int num = 0; //题目总数
float perTotalScore = 0; //每题分数
float totalScore = 0; //最后得分
QustionItem_t *Paper = Question; //为每道题占的内存申请空间
int* pJudgeMethod = &JudgeMethod;
int* pScoreMethod = &ScoreMethod;
int i = 0; //??
num = GetQuestionNum();//得到题目总数
GetPaperAndAnswer(Paper);
GetMehod(pJudgeMethod, pScoreMethod);
for (int i = 0; i < num; i++) {
GetPerQuestionScore(i, num, Paper, pScoreMethod, &perTotalScore);
CheckOneQuestion(i, Paper, &perTotalScore, pJudgeMethod, &totalScore);
}
OutPutResult(score);
return 0;
}
void CheckOneQuestion(int i, QuestionItem_t *Paper,
float *perTotalScore, int *pJudgeMethod, float *totalScore)
{
int choiceNum = 0;
int ansNum = 0;
int rightNum = 0;
//该题正确答案字符数
for (int j = 0; j < 10; j++) {
if ('\0' != Paper[i].Answer[j]) {
ansNum++;
} else {
break;
}
}
//考生选定选项字符数
for (int j = 0; j < 10; j++) {
if ('\0' != Paper[i].Choice[j]) {
choiceNum++;
} else {
break;
}
}
//得到当前题目考生选项中正确的个数
for (int j = 0; j < choiceNum; j++) {
for (int k = 0; k < ansNum; k++) {
if (Paper[i].Answer[k] == Paper[i].Choice[j]) {
//正确数+1
rightNum++;
}
else {
rightNum += 0; //?
}
}
}
if (1 == *pJudgeMethod) {
//答案全正确加分
//多选少选都不得分
if (choiceNum == ansNum && ansNum == rightNum) {
*totalScore += *perTotalScore;
}
else {
*totalScore += 0; //??
}
}
else if (2 == *pJudgeMethod) {
//多选不得分
if(choiceNum > ansNum){
*totalScore += 0;
}
//选项正确得分
else if (choiceNum == ansNum && rightNum == ansNum) {
*totalScore += *perTotalScore;
}
//其他得部分分数
else {
*totalScore += *perTotalScore * rightNum / ansNum;
}
}
else if (3 == *pJudgeMethod) {
int wrongNum = choiceNum - rightNum;
//全部正确得本题满分
if (choiceNum == ansNum && rightNum == ansNum) {
*totalScore += *perTotalScore;
}
//少选按正确数给分
else if (choiceNum < ansNum) {
*totalScore += *perTotalScore * rightNum / ansNum;
}
//多选则扣除错误数分数再加上正确分数
else {
float score = *perTotalScore - (*perTotalScore * wrongNum / ansNum);
score += *perTotalScore * rightNum / ansNum;
*totalScore += score < 0 ? 0 : score;
}
}
}
int GetPerQuestionScore(int i,
int num, QuestionItem_t* Paper, int* pScoreMethod,
float* perTotalScore)
{
if (1 == *pScoreMethod) {
*perTotalScore = 100.0f / num;
}else if (2 == *pScoreMethod) {
*perTotalScore = getScoreMethod2(i, Paper, num);
}else if(3 == *pScoreMethod) {
*perTotalScore = Paper[i].Score;
}
}
//当分配方式为第二种时,获得该题号总分
float getScoreMethod2(int i, QuestionItem_t* Paper, int num)
{
int allAnsNum = 0;
int currentAnsNum = 0;
//获得所有题答案选项数
for (int j = 0; j < num; j++) {
for (int k = 0; k < 10; k++) {
if ('\0' != Paper[j].Answer[k]) {
allAnsNum++;
}
else {
break;
}
}
}
//获得当前题目答案选项数
for (int j = 0; j < 10; j++) {
if('\0' != Paper[i].Answer[j]) {
currentAnsNum++;
}else {
break;
}
}
return 100.0f * currentAnsNum / allAnsNum;
}
这篇关于练习题多选题程序的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!