This commit is contained in:
a.pivkin 2025-07-14 06:14:06 +03:00
parent f7620b40f3
commit cebbf27b3a
11 changed files with 140 additions and 0 deletions

3
Lec18/figure/go.mod Normal file
View File

@ -0,0 +1,3 @@
module main.go
go 1.24.4

26
Lec18/figure/main.go Normal file
View File

@ -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())
}

3
Lec18/go.mod Normal file
View File

@ -0,0 +1,3 @@
module main.go
go 1.24.4

27
Lec18/main.go Normal file
View File

@ -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()
}

3
Lec19/go.mod Normal file
View File

@ -0,0 +1,3 @@
module main.go
go 1.24.4

37
Lec19/main.go Normal file
View File

@ -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)
}

9
Lec20/calculator.go Normal file
View File

@ -0,0 +1,9 @@
package main
func add(a,b int) int {
return a + b
}
func Sub(a,b int) int {
return a - b
}

3
Lec20/go.mod Normal file
View File

@ -0,0 +1,3 @@
module Lec20
go 1.24.4

15
Lec20/main.go Normal file
View File

@ -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())
}

View File

@ -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)
}

BIN
bin/Lec20 Executable file

Binary file not shown.