<?php
    /* 
    Fichier qui définit des chose mais ne fait rien, 
    au sens informatique ceci peut être considéré comme un librairie
    */
    abstract class forme
    {
        abstract function surface();
        abstract function perimetre();
        function type() 
        {
            return ucfirst(get_class($this));
        }
    }

    class cercle extends forme 
    {
        private $rayon;

        function __construct($rayon)
        {
            $this->rayon = $rayon;
        }
    
        function surface() 
        {
            return M_PI * $this->rayon * $this->rayon;
        }

        function perimetre()
        {
            return M_PI * $this->rayon * 2;
        }
    }

    class rectangle extends forme 
    {
        protected $longeur;
        protected $largeur;

        function __construct($longeur, $largeur)
        {
            $this->longeur = $longeur;
            $this->largeur = $largeur;
        }
    
        function surface() 
        {
            return $this->longeur * $this->largeur;
        }

        function perimetre()
        {
            return 2 * $this->longeur + 2 * $this->largeur;
        }
    }

    class carre extends rectangle 
    {
        function __construct($cote)
        {
            $this->longeur = $cote;
            $this->largeur = $cote;
        }

        function type()
        {
            return "Carré";
        }        
    }

    class triangle_rectangle extends forme 
    {
        protected $hauteur;
        protected $base;

        function __construct($h, $b)
        {
            $this->hauteur = $h;
            $this->base = $b;
        }
    
        function hypothenuse()
        {
            return sqrt($this->hauteur*$this->hauteur + $this->base*$this->base);
        }

        function surface() 
        {
            return ($this->hauteur * $this->base) / 2; 
        }

        function perimetre()
        {
            return $this->hauteur + $this->base + $this->hypothenuse();
        }

        function type()
        {
            return "Triangle Rectangle";
        }
    }