Rectangle Class

Rectangle Class

Easy PHP PHP OOP Basics 36 views
Explanation Complexity

Problem Statement

Create a Rectangle class with width and height. Print area and perimeter.

Input Format

One line: w h.

Output Format

Two integers: area perimeter.

Example

3 5
15 16

Constraints

0

Input / Output Format

Input Format
One line: w h.
Output Format
Two integers: area perimeter.
Constraints
0

Examples

Input:
3 5
Output:
15 16

Example Solution (Public)

PHP
<?php
class Rectangle{
  public $w; public $h;
  function __construct($w,$h){ $this->w=$w; $this->h=$h; }
  function area(){ return $this->w*$this->h; }
  function perim(){ return 2*($this->w+$this->h); }
}
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
[$w,$h]=array_map('intval',preg_split('/\\s+/', $inputText));
$r=new Rectangle($w,$h);
echo $r->area().' '.$r->perim();
?>

Official Solution Code

<?php
class Rectangle{
  public $w; public $h;
  function __construct($w,$h){ $this->w=$w; $this->h=$h; }
  function area(){ return $this->w*$this->h; }
  function perim(){ return 2*($this->w+$this->h); }
}
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
[$w,$h]=array_map('intval',preg_split('/\\s+/', $inputText));
$r=new Rectangle($w,$h);
echo $r->area().' '.$r->perim();
?>
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.