diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..5c7247b4 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,7 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [] +} \ No newline at end of file diff --git a/golang/internal/lab4/lab4.go b/golang/internal/lab4/lab4.go new file mode 100644 index 00000000..c2c11810 --- /dev/null +++ b/golang/internal/lab4/lab4.go @@ -0,0 +1,31 @@ +package lab4 + +import ( + "math" +) + +func formula(x float64) float64 { + var a float64 = 1.2 + var b float64 = 0.48 + return ((math.Pow(b, 3) + math.Pow(math.Sin(a*x), 2)) / (math.Acos((x * b * x)) + math.Exp(-x/2))) +} + +func TaskA(xN, xK, xD float64) ([]float64, []float64) { + x := make([]float64, 0, (int((xK-xN)/xD - 1))) + y := make([]float64, 0, (int((xK-xN)/xD - 1))) + for i := xN; i <= xK; i += xD { + y = append(y, formula(i)) + x = append(x, i) + } + return x, y +} + +func TaskB(xArray []float64) ([]float64, []float64) { + x := make([]float64, 0, len(xArray)) + y := make([]float64, 0, len(xArray)) + for i := 0; i < len(xArray); i++ { + y = append(y, formula(xArray[i])) + x = append(x, xArray[i]) + } + return x, y +} diff --git a/golang/lab5/lab5.go b/golang/lab5/lab5.go new file mode 100644 index 00000000..c74fd88d --- /dev/null +++ b/golang/lab5/lab5.go @@ -0,0 +1,59 @@ +package lab5 + +import ( + "fmt" + "log" +) + +type Rabbit struct { + age uint + weigth float64 + color string + gender string +} + +func New_Struct(new_age uint, new_w float64, new_color, new_gender string) Rabbit { + var new_rabbit = Rabbit{ + color: new_color, + } + err := new_rabbit.set_weigth(new_w) + if err != nil { + log.Fatal(err) + } + err = new_rabbit.set_age(new_age) + if err != nil { + log.Fatal(err) + } + err = new_rabbit.set_gender(new_gender) + if err != nil { + log.Fatal(err) + } + return new_rabbit +} +func (r *Rabbit) set_age(new_age uint) error { + if new_age < 15 { + r.age = new_age + return nil + } else { + return fmt.Errorf("некорректно введён возраст кролика") + } +} +func (r *Rabbit) set_weigth(new_w float64) error { + if (new_w >= 0.4) && (new_w <= 2.0) { + r.weigth = new_w + return nil + } else { + return fmt.Errorf("некорректно введён вес кролика") + } +} +func (r *Rabbit) set_gender(new_gender string) error { + if new_gender == "муж" || new_gender == "жен" { + r.gender = new_gender + return nil + } else { + return fmt.Errorf("некорректно введён гендер кролика") + } +} +func Output(r *Rabbit) { + fmt.Printf("Кролик весит %1.2f килограмм, имеет возраст %d лет, %s пол и %s цвет\n", r.weigth, r.age, r.gender, r.color) +} diff --git a/golang/main.go b/golang/main.go index 030f1b3f..747d5105 100644 --- a/golang/main.go +++ b/golang/main.go @@ -1,7 +1,33 @@ package main -import "fmt" +import ( + "fmt" + "math" + "isuct.ru/informatics2022/lab5" +) + +func formula(x float64) float64 { + a := 1.2 + b := 0.48 + e := 2.71 + return ((math.Pow(b, 3) + math.Pow(math.Sin(a*x), 2)) / (math.Acos((x * b * x)) + math.Pow(e, (-x/2)))) +} func main() { fmt.Println("Корчагин Пётр Сергеевич") + fmt.Println("Ответы на задачу A") + for i := 0.7; i <= 2.2; i += 0.3 { + fmt.Println("x=", i, "y=", formula(i)) + } + fmt.Println("Ответы на задачу B") + var listx [5]float64 = [5]float64{0.25, 0.36, 0.56, 0.94, 1.28} + for i := 0; i < 5; i++ { + fmt.Println("x=", listx[i], "y=", formula(listx[i])) + } + p := lab5.New_Struct(5, 1.5, "Чёрный", "муж") + lab5.Output(&p) + p = lab5.New_Struct(7, 2.0, "Белый", "жен") + lab5.Output(&p) + p = lab5.New_Struct(100, 1.5, "Чёрный", "муж") + lab5.Output(&p) }