Skip to content
Open
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
63 changes: 63 additions & 0 deletions golang/labs/lab4/lab4.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package function

import (
"fmt"
"math"
)

const epsilon = 1e-9

func CalculateY(x, a, b float64) float64 {
arccosArg := x*x - b*b
arcsinArg := x*x - a*a

fmt.Printf("x: %f, a: %f, b: %f\n", x, a, b)
fmt.Printf("arccosArg: %f, arcsinArg: %f\n", arccosArg, arcsinArg)

if arccosArg < -1 || arccosArg > 1 || arcsinArg < -1 || arcsinArg > 1 {
fmt.Println("Out of range")
return math.NaN()
}

asinValue := math.Asin(arcsinArg)
fmt.Printf("asinValue: %f\n", asinValue)

if math.Abs(asinValue) < epsilon {
fmt.Println("asinValue too small")
return math.NaN()
}

result := math.Acos(arccosArg) / asinValue
fmt.Printf("Result: %f\n", result)

return result
}

func Task_A(begin_x, end_x, delta_x, a, b float64) []float64 {
var answer_arr []float64
for x := begin_x; x < end_x; x += delta_x {
answer_arr = append(answer_arr, CalculateY(x, a, b))
}
return answer_arr
}

func Task_B(arguments []float64, a, b float64) []float64 {
var answer_arr []float64
for _, x := range arguments {
answer_arr = append(answer_arr, CalculateY(x, a, b))
}
return answer_arr
}

func RunLab4Task() {
fmt.Println("------------------------------------------")

resultA := Task_A(0.05, 0.95, 0.15, 0.06, 0.05)
fmt.Println(resultA)
fmt.Println("------------------------------------------")

arr := []float64{0.15, 0.26, 0.37, 0.48, 0.56}
resultB := Task_B(arr, 0.05, 0.07)
fmt.Println(resultB)
fmt.Println("------------------------------------------")
}
43 changes: 43 additions & 0 deletions golang/labs/lab6/lab6.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package labs

import "fmt"

type Table struct {
length, width, height float64
}

func NewTable(length, width, height float64) Table {
return Table{
length: length,
width: width,
height: height,
}
}

func (t *Table) SetDimensions(length, width, height float64) {
t.length = length
t.width = width
t.height = height
}

func (t *Table) GetLength() float64 {
return t.length
}

func (t *Table) GetWidth() float64 {
return t.width
}

func (t *Table) GetHeight() float64 {
return t.height
}

func RunLab6Task() {
myTable := NewTable(120, 60, 75)

fmt.Printf("Начальные размеры стола: Длина = %.2f, Ширина = %.2f, Высота = %.2f\n", myTable.GetLength(), myTable.GetWidth(), myTable.GetHeight())

myTable.SetDimensions(150, 70, 80)

fmt.Printf("Обновленные размеры стола: Длина = %.2f, Ширина = %.2f, Высота = %.2f\n", myTable.GetLength(), myTable.GetWidth(), myTable.GetHeight())
}
10 changes: 9 additions & 1 deletion golang/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package main

import "fmt"
import (
"fmt"

lab4 "isuct.ru/informatics2022/labs/lab4"
lab6 "isuct.ru/informatics2022/labs/lab6"
)

func main() {
fmt.Print()
lab4.RunLab4Task()
lab6.RunLab6Task()
fmt.Println("Kolbasov Nikita Andreevich")
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ func TestSumm(t *testing.T) {
t.Fatalf(`Summ(2,3) = %d, want 5, error`, summ)
}
}

Loading