diff --git a/golang/LAB_4/LAB_4.go b/golang/LAB_4/LAB_4.go new file mode 100644 index 00000000..ed1b8bdb --- /dev/null +++ b/golang/LAB_4/LAB_4.go @@ -0,0 +1,36 @@ +package LAB_4 + +import ( + "fmt" + "math" +) + +const a = 2.0 + +func calculateY(x float64) float64 { + y := math.Tan(math.Pow(math.Log10(a+x), 3)) / math.Pow(math.Pow((a+x), 2), 1/7) + return y +} + +func TaskA(xn, xk, delx float64) []float64 { + var ValuesY []float64 + for x := xn; x <= xk; x += delx { + ValuesY = append(ValuesY, calculateY(x)) + } + return ValuesY +} + +func TaskB(xv []float64) []float64 { + var ValuesY []float64 + for _, x := range xv { + ValuesY = append(ValuesY, calculateY(x)) + } + return ValuesY +} + +func Lab4() { + xn, xk, delx := 1.08, 1.88, 0.16 + xv := []float64{1.16, 1.35, 1.48, 1.52, 1.96} + fmt.Println("Задача А:", TaskA(xn, xk, delx)) + fmt.Println("Задача B:", TaskB(xv)) +} diff --git a/golang/LAB_6/LAB_6.go b/golang/LAB_6/LAB_6.go new file mode 100644 index 00000000..07ab0c32 --- /dev/null +++ b/golang/LAB_6/LAB_6.go @@ -0,0 +1,44 @@ +package LAB_6 + +import ( + "fmt" + "strconv" +) + +const maxRabbitAge = 12 + +type Rabbit struct { + Name string + Age int + Color string +} + +func (rabbit *Rabbit) SetName(name string) { + rabbit.Name = name +} + +func (rabbit *Rabbit) SetColor(color string) { + rabbit.Color = color +} +func (rabbit *Rabbit) SetAge(age int) { + if age <= maxRabbitAge { + rabbit.Age = age + } else { + fmt.Println("Ошибка: указанный возраст превышает максимальный возраст кроликов!") + } +} + +func (rabbit Rabbit) GetInfo() string { + return "Имя кролика: " + rabbit.Name + "\nВозраст кролика: " + strconv.Itoa(rabbit.Age) + "\nЦвет кролика: " + rabbit.Color +} + +func Lab6() { + rabbit := Rabbit{Name: "Беляш", Age: 1, Color: "Белый"} + + fmt.Println(rabbit.GetInfo()) + + rabbit.SetName("Пушок") + rabbit.SetAge(3) + + fmt.Println(rabbit.GetInfo()) +} diff --git a/golang/LAB_7/LAB_7.go b/golang/LAB_7/LAB_7.go new file mode 100644 index 00000000..a1401c8b --- /dev/null +++ b/golang/LAB_7/LAB_7.go @@ -0,0 +1,50 @@ +package LAB_7 + +import "fmt" + +type Product interface { + GetName() string + GetPrice() float64 + SetPrice(price float64) + ApplyDiscount(discount float64) +} + +func Calculate(products []Product) float64 { + total := 0.0 + for _, product := range products { + total += product.GetPrice() + } + return total +} + +func Lab7() { + iceCream := &IceCream{ + Name: "Ванильное", + Brand: "Веселая коровка", + Price: 50.00, + Flavor: "Ваниль", + } + sofa := &Sofa{ + Name: "Классический диван", + Price: 20000.00, + Brand: "IKEA", + Color: "Коричневый", + Material: "Кожа", + } + + products := []Product{iceCream, sofa} + fmt.Println("Общая стоимость:", Calculate(products)) + iceCream.ApplyDiscount(10) + sofa.ApplyDiscount(15) + fmt.Println("Общая стоимость товаров после применения скидок:", Calculate(products)) + + fmt.Println("Материал дивана:", sofa.Material) + fmt.Println("Цвет дивана:", sofa.Color) + fmt.Println("Вкус мороженого:", iceCream.Flavor) + sofa.ChangeColor("Черный") + sofa.ChangeMaterial("Замша") + iceCream.ChangeFlavor("Шоколад") + fmt.Println("Цвет дивана изменен на:", sofa.Color) + fmt.Println("Материал дивана изменен на:", sofa.Material) + fmt.Println("Вкус мороженого изменен на:", iceCream.Flavor) +} diff --git a/golang/LAB_7/icecream.go b/golang/LAB_7/icecream.go new file mode 100644 index 00000000..2fa27f0f --- /dev/null +++ b/golang/LAB_7/icecream.go @@ -0,0 +1,28 @@ +package LAB_7 + +type IceCream struct { + Name string + Brand string + Price float64 + Flavor string +} + +func (i *IceCream) GetName() string { + return i.Name +} + +func (i *IceCream) GetPrice() float64 { + return i.Price +} + +func (i *IceCream) SetPrice(price float64) { + i.Price = price +} + +func (i *IceCream) ApplyDiscount(discount float64) { + i.Price -= i.Price * discount / 100 +} + +func (i *IceCream) ChangeFlavor(newFlavor string) { + i.Flavor = newFlavor +} diff --git a/golang/LAB_7/sofa.go b/golang/LAB_7/sofa.go new file mode 100644 index 00000000..3c441bf9 --- /dev/null +++ b/golang/LAB_7/sofa.go @@ -0,0 +1,32 @@ +package LAB_7 + +type Sofa struct { + Name string + Price float64 + Brand string + Color string + Material string +} + +func (s *Sofa) GetName() string { + return s.Name +} + +func (s *Sofa) GetPrice() float64 { + return s.Price +} + +func (s *Sofa) SetPrice(price float64) { + s.Price = price +} + +func (s *Sofa) ApplyDiscount(discount float64) { + s.Price -= s.Price * discount / 100 +} + +func (s *Sofa) ChangeColor(newColor string) { + s.Color = newColor +} +func (s *Sofa) ChangeMaterial(newMaterial string) { + s.Material = newMaterial +} diff --git a/golang/main.go b/golang/main.go index d2c4e91e..923c2761 100644 --- a/golang/main.go +++ b/golang/main.go @@ -1,7 +1,16 @@ package main -import "fmt" +import ( + "fmt" + + "isuct.ru/informatics2022/LAB_4" + "isuct.ru/informatics2022/LAB_6" + "isuct.ru/informatics2022/LAB_7" +) func main() { - fmt.Println("Hello world") + fmt.Println("Чернов Максим Александрович") + LAB_4.Lab4() + LAB_6.Lab6() + LAB_7.Lab7() }