diff --git a/Lec18/figure/go.mod b/Lec18/figure/go.mod new file mode 100644 index 0000000..a692304 --- /dev/null +++ b/Lec18/figure/go.mod @@ -0,0 +1,3 @@ +module main.go + +go 1.24.4 diff --git a/Lec18/figure/main.go b/Lec18/figure/main.go new file mode 100644 index 0000000..2909470 --- /dev/null +++ b/Lec18/figure/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "math" +) + +type Cicle struct { + radius int +} + +type Rectangle struct { + lenght,width int +} + +func (circle Cicle) Perim() float64 { + return float64(circle.radius) * math.Pi +} + + +func main() { + c := Cicle{ + radius: 3, + } + fmt.Println(c.Perim()) +} \ No newline at end of file diff --git a/Lec18/go.mod b/Lec18/go.mod new file mode 100644 index 0000000..a692304 --- /dev/null +++ b/Lec18/go.mod @@ -0,0 +1,3 @@ +module main.go + +go 1.24.4 diff --git a/Lec18/main.go b/Lec18/main.go new file mode 100644 index 0000000..bc38e76 --- /dev/null +++ b/Lec18/main.go @@ -0,0 +1,27 @@ +package main + +import "fmt" + + +type Employee struct { + name string + position string + salary int + currency string +} + +func (e Employee) DisplayInfo() { + fmt.Println("Name: ", e.name) + fmt.Println("Position: ",e.position) + fmt.Printf("Salary: %d %s\n",e.salary,e.currency) +} + +func main(){ + emp := Employee { + name: "Bob", + position: "senior", + salary: 10000, + currency: "RUB", + } + emp.DisplayInfo() +} diff --git a/Lec19/go.mod b/Lec19/go.mod new file mode 100644 index 0000000..a692304 --- /dev/null +++ b/Lec19/go.mod @@ -0,0 +1,3 @@ +module main.go + +go 1.24.4 diff --git a/Lec19/main.go b/Lec19/main.go new file mode 100644 index 0000000..18a0885 --- /dev/null +++ b/Lec19/main.go @@ -0,0 +1,37 @@ +package main + +import "fmt" + +type Student struct { + name string + age int +} + +type Desriber interface { + Describe() +} + + +func (std Student) Describe(){ + fmt.Printf("%s and %d y.o",std.name,std.age) +} + +func TypeDescriber(i interface{}){ + switch v := i.(type){ + case string: + fmt.Println("I am string") + case int: + fmt.Println("I am int") + case Desriber: + fmt.Println("I am describer!") + v.Describe() + default: + fmt.Println("Unknown type but I still work!") + } +} + +func main() { + TypeDescriber(9) + std := Student{"Alex", 19} + TypeDescriber(std) +} diff --git a/Lec20/calculator.go b/Lec20/calculator.go new file mode 100644 index 0000000..c52e552 --- /dev/null +++ b/Lec20/calculator.go @@ -0,0 +1,9 @@ +package main + +func add(a,b int) int { + return a + b +} + +func Sub(a,b int) int { + return a - b +} diff --git a/Lec20/go.mod b/Lec20/go.mod new file mode 100644 index 0000000..3bdfff5 --- /dev/null +++ b/Lec20/go.mod @@ -0,0 +1,3 @@ +module Lec20 + +go 1.24.4 diff --git a/Lec20/main.go b/Lec20/main.go new file mode 100644 index 0000000..e44c82a --- /dev/null +++ b/Lec20/main.go @@ -0,0 +1,15 @@ +package main + +import ( + "fmt" + "Lec20/rectangle" +) + +func main() { + // res := add(2,5) + // fmt.Println("Addition equals to ",res) + + r := rectangle.New(10,20,"green") + fmt.Println("Perimeter: ",r.Perimeter()) +} + diff --git a/Lec20/rectangle/rectangle.go b/Lec20/rectangle/rectangle.go new file mode 100644 index 0000000..da9e6e8 --- /dev/null +++ b/Lec20/rectangle/rectangle.go @@ -0,0 +1,14 @@ +package rectangle + +type Rect struct { + A,B int + color string +} + +func New(newA int, newB int, newColor string) *Rect { + return &Rect{newA,newB,newColor} +} + +func (r *Rect) Perimeter() int { + return 2 * (r.A + r.B) +} \ No newline at end of file diff --git a/bin/Lec20 b/bin/Lec20 new file mode 100755 index 0000000..fa4a65d Binary files /dev/null and b/bin/Lec20 differ