Un cours pour se lancer dans la programmation avec le langage Go (golang).
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

pirms 1 gada
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package main
  2. import (
  3. "fmt"
  4. "math"
  5. )
  6. type Wheel struct {
  7. Circle
  8. Material string
  9. Color string
  10. X float64
  11. }
  12. func (w Wheel) Info() {
  13. fmt.Printf("Une roue est faite en %s de couleur %s\n", w.Material, w.Color)
  14. }
  15. type Circle struct {
  16. X float64
  17. Y float64
  18. Radius float64
  19. }
  20. type Shape interface {
  21. Area() float64
  22. Area2() float64
  23. }
  24. func (c *Circle) Area() float64 {
  25. return c.Radius * c.Radius * math.Pi
  26. }
  27. func (c Circle) Area2() float64 {
  28. return c.Radius * c.Radius * math.Pi
  29. }
  30. func Area(c Circle) float64 {
  31. return c.Radius * c.Radius * math.Pi
  32. }
  33. func ShapeArea(s Shape) float64 {
  34. return s.Area()
  35. }
  36. func main() {
  37. c1 := Circle{
  38. X: 15.0,
  39. Y: 12.0,
  40. Radius: 8.5,
  41. }
  42. c2 := Circle{15.0, 12, 8.5}
  43. fmt.Println(c1 == c2)
  44. fmt.Println(c1.Area() == c1.Area2())
  45. w1 := Wheel{
  46. Circle: Circle{
  47. Radius: 10.0,
  48. X: 15.0,
  49. },
  50. Material: "Caoutchouc",
  51. Color: "Noire",
  52. X: 5.0,
  53. }
  54. w1.Info()
  55. fmt.Println(w1.Area())
  56. fmt.Println(w1.X)
  57. fmt.Println(w1.Circle.X)
  58. }