Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "math"
- )
- type Shape interface {
- area() float64
- perimeter() float64
- }
- type Circle struct {
- radius float64
- //Shape
- }
- type Rectangle struct {
- width, height float64
- //Shape
- }
- func (rectangle *Rectangle) area() float64 {
- return rectangle.width * rectangle.height
- }
- func (rectangle *Rectangle) perimeter() float64 {
- return 2 * (rectangle.width + rectangle.height)
- }
- func (circle *Circle) area() float64 {
- return math.Pi * math.Pow(circle.radius, 2)
- }
- func (circle *Circle) perimeter() float64 {
- return 2 * math.Pi * circle.radius
- }
- func main() {
- c := Circle{radius: 23}
- r := Rectangle{height: 11, width: 77.05}
- fmt.Printf("Circle's area is \t%f\nand perimeter is \t%f\n", c.area(), c.perimeter())
- fmt.Printf("Rectangle's area is \t%f\nand perimeter is \t%f\n", r.area(), r.perimeter())
- }
Advertisement
Add Comment
Please, Sign In to add comment