Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lab3) #132

Open
wants to merge 3 commits into
base: Korchagin_Petr_Sergeevich
Choose a base branch
from
Open

lab3) #132

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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": []
}
31 changes: 31 additions & 0 deletions golang/internal/lab4/lab4.go
Original file line number Diff line number Diff line change
@@ -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
}
59 changes: 59 additions & 0 deletions golang/lab5/lab5.go
Original file line number Diff line number Diff line change
@@ -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)
}
28 changes: 27 additions & 1 deletion golang/main.go
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +11 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a и b передавайте параметрами, а вот e - возьмите из math - там есть и константа и функция exp(2) - что равнозначно например e^2

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)
}