OOP PHP: Klasifikasikan Markah kepada Gred

7:37 PTG 0 Comments A+ a-




/**
 * Mari Belajar PHP
 * @copyright (c) 2012, Encraptor Inc. All Right Reserved
 * @author  Encraptor@gmail.com

 * @link http://encraption.blogspot.com
 * @version 2.7
 * @desc Class untuk mengklasifikasikan gred daripada markah yg diterima.
 * Fail: kelas_grade.php
 */

class KiraGred
{

    public   $markah;
    private  $kelas_markah;

//Function yang menerima markah, dan memproses markah tersebut kepada
//gred yang telah ditetapkan. .

    function terimaGred($int)
    {
        $this->markah= (int) $int;

         if ($this->markah <= 100 && $this->markah  >= 80)
                {
                $this->kelas_markah='MUMTAZ';
                }
            elseif ($this->markah <= 79 && $this->markah  >=65)
                {
                  $this->kelas_markah='JAYYID JIDDAN';
                }
            elseif ($this->markah <=64  && $this->markah  >= 50)
                {
               $this->kelas_markah='JAYYID';

                }
            elseif ($this->markah <= 49 && $this->markah  >= 40)
                {
                $this->kelas_markah='MAQBUL';

                }
            elseif ($this->markah <= 39 && $this->markah  >= 25)
                {
               $this->kelas_markah='DHAIF';

                }
            elseif ($this->markah <= 24 && $this->markah  >= 01)
                {
                $this->kelas_markah='DHAIF JIDDAN';

                }
            elseif ($this->markah = 0 )
                {
                $this->kelas_markah='TIDAK HADIR';

                }
            else
                {
                $this->kelas_markah='SILA SEMAK KEMASUKAN MARKAH ANDA!';
                }
    }




// Function untk menghantar value Gred yang telah diproses
// daripada function terimaGred.

    function keluarKeputusanGred()
    {
      return $this->kelas_markah;
    }


}

$kira=new KiraGred();

// Hantar markah 65 ke function terimaGred untuk diproses.
$kira->terimaGred(65);

// terima keputusan gred yang dihantar dan display terus result.
echo $kira->keluarKeputusanGred();

// echo $kira->kelas_Markah;  //Saje nak test leh hijack ke tak $kelas_Markah
                              // yang telah di private.