Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.78 KB | None | 0 0
  1. <html>
  2. <body>
  3. </php
  4.  
  5. abstract class Shape {
  6.  
  7. private $x=0;
  8. private $y=0;
  9. private $z=0;
  10.  
  11. public abstract function volume(){
  12. }
  13.  
  14. }
  15. class rectangular extends shape {
  16.  
  17. function __construct ($x,$y,$z){
  18. $this->x= $x;
  19. $this->y= $y;
  20. $this->z= $z;
  21. }
  22. function volume(){
  23. volume=$this->x*$this->y*$this->z;
  24. return volume;
  25. }
  26. }
  27. class cube extends shape {
  28.  
  29. function __construct ($x){
  30. $this->x= $x;
  31. }
  32. function volume(){
  33. volume=$this->x*$this->x*$this->x;
  34. return volume;
  35. }
  36. }
  37. class sphere extends shape {
  38.  
  39. function __construct($x){
  40. $this->x= $x;
  41. }
  42. function volume(){
  43. volume=4/3*pi()*$this->x*$this->x*$this->x;
  44. return volume;
  45. }
  46. }
  47. $shape =array(
  48. new rectangular(3,5,6),
  49. new cube(4),
  50. new sphere(8)
  51. );
  52.  
  53. foreach ($shape as $shape1){
  54. echo $shape1-> volume(). "\n";
  55. }
  56.  
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement