lkejfl
This commit is contained in:
parent
f7620b40f3
commit
cebbf27b3a
3
Lec18/figure/go.mod
Normal file
3
Lec18/figure/go.mod
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
module main.go
|
||||
|
||||
go 1.24.4
|
||||
26
Lec18/figure/main.go
Normal file
26
Lec18/figure/main.go
Normal 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
3
Lec18/go.mod
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
module main.go
|
||||
|
||||
go 1.24.4
|
||||
27
Lec18/main.go
Normal file
27
Lec18/main.go
Normal 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
3
Lec19/go.mod
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
module main.go
|
||||
|
||||
go 1.24.4
|
||||
37
Lec19/main.go
Normal file
37
Lec19/main.go
Normal 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
9
Lec20/calculator.go
Normal 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
3
Lec20/go.mod
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
module Lec20
|
||||
|
||||
go 1.24.4
|
||||
15
Lec20/main.go
Normal file
15
Lec20/main.go
Normal 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())
|
||||
}
|
||||
|
||||
14
Lec20/rectangle/rectangle.go
Normal file
14
Lec20/rectangle/rectangle.go
Normal 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)
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user