Guest User

Untitled

a guest
Aug 26th, 2019
757
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.86 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "math"
  6. )
  7.  
  8. type Shape interface {
  9.     area() float64
  10.     perimeter() float64
  11. }
  12.  
  13. type Circle struct {
  14.     radius float64
  15.     //Shape
  16. }
  17.  
  18. type Rectangle struct {
  19.     width, height float64
  20.     //Shape
  21. }
  22.  
  23. func (rectangle *Rectangle) area() float64 {
  24.     return rectangle.width * rectangle.height
  25. }
  26.  
  27. func (rectangle *Rectangle) perimeter() float64 {
  28.     return 2 * (rectangle.width + rectangle.height)
  29. }
  30.  
  31. func (circle *Circle) area() float64 {
  32.     return math.Pi * math.Pow(circle.radius, 2)
  33. }
  34.  
  35. func (circle *Circle) perimeter() float64 {
  36.     return 2 * math.Pi * circle.radius
  37. }
  38.  
  39. func main() {
  40.     c := Circle{radius: 23}
  41.     r := Rectangle{height: 11, width: 77.05}
  42.     fmt.Printf("Circle's area is \t%f\nand perimeter is \t%f\n", c.area(), c.perimeter())
  43.     fmt.Printf("Rectangle's area is \t%f\nand perimeter is \t%f\n", r.area(), r.perimeter())
  44. }
Advertisement
Add Comment
Please, Sign In to add comment