Un cours pour se lancer dans la programmation avec le langage Go (golang).
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

92 Zeilen
1.8 KiB

  1. /* Copyright (C) 2011-2023 Patrick H. E. Foubet - E2L Ivry
  2. Ecole du Logiciel Libre : https://e2li.org/
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or any
  6. later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>
  13. *******************************************************************/
  14. package main
  15. import (
  16. "fmt"
  17. "math"
  18. )
  19. type Wheel struct {
  20. Circle
  21. Material string
  22. Color string
  23. X float64
  24. }
  25. func (w Wheel) Info() {
  26. fmt.Printf("Une roue est faite en %s de couleur %s\n", w.Material, w.Color)
  27. }
  28. type Circle struct {
  29. X float64
  30. Y float64
  31. Radius float64
  32. }
  33. type Shape interface {
  34. Area() float64
  35. Area2() float64
  36. }
  37. func (c *Circle) Area() float64 {
  38. return c.Radius * c.Radius * math.Pi
  39. }
  40. func (c Circle) Area2() float64 {
  41. return c.Radius * c.Radius * math.Pi
  42. }
  43. func Area(c Circle) float64 {
  44. return c.Radius * c.Radius * math.Pi
  45. }
  46. func ShapeArea(s Shape) float64 {
  47. return s.Area()
  48. }
  49. func main() {
  50. c1 := Circle{
  51. X: 15.0,
  52. Y: 12.0,
  53. Radius: 8.5,
  54. }
  55. c2 := Circle{15.0, 12, 8.5}
  56. fmt.Println(c1 == c2)
  57. fmt.Println(c1.Area() == c1.Area2())
  58. w1 := Wheel{
  59. Circle: Circle{
  60. Radius: 10.0,
  61. X: 15.0,
  62. },
  63. Material: "Caoutchouc",
  64. Color: "Noire",
  65. X: 5.0,
  66. }
  67. w1.Info()
  68. fmt.Println(w1.Area())
  69. fmt.Println(w1.X)
  70. fmt.Println(w1.Circle.X)
  71. }