added orai
This commit is contained in:
41
20241118/obj.php
Normal file
41
20241118/obj.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
//objektumok használata
|
||||
|
||||
class Tanulo{
|
||||
public $nev;
|
||||
public $kor;
|
||||
public $jegyek = array();
|
||||
|
||||
public function __construct($nev, $kor){
|
||||
$this->kor = $kor;
|
||||
$this->nev = $nev;
|
||||
}
|
||||
|
||||
public function adjegy($jegy){
|
||||
$this->jegyek[] = $jegy;
|
||||
}
|
||||
|
||||
public function atlagkiszamit(){
|
||||
if (count($this->jegyek) == 0){
|
||||
return 0;
|
||||
} else{
|
||||
return array_sum($this->jegyek) / count($this->jegyek);
|
||||
}
|
||||
}
|
||||
|
||||
public function adatkiir(){
|
||||
$atlag = $this->atlagkiszamit();
|
||||
echo "Név: {$this->nev},\nKor: {$this->kor}, Átlag:"
|
||||
.number_format($atlag, 2);
|
||||
}
|
||||
}
|
||||
|
||||
$digi = new Tanulo("Szabó Márton", 19);
|
||||
$digi->adjegy(5);
|
||||
$digi->adjegy(2);
|
||||
$digi->adjegy(4);
|
||||
$digi->adjegy(5);
|
||||
$digi->adatkiir();
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user