php计算多选题的分数,多选题评分算法 求指导

9c02dc82f15cec5b18c9d94f81b20b89.png

斯蒂芬大帝

PHP面向对象版

/**

* Created by: Singee77

*/

class Standard

{

//答对全部题所得总分

private $totalScore = 0;

//标准答案

private $standard = [];

//提交答案

private $answer = [];

//所得总分

private $getScore = 0;

public function __construct($totalScore)

{

$this->setTotalScore($totalScore);

}

/**

* @return int

*/

public function getTotalScore()

{

return $this->totalScore;

}

/**

* @param int $totalScore

*/

public function setTotalScore($totalScore)

{

$this->totalScore = $totalScore;

}

/**

* @param array $standard

*/

public function setStandard($standard)

{

$this->standard = $standard;

}

/**

* @return array

*/

public function getStandard()

{

return $this->standard;

}

/**

* @param $answer

*/

public function checkStandard()

{

foreach ($this->answer as $each) {

if (!$weight = $this->checkAnswer($each)) {

//选错一个总分为0

$this->setGetScore(0);

break;

}

//答对一个就追加分数

$this->appendGetScore($this->getTotalScore() * $weight);

}

}

/**

* @param array $answer

*/

public function setAnswer($answer)

{

$this->answer = $answer;

}

/**

* @return array

*/

public function getAnswer()

{

return $this->answer;

}

/**

* @param $each

* return $weight

*/

private function checkAnswer($each)

{

return array_key_exists($each, $this->standard) ? $this->standard[$each] : 0;

}

/**

* @param int $getScore

*/

public function setGetScore($score)

{

$this->getScore = $score;

}

/**

* @return int

*/

public function getGetScore()

{

return $this->getScore;

}

/**

* @param int $totalScore

*/

public function appendGetScore($appendScore)

{

$this->getScore += $appendScore;

}

}

//实例一个CHECK对象并设置总分

$std = new Standard(10);

//设置标准答案以及占比

$std->setStandard(['A' => 0.2, 'B' => 0.4, 'C' => 0.4]);

//设置答案

$std->setAnswer(['A', 'B']);

//计算分数

$std->checkStandard();

//获取所得总分

$totalScore = $std->getTotalScore();

echo $totalScore;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值