Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4. import "math"
  5.  
  6. type Gemetric interface {
  7. area() float64
  8. perim() float64
  9. }
  10.  
  11. type rect struct {
  12. width, height float64
  13. }
  14.  
  15. type circle struct {
  16. radius float64
  17. }
  18.  
  19. func (r rect) area() float64 {
  20. return r.width * r.height
  21. }
  22.  
  23. func (r rect) perim() float64 {
  24. return 2*r.width + 2*r.height
  25. }
  26.  
  27. func (c circle) area() float64 {
  28. return math.Pi * c.radius * c.radius
  29. }
  30.  
  31. func (c circle) perim() float64 {
  32. return 2 * math.Pi * c.radius
  33. }
  34.  
  35. func measure(g geometry) {
  36. fmt.Println(g)
  37. fmt.Println(g.area())
  38. fmt.Println(g.perim())
  39. }
  40.  
  41. func main() {
  42. r := rect{width: 3, height: 4}
  43. c := circle{radius: 5}
  44.  
  45. measure(r)
  46. measure(c)
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement