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

lab5 #292

Open
wants to merge 1 commit into
base: Polozkov_Maksim_Mihajlovich
Choose a base branch
from
Open

lab5 #292

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
30 changes: 30 additions & 0 deletions golang/internal/struct2/struct2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package struct2

import (
"fmt"
)

type Mouse struct {
Brand string
Buttons int
Wireless bool
}

func (m *Mouse) GetBrand() (string, error) {
if m.Brand == "" {
return "", fmt.Errorf("бренд мыши не установлен")
}
return m.Brand, nil
}

func (m *Mouse) SetButtons(num int) error {
if num < 0 {
return fmt.Errorf("количество кнопок не может быть отрицательным")
}
m.Buttons = num
return nil
}

func (m *Mouse) IsWireless() bool {
return m.Wireless
}
39 changes: 34 additions & 5 deletions golang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,40 @@ package main

import (
"fmt"
"isuct.ru/informatics2022/internal"
"math"

"isuct.ru/informatics2022/internal/struct2"
)

func main() {
fmt.Println("Полозков Максим Михайлович | Вариант №19")
fmt.Println(internal.Task_A(1.2, 4.2, 0.6))
fmt.Println(internal.Task_B([]float64{1.16, 1.32, 1.47, 1.65, 1.93}))
}
fmt.Println("Полозков Максим Михайлович")
a := 2.0
x_n := 1.2
x_k := 4.2
x_z := 0.6
for x := x_n; x <= x_k; x = x + x_z {
var ya = (math.Pow(math.Log10(a+x), 2) / math.Pow(a+x, 2))
fmt.Println("Результат задачи A =", ya)
}
var argument = [5]float64{1.16, 1.32, 1.47, 1.65, 1.93}
for z := 0; z < 5; z++ {
var yb = (math.Pow(math.Log10(a+argument[z]), 2) / math.Pow(a+argument[z], 2))
fmt.Println("Результат задачи B =", yb)
}

m := struct2.Mouse{Brand: "Logitech", Buttons: 3, Wireless: true}

brand, err := m.GetBrand()
if err != nil {
fmt.Println("Ошибка при получении бренда мыши:", err)
} else {
fmt.Println("Бренд мыши:", brand)
}

if err := m.SetButtons(5); err != nil {
fmt.Println("Ошибка при установке количества кнопок:", err)
} else {
fmt.Println("Количество кнопок после установки:", m.Buttons)
}
fmt.Println("Беспроводная мышь?", m.IsWireless())
}