diff --git a/golang/go.mod b/golang/go.mod index d1cc943c..5cecc1f3 100644 --- a/golang/go.mod +++ b/golang/go.mod @@ -1,5 +1,3 @@ module isuct.ru/informatics2022 go 1.16 - -require github.com/stretchr/testify v1.8.1 diff --git a/golang/go.sum b/golang/go.sum index 2ec90f70..d3f5a12f 100644 --- a/golang/go.sum +++ b/golang/go.sum @@ -1,17 +1 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= + diff --git a/golang/lab4/lab4.go b/golang/lab4/lab4.go new file mode 100644 index 00000000..32a83676 --- /dev/null +++ b/golang/lab4/lab4.go @@ -0,0 +1,30 @@ +package lab4 + +import ( + "fmt" + "math" +) + +func lab4(a, x float64) float64 { + return (math.Pow(a, math.Pow(x, 2)-1) - math.Log10(math.Pow(x, 2)-1) + math.Cbrt(math.Pow(x, 2)-1)) +} +func lab4A(imin float64, imax float64, razn float64, a float64) []float64 { + var result []float64 + for i := imin; i < imax; i += razn { + result = append(result, lab4(a, i)) + } + return (result) +} +func lab4B(x []float64, a float64) []float64 { + var result []float64 + for _, value := range x { + result = append(result, lab4(a, value)) + } + return (result) +} +func Lab4AB() { + var a float64 = 1.6 + var x = []float64{1.28, 1.36, 2.47, 3.68, 4.56} + fmt.Println(lab4A(1.2, 3.7, 0.5, a)) + fmt.Println(lab4B(x, a)) +} diff --git a/golang/lab6/lab6.go b/golang/lab6/lab6.go new file mode 100644 index 00000000..20043fde --- /dev/null +++ b/golang/lab6/lab6.go @@ -0,0 +1,41 @@ +package lab6 + +import ( + "fmt" +) + +type Person struct { + Name string + Age int + Country string +} + +func (c *Person) SetAge(age int) { + c.Age = age +} + +func (c *Person) SetCountry(country string) { + c.Country = country +} + +func (c *Person) DisplayInfo() { + fmt.Println("Имя:", c.Name) + fmt.Println("Возраст:", c.Age) + fmt.Println("Страна:", c.Country) +} + +func Lab6() { + Yan := Person{ + Name: "Ян", + Age: 20, + Country: "Россия", + } + + Yan.DisplayInfo() + + Yan.SetAge(31) + + Yan.SetCountry("Беларусь") + + Yan.DisplayInfo() +} diff --git a/golang/lab7/fruit.go b/golang/lab7/fruit.go new file mode 100644 index 00000000..e83eabd9 --- /dev/null +++ b/golang/lab7/fruit.go @@ -0,0 +1,31 @@ +package lab7 + +type Fruits struct { + price float64 + name string + calories float64 +} + +func (f *Fruits) GetName() string { + return f.name +} + +func (f *Fruits) SetName(newName string) { + f.name = newName +} + +func (f *Fruits) GetPrice() float64 { + return f.price +} + +func (f *Fruits) SetPrice(newPrice float64) { + f.price = newPrice +} + +func (f *Fruits) SetCalories(newCalories float64) { + f.calories = newCalories +} + +func (f *Fruits) ApplyDiscount(discount float64) { + f.price = f.price * (100 - discount) / 100 +} diff --git a/golang/lab7/lab7.go b/golang/lab7/lab7.go new file mode 100644 index 00000000..762cc013 --- /dev/null +++ b/golang/lab7/lab7.go @@ -0,0 +1,37 @@ +package lab7 + +import "fmt" + +type Product interface { + GetPrice() float64 + SetPrice(price float64) + ApplyDiscount(discount float64) + GetName() string + SetName(name string) +} + +func CalculateTotalPrice(products []Product) float64 { + totalPrice := 0.0 + for _, product := range products { + totalPrice += product.GetPrice() + } + return totalPrice +} + +func Lab7() { + iphone := &Phone{price: 100, weight: 200, name: "Айфон"} + tshirt := &Shirt{price: 200, size: "S", name: "Футболка"} + apple := &Fruits{price: 50, calories: 52, name: "Яблоко"} + + products := []Product{iphone, tshirt, apple} + + totalPrice := CalculateTotalPrice(products) + fmt.Println("Общая цена без скидки:", totalPrice) + + products[0].ApplyDiscount(10) + products[1].ApplyDiscount(20) + products[2].ApplyDiscount(25) + + totalPrice = CalculateTotalPrice(products) + fmt.Println("Общая цена с скидкой:", totalPrice) +} diff --git a/golang/lab7/phone.go b/golang/lab7/phone.go new file mode 100644 index 00000000..59838be4 --- /dev/null +++ b/golang/lab7/phone.go @@ -0,0 +1,31 @@ +package lab7 + +type Phone struct { + price float64 + name string + weight float64 +} + +func (t *Phone) GetName() string { + return t.name +} + +func (t *Phone) SetName(newName string) { + t.name = newName +} + +func (t *Phone) GetPrice() float64 { + return t.price +} + +func (t *Phone) SetPrice(newPrice float64) { + t.price = newPrice +} + +func (t *Phone) SetWeight(newWeight float64) { + t.weight = newWeight +} + +func (t *Phone) ApplyDiscount(discount float64) { + t.price = t.price * (100 - discount) / 100 +} diff --git a/golang/lab7/shirt.go b/golang/lab7/shirt.go new file mode 100644 index 00000000..c133a448 --- /dev/null +++ b/golang/lab7/shirt.go @@ -0,0 +1,31 @@ +package lab7 + +type Shirt struct { + price float64 + name string + size string +} + +func (c *Shirt) GetName() string { + return c.name +} + +func (c *Shirt) SetName(newName string) { + c.name = newName +} + +func (c *Shirt) GetPrice() float64 { + return c.price +} + +func (c *Shirt) SetPrice(newPrice float64) { + c.price = newPrice +} + +func (c *Shirt) SetSize(newSize string) { + c.size = newSize +} + +func (c *Shirt) ApplyDiscount(discount float64) { + c.price = c.price * (100 - discount) / 100 +} diff --git a/golang/main.go b/golang/main.go index 978819f0..db4971fa 100644 --- a/golang/main.go +++ b/golang/main.go @@ -1,7 +1,16 @@ package main -import "fmt" +import ( + "fmt" + + "isuct.ru/informatics2022/lab4" + "isuct.ru/informatics2022/lab6" + "isuct.ru/informatics2022/lab7" +) func main() { fmt.Println("Капицын Данила Сергеевич") + lab4.Lab4AB() + lab6.Lab6() + lab7.Lab7() }