Temperature Converter Object
PHP
Medium
7 views
Problem Description
Make a Temperature class with setC(c) and getF(). Input c, print Fahrenheit with 2 decimals.
Input Format
One number c.
Output Format
One number f.
Official Solution
<?php
class Temperature{
private $c=0.0;
function setC($c){ $this->c=$c; }
function getF(){ return $this->c*9/5+32; }
}
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
$t=new Temperature();
$t->setC(floatval($inputText));
echo number_format($t->getF(),2,'.','');
?>
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!