İnternet Programlama Dersi – 1 (Güz-2017) Hafta – 11
<html> <head> <meta charset="UTF-8"> <title></title> </head> <?php function getir($key) { if (isset($_POST[$key]) && strlen($_POST[$key])>0) return $_POST[$key]; return false; } $dolartl = ""; $altintl = ""; $miktar = ""; $sonuc = ""; if (count($_POST) == 5) { $dolartl = getir("dolartl"); $altintl = getir("altintl"); $miktar = getir("miktar"); $secim1 = getir("secim1"); $secim2 = getir("secim2"); if (!($dolartl && $altintl && $miktar && $secim1 && $secim2)) { $sonuc="veri girisi hatali"; } else { if($secim1!=$secim2) { include "kur.php"; $kur = new kur($dolartl,$altintl); $tip=$secim1.$secim2; $deger=$kur->donustur($tip,$miktar); $sonuc=$secim1."(".$miktar.")-->".$secim2."<br>"; $sonuc.="Sonuç:".$deger; } else $sonuc="secimler ayni!"; } } ?> <body> <form method="POST"> <table> <tr> <td>1$:</td> <td><input type="text" name="dolartl" value="<?php echo $dolartl; ?>">TL</td> </tr> <tr> <td>1gr Altın:</td> <td><input type="text" name="altintl" value="<?php echo $altintl; ?>">TL</td> </tr> <tr> <td colspan="2"><br></td> </tr> <tr> <td>Miktar:</td> <td><input type="text" name="miktar" value="<?php echo $miktar; ?>"></td> </tr> <tr> <td> Seçim-1: </td> <td> <input type="radio" name="secim1" value="tl" checked>TL <input type="radio" name="secim1" value="dolar">Dolar <input type="radio" name="secim1" value="altin">Altın </td> </tr> <tr> <td> Seçim-2: </td> <td> <input type="radio" name="secim2" value="tl" checked>TL <input type="radio" name="secim2" value="dolar">Dolar <input type="radio" name="secim2" value="altin">Altın </td> </tr> <?php if (strlen($sonuc) > 0) echo "<tr><td colspan='2' style='text-align: center; color: #ff6144;'>" . $sonuc . "</td></tr>"; ?> <tr> <td colspan="2" style="text-align: center"><input type="submit" value="Çevir"></td> </tr> </table> </form> </body> </html>
<?php /** * Created by PhpStorm. * User: caglar * Date: 06.12.2017 * Time: 20:37 */ class kur { public $dolartl; public $altintl; public function __construct($dolartl,$altintl) { $this->dolartl=$dolartl; $this->altintl=$altintl; } public function donustur($tip,$miktar) { switch ($tip) { case "tldolar": return $this->tl2dolar($miktar); case "tlaltin": return $this->tl2altin($miktar); case "dolartl": return $this->dolar2tl($miktar); case "altintl": return $this->altin2tl($miktar); case "dolaraltin": return $this->dolar2altin($miktar); case "altindolar": return $this->altin2dolar($miktar); default: return "Seçimler Uygun Değil!"; } } public function tl2dolar($miktar) { $sonuc=$miktar/$this->dolartl; return round($sonuc,2); } public function dolar2tl($miktar) { $sonuc=$miktar*$this->dolartl; return round($sonuc,2); } public function tl2altin($miktar) { $sonuc=$miktar/$this->altintl; return round($sonuc,2); } public function altin2tl($miktar) { $sonuc=$miktar*$this->altintl; return round($sonuc,2); } public function dolar2altin($miktar) { $tl=$this->dolar2tl($miktar); return $this->tl2altin($tl); } public function altin2dolar($miktar) { $tl=$this->altin2tl($miktar); return $this->tl2dolar($tl); } }