ORTALAMA HESAPLAMA

ORTALAMA HESAPLA DEMOSU

<?php 
class Ortalama{
	
function getir($key)
{
	if(isset($_POST[$key]))
		return $_POST[$key];
	  else
		  return "";
}	
function kontrolet($dsayisi,$key)
{   for($i=1;$i<=$dsayisi;$i++)
	 {   $deger=$this->getir($key.$i);
		 if($deger=="" || !(is_numeric($deger)))
			 return false; 
	 }
   return true;
	 }
	 function hdeger($harfd)
	 {  $veri=explode("-",$this->getir($harfd));
	    return (float)$veri[0]; 
	 }
	  function hharf($harfd)
	 {  $veri=explode("-",$this->getir($harfd));
	    return $veri[1]; 
	 }
function hesapla($dsayisi,$harfd,$krd)
{
	$toplam=0;
	$krdtoplam=0;
	for($i=1;$i<=$dsayisi;$i++)
	{    $krdsayisi=$this->getir($krd.$i);
		   $deger=$this->hdeger($harfd.$i);
		$toplam+=$deger*$krdsayisi;
		$krdtoplam+=$krdsayisi;
	}
return $toplam/$krdtoplam;
	}

	}
	
$ort=new Ortalama();
$dsayisi=$ort->getir("dsayisi");
$sayim=$ort->getir("sayi");
if($sayim!=""&&is_numeric($sayim)&&$ort->kontrolet($sayim,"krd"))
{ $ortalama=$ort->hesapla($sayim,"harfdeg","krd");
$ortalama*=100;
$ortalama=(int)$ortalama;
$ortalama/=100;
?>
<table  style="text-align:center" border="1">
<tr><td>DERSİN ADI</td><td>KREDİ SAYISI</td><td>HARF VE DEĞERİ</td><tr>
<?php 

for($i=1;$i<=$sayim;$i++)
    {   
?>
<tr>
<td><?php echo $ort->getir("ort".$i); ?></td>
<td><?php echo $ort->getir("krd".$i); ?></td>
<td><?php $sonuc=$ort->hharf("harfdeg".$i); echo $sonuc; ?></td>
</tr>      
	<?php }?>
	<tr><td >ORTALAMA:</td><td colspan="2"><?php echo $ortalama; ?></td></tr>
</table>
<?php 
} 
else{	
if($dsayisi!=""&&$dsayisi<=20 &&is_numeric($dsayisi)&&$ort->kontrolet(9,"tharf"))
 {  
?>
<form method="post" action="">
<table  style="text-align:center" style="align:center">
<tr><td colspan="3">DERS SAYISI:<input type="text" name="sayi" id="sayi" value="<?php echo $dsayisi; ?>" readonly="true" /></td></tr>
<tr><td>DERSİN ADI</td><td>KREDİ SAYISI</td><td>HARF </td><tr>
<?php 
//ekrana kactane ders varsa o kadar text olusturuyor
$harfler=["AA","BA","BB","CB","CC","DC","DD","FD","FF"]; 
for($i=1;$i<=$dsayisi;$i++)
    {   
?>
<tr><td><input type="text" placeholder="Ders Adı Giriniz" value="" name="<?php echo "ort".$i; ?>" /></td><td><input type="text" placeholder="Kredi sayısını Giriniz.."value="" name="<?php echo "krd".$i; ?>" required/></td><td>    
<select  name="<?php echo "harfdeg".$i; ?>" id="<?php echo "harfdeg".$i; ?>">
                                        <?php 
										$say=1;
										foreach($harfler as $deger)
										{
										?>
                                         <option  value="<?php echo $ort->getir("tharf".$say)."-".$deger;?>"><?php echo $deger; ?></option> 
	                                 <?php $say++; }?>										   
                                       </select>   </td></tr>
<?php 
    }
?>
<tr><td colspan="3"><input type="submit" value="Hesapla"/></td></tr>
</table>
</form>
 <?php 
 }
 else
 {
 ?>
 <form method="post" action="" >
 <table border="1">
 <?php
$kars=["AA"=>4,"BA"=>3.50,"BB"=>3,"CB"=>2.50,"CC"=>2.25,"DC"=>1.75,"DD"=>1.25,"FD"=>0.75,"FF"=>0]; 
 $sayac=1;
foreach($kars as $key=>$deger)
{
?>
<tr>
<td>
<?php echo $key; ?>:
</td>
<td>
<input type="text" value="<?php echo $deger;?>" name="<?php echo "tharf".($sayac); ?>" id="<?php echo "tharf".($sayac++); ?>" required/>
</td>
</tr>
<?php 
}
?>
<tr>
<td>Ders Sayısı:</td><td><input type="text" value="" name="dsayisi" id="dsayisi"  required/></td>
</tr>
<tr>
<td colspan="2" style="text-align:center"><input type="submit" value="Başla"/></td>
</tr>
</table>
</form>
 <?php }
}
 ?>

 

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir