php
<?php
class Student {
public $name;
public $grades = array();
public function addGrade($grade) {
$this->grades[] = $grade;
}
public function getAverageGrade() {
$total = array_sum($this->grades);
$count = count($this->grades);
return $total / $count;
}
}
$student1 = new Student();
$student1->name = 'Alice';
$student1->addGrade(85);
$student1->addGrade(92);
echo $student1->name . '的平均成绩是:' . $student1->getAverageGrade();
?>
顶一下
(0)
0%
踩一下
(0)
0%
- 相关评论
- 我要评论
-