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..968779fd --- /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..00a53183 --- /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) GetMaterial() string { + return c.material +} +func (c *Clothes) GetInfo() 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..93daf823 --- /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) GetInfo() 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..0871eb91 --- /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) GetInfo() 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..a2e53d23 --- /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() { + potato := &Food{50.15, "картошка", "вкусвилл", 17} + lipstick := &Cosmetics{"помада", 1700, "Chanel"} + sweatshirt := &Clothes{"толстовка", 3000.99, "Levi`s", "хлопок", "осень"} + products := []Product{potato, lipstick, sweatshirt} + fmt.Println("Товары") + fmt.Println("Общая стоимость:", CalculateProductsSum(products), "рублей") + for _, product := range products { + fmt.Println(product.GetInfo()) + } + + for _, product := range products { + product.SetDiscount(20) + } + fmt.Println("Общая стоимость товаров после применения скидки 20%:", CalculateProductsSum(products), "рублей") + + fmt.Println("Информация про товар толстовка") + fmt.Println("материал:", sweatshirt.GetMaterial()) + fmt.Println("сезон:", sweatshirt.GetSeason()) + fmt.Println("бренд:", sweatshirt.GetBrand()) +} diff --git a/golang/labs/lab7/product.go b/golang/labs/lab7/product.go new file mode 100644 index 00000000..cb3bd517 --- /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 + GetInfo() 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() }