Created
June 29, 2014 17:45
-
-
Save bolilla/1cb438627984cf08f533 to your computer and use it in GitHub Desktop.
GoPadawan OO Ejemplo Clásico Modificación
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type rectángulo struct { | |
lado1, lado2 float32 | |
} | |
func (r rectángulo) área() float32 { | |
return r.lado1 * r.lado2 | |
} | |
func (r rectángulo) perímetro() float32 { | |
return (2 * r.lado1) + (2 * r.lado2) | |
} | |
func (r *rectángulo) agrandar() { | |
r.lado1 = 2 * r.lado1 | |
r.lado2 = 2 * r.lado2 | |
} | |
func main() { | |
var miRectángulito rectángulo = rectángulo{3.0, 4.0} | |
fmt.Println("Este es mi rectángulo", miRectángulito) | |
fmt.Println("Su área es", miRectángulito.área()) | |
fmt.Println("Su perímetro es", miRectángulito.perímetro()) | |
miRectángulito.agrandar() | |
fmt.Println("\nAgrando mi rectángulo\n") | |
fmt.Println("Este es mi rectángulo agrandado", miRectángulito) | |
fmt.Println("Su área es", miRectángulito.área()) | |
fmt.Println("Su perímetro es", miRectángulito.perímetro()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment