diff --git a/Informatics_2024 b/Informatics_2024 new file mode 160000 index 00000000..f0237cff --- /dev/null +++ b/Informatics_2024 @@ -0,0 +1 @@ +Subproject commit f0237cffc24b67041be9a6feecd155945357649c diff --git a/golang/labs/lab4/lab4.go b/golang/labs/lab4/lab4.go new file mode 100644 index 00000000..5de6832e --- /dev/null +++ b/golang/labs/lab4/lab4.go @@ -0,0 +1,35 @@ +package lab4 + +import ( + "fmt" + "math" +) + +func RunLab4() { + a := 2.5 + b := 4.6 + fmt.Println(taska(1.1, 3.6, 0.5, a, b)) + arr := []float64{1.2, 1.28, 1.36, 1.46, 2.35} + fmt.Println(taskb(arr, a, b)) +} + +func taska(xn, xk, deltax, a, b float64) []float64 { + var yValues []float64 + for x := xn; x <= xk; x += deltax { + yValues = append(yValues, CalculateY(x, a, b)) + } + return yValues +} + +func taskb(values []float64, a, b float64) []float64 { + var yValues []float64 + for _, x := range values { + yValues = append(yValues, CalculateY(x, a, b)) + } + return yValues +} + +func CalculateY(x float64, a float64, b float64) float64 { + y := math.Pow(a+b*x, 2.5) / (1 + math.Log10(a+b*x)) + return y +} diff --git a/golang/labs/lab6/lab6.go b/golang/labs/lab6/lab6.go new file mode 100644 index 00000000..a6c60343 --- /dev/null +++ b/golang/labs/lab6/lab6.go @@ -0,0 +1,41 @@ +package lab6 + +import ( + "fmt" +) + +type Mouse struct { + Name string + Age int + Weight float64 +} + +func NewMouse(name string, age int, weight float64) Mouse { + return Mouse{Name: name, Age: age, Weight: weight} +} + +func (r *Mouse) GetAge() int { + return r.Age +} + +func (r *Mouse) SetAge(age int) { + if age > 0 { + r.Age = age + } +} + +func (r Mouse) Info() string { + return fmt.Sprintf("Имя: %s, Возраст: %d, Вес: %.2f кг", r.Name, r.Age, r.Weight) +} + +func RunLab6() { + mouse := NewMouse("Гена", 2, 1.5) + + fmt.Println(mouse.Info()) + + mouse.SetAge(3) + + fmt.Printf("Обновленный возраст: %d\n", mouse.GetAge()) + + fmt.Println(mouse.Info()) +} diff --git a/golang/labs/lab7/clothes.go b/golang/labs/lab7/clothes.go new file mode 100644 index 00000000..01737183 --- /dev/null +++ b/golang/labs/lab7/clothes.go @@ -0,0 +1,40 @@ +package labs + +import "fmt" + +type Clothes struct { + name string + price float64 + brand string + material string + season string +} + +func (c *Clothes) GetName() string { + return c.name +} + +func (c *Clothes) GetPrice() float64 { + return c.price +} + +func (c *Clothes) SetDiscount(discount float64) { + c.price -= c.price * discount / 100 +} + +func (c *Clothes) SetPrice(newPrice float64) { + c.price = newPrice +} + +func (c *Clothes) GetBrand() string { + return c.brand +} +func (c *Clothes) GetSeason() string { + return c.season +} +func (c *Clothes) GetMat() string { + return c.material +} +func (c *Clothes) GetInf() string { + return fmt.Sprintf("название: %s, цена: %.2f, бренд: %s, материал: %s,сезон: %s", c.name, c.price, c.brand, c.material, c.season) +} diff --git a/golang/labs/lab7/cosmetics.go b/golang/labs/lab7/cosmetics.go new file mode 100644 index 00000000..715d61e5 --- /dev/null +++ b/golang/labs/lab7/cosmetics.go @@ -0,0 +1,27 @@ +package labs + +import "fmt" + +type Cosmetics struct { + name string + price float64 + brand string +} + +func (c *Cosmetics) GetName() string { + return c.name +} +func (c *Cosmetics) GetPrice() float64 { + return c.price +} + +func (c *Cosmetics) SetDiscount(discount float64) { + c.price -= c.price * discount / 100 +} + +func (c *Cosmetics) SetPrice(newPrice float64) { + c.price = newPrice +} +func (c *Cosmetics) GetInf() string { + return fmt.Sprintf("название: %s, бренд: %s, цена: %.2f", c.name, c.brand, c.price) +} diff --git a/golang/labs/lab7/food.go b/golang/labs/lab7/food.go new file mode 100644 index 00000000..29ecbd6b --- /dev/null +++ b/golang/labs/lab7/food.go @@ -0,0 +1,28 @@ +package labs + +import "fmt" + +type Food struct { + price float64 + name string + brand string + calories int +} + +func (f *Food) GetName() string { + return f.name +} +func (f *Food) GetPrice() float64 { + return f.price +} + +func (f *Food) SetDiscount(discount float64) { + f.price -= f.price * discount / 100 +} + +func (f *Food) SetPrice(newPrice float64) { + f.price = newPrice +} +func (f *Food) GetInf() string { + return fmt.Sprintf("название: %s, цена: %.2f, каллории: %d , бренд: %s", f.name, f.price, f.calories, f.brand) +} diff --git a/golang/labs/lab7/lab7.go b/golang/labs/lab7/lab7.go new file mode 100644 index 00000000..1109a6ba --- /dev/null +++ b/golang/labs/lab7/lab7.go @@ -0,0 +1,33 @@ +package labs + +import "fmt" + +func CalculateProductsSum(products []Product) float64 { + var sum float64 = 0 + for _, product := range products { + sum += product.GetPrice() + } + return sum +} + +func RunLab7() { + carrot := &Food{50.15, "морковь", "магнит", 17} + mascara := &Cosmetics{"тушь для ресниц", 1700, "loreal paris"} + shirt := &Clothes{"рубашка", 3000.99, "Levi`s", "синтетика", "весна"} + products := []Product{carrot, mascara, shirt} + fmt.Println("товары") + fmt.Println("общая стоимость:", CalculateProductsSum(products), "рублей") + for _, product := range products { + fmt.Println(product.GetInf()) + } + + for _, product := range products { + product.SetDiscount(20) + } + fmt.Println("общая стоимость товаров после применения скидки 20%:", CalculateProductsSum(products), "рублей") + + fmt.Println("информация про товар рубашка") + fmt.Println("материал:", shirt.GetMat()) + fmt.Println("сезон:", shirt.GetSeason()) + fmt.Println("бренд:", shirt.GetBrand()) +} diff --git a/golang/labs/lab7/product.go b/golang/labs/lab7/product.go new file mode 100644 index 00000000..dbf38e30 --- /dev/null +++ b/golang/labs/lab7/product.go @@ -0,0 +1,9 @@ +package labs + +type Product interface { + SetDiscount(discount float64) + SetPrice(newPrice float64) + GetPrice() float64 + GetName() string + GetInf() string +} diff --git a/golang/main.go b/golang/main.go index 41a1d795..1b9070c7 100644 --- a/golang/main.go +++ b/golang/main.go @@ -1,7 +1,15 @@ package main -import "fmt" +import ( + "fmt" + lab4 "isuct.ru/informatics2022/labs/lab4" + lab6 "isuct.ru/informatics2022/labs/lab6" + lab7 "isuct.ru/informatics2022/labs/lab7" +) func main() { fmt.Println("Медведева Виктория Александровна") + lab4.RunLab4() + lab6.RunLab6() + lab7.RunLab7() }