-
Notifications
You must be signed in to change notification settings - Fork 111
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
Baldina Lab8 #456
Open
BaldinaDaria
wants to merge
15
commits into
ISUCT:Baldina_Daria
Choose a base branch
from
BaldinaDaria:Baldina_Lab8
base: Baldina_Daria
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Baldina Lab8 #456
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
932fc9a
Baldina Lab8
BaldinaDaria 2520f6d
Update Lab4.go
BaldinaDaria ff9b1a5
Update Lab4.go
BaldinaDaria b194e59
Update Lab4.go
BaldinaDaria fd1c392
Update Lab4.go
BaldinaDaria 92cb0f7
Update Lab8.go
BaldinaDaria b981202
Update Lab4.go
BaldinaDaria 8cf9d1c
Update Lab8.go
BaldinaDaria 19114f1
Update Lab4.go
BaldinaDaria db47305
Update Lab4.go
BaldinaDaria f6cd8c9
Update Lab4.go
BaldinaDaria 1329e0f
Update Lab4.go
BaldinaDaria f531b81
Update Lab4.go
BaldinaDaria 75672ac
Update Lab8.go
BaldinaDaria cdd9038
Update Lab8.go
BaldinaDaria File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package Lab8 | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"math" | ||
"os" | ||
"strconv" | ||
) | ||
|
||
func calcYA(b, x float64) float64 { | ||
denominator := math.Cbrt(math.Pow(b, 3) + math.Pow(x, 3)) | ||
if denominator == 0 { | ||
return math.Inf(1) | ||
} | ||
return (1 + math.Pow(math.Sin(math.Pow(b, 3)+math.Pow(x, 3)), 2)) / denominator | ||
} | ||
|
||
func taskAA(bA, xStart, xEnd, deltaX float64) []float64 { | ||
var results []float64 | ||
for x := xStart; x <= xEnd; x += deltaX { | ||
y := calcYA(bA, x) | ||
results = append(results, y) | ||
} | ||
return results | ||
} | ||
|
||
func taskBA(bB float64, xValues []float64) []float64 { | ||
var results []float64 | ||
for _, x := range xValues { | ||
y := calcYA(bB, x) | ||
results = append(results, y) | ||
} | ||
return results | ||
} | ||
|
||
func RunLab8A() { | ||
const filename = "input.txt" | ||
|
||
values, err := readInputFileA(filename) | ||
if err != nil { | ||
fmt.Println("Ошибка при чтении файла:", err) | ||
return | ||
} | ||
|
||
if len(values) < 2 { | ||
fmt.Println("Недостаточно значений в файле") | ||
return | ||
} | ||
|
||
bA := values[0] | ||
bB := values[1] | ||
xValues := values[2:] | ||
|
||
xStart := 1.28 | ||
xEnd := 3.28 | ||
deltaX := 0.4 | ||
|
||
resultsA := taskAA(bA, xStart, xEnd, deltaX) | ||
fmt.Println("Результаты задания A:") | ||
for i, y := range resultsA { | ||
x := xStart + float64(i)*deltaX | ||
fmt.Printf("x: %.2f, y: %.4f\n", x, y) | ||
} | ||
|
||
resultsB := taskBA(bB, xValues) | ||
fmt.Println("\nРезультаты задания B:") | ||
for i, y := range resultsB { | ||
x := xValues[i] | ||
fmt.Printf("x: %.2f, y: %.4f\n", x, y) | ||
} | ||
} | ||
|
||
func readInputFileA(filename string) ([]float64, error) { | ||
file, err := os.Open(filename) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer file.Close() | ||
|
||
var values []float64 | ||
scanner := bufio.NewScanner(file) | ||
|
||
for scanner.Scan() { | ||
line := scanner.Text() | ||
value, err := strconv.ParseFloat(line, 64) | ||
if err != nil { | ||
fmt.Println("Ошибка при чтении числа:", err) | ||
continue | ||
} | ||
values = append(values, value) | ||
} | ||
|
||
if err := scanner.Err(); err != nil { | ||
return nil, err | ||
} | ||
return values, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
package Lab8 | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"math" | ||
"os" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
func calcY(b, x float64) float64 { | ||
denominator := math.Cbrt(math.Pow(b, 3) + math.Pow(x, 3)) | ||
if denominator == 0 { | ||
return math.Inf(1) | ||
} | ||
return (1 + math.Pow(math.Sin(math.Pow(b, 3)+math.Pow(x, 3)), 2)) / denominator | ||
} | ||
|
||
func taskA(a, xStart, xEnd, deltaX float64) []float64 { | ||
var results []float64 | ||
for x := xStart; x <= xEnd; x += deltaX { | ||
y := calcY(a, x) | ||
results = append(results, y) | ||
} | ||
return results | ||
} | ||
|
||
func taskB(b float64, xValues []float64) []float64 { | ||
var results []float64 | ||
for _, x := range xValues { | ||
y := calcY(b, x) | ||
results = append(results, y) | ||
} | ||
return results | ||
} | ||
|
||
func RunLab8() { | ||
const inputFilename = "input.txt" | ||
const outputFilename = "output.txt" | ||
|
||
values, err := readInputFile(inputFilename) | ||
if err != nil { | ||
fmt.Println("Ошибка при чтении файла:", err) | ||
return | ||
} | ||
|
||
if len(values) < 2 { | ||
fmt.Println("Недостаточно значений в файле") | ||
return | ||
} | ||
|
||
a := values[0] | ||
b := values[1] | ||
xValues := values[2:] | ||
|
||
xStart := 1.28 | ||
xEnd := 3.28 | ||
deltaX := 0.4 | ||
|
||
resultsA := taskA(a, xStart, xEnd, deltaX) | ||
fmt.Println("Результаты задания A:") | ||
for i, y := range resultsA { | ||
x := xStart + float64(i)*deltaX | ||
fmt.Printf("x: %.2f, y: %.4f\n", x, y) | ||
} | ||
|
||
resultsB := taskB(b, xValues) | ||
fmt.Println("\nРезультаты задания B:") | ||
for i, y := range resultsB { | ||
x := xValues[i] | ||
fmt.Printf("x: %.2f, y: %.4f\n", x, y) | ||
} | ||
|
||
err = writeOutputFile(outputFilename, resultsA, resultsB, xStart, deltaX, xValues) | ||
if err != nil { | ||
fmt.Println("Ошибка при записи в файл:", err) | ||
return | ||
} | ||
|
||
err = writeDataToFile(outputFilename) | ||
if err != nil { | ||
fmt.Println("Ошибка при записи данных в файл:", err) | ||
return | ||
} | ||
|
||
err = displayFileContents(outputFilename) | ||
if err != nil { | ||
fmt.Println("Ошибка при выводе данных из файла:", err) | ||
return | ||
} | ||
|
||
fmt.Print("Введите текст для поиска в файле: ") | ||
scanner := bufio.NewScanner(os.Stdin) | ||
scanner.Scan() | ||
searchTerm := scanner.Text() | ||
err = searchInFile(outputFilename, searchTerm) | ||
if err != nil { | ||
fmt.Println("Ошибка при поиске в файле:", err) | ||
return | ||
} | ||
} | ||
|
||
func readInputFile(filename string) ([]float64, error) { | ||
file, err := os.Open(filename) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer file.Close() | ||
|
||
var values []float64 | ||
scanner := bufio.NewScanner(file) | ||
|
||
for scanner.Scan() { | ||
line := scanner.Text() | ||
value, err := strconv.ParseFloat(line, 64) | ||
if err != nil { | ||
fmt.Println("Ошибка при чтении числа:", err) | ||
continue | ||
} | ||
values = append(values, value) | ||
} | ||
if err := scanner.Err(); err != nil { | ||
return nil, err | ||
} | ||
return values, nil | ||
} | ||
|
||
func writeOutputFile(filename string, resultsA, resultsB []float64, xStart, deltaX float64, xValues []float64) error { | ||
file, err := os.Create(filename) | ||
if err != nil { | ||
return err | ||
} | ||
defer file.Close() | ||
|
||
writer := bufio.NewWriter(file) | ||
|
||
writer.WriteString("Результаты задания A:\n") | ||
for i, y := range resultsA { | ||
x := xStart + float64(i)*deltaX | ||
writer.WriteString(fmt.Sprintf("x: %.2f, y: %.4f\n", x, y)) | ||
} | ||
|
||
writer.WriteString("\nРезультаты задания B:\n") | ||
for i, y := range resultsB { | ||
x := xValues[i] | ||
writer.WriteString(fmt.Sprintf("x: %.2f, y: %.4f\n", x, y)) | ||
} | ||
|
||
return writer.Flush() | ||
} | ||
|
||
func writeDataToFile(filename string) error { | ||
file, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0644) | ||
if err != nil { | ||
return err | ||
} | ||
defer file.Close() | ||
|
||
writer := bufio.NewWriter(file) | ||
fmt.Println("Введите данные для записи в файл (введите 'exit' для выхода):") | ||
|
||
scanner := bufio.NewScanner(os.Stdin) | ||
for { | ||
scanner.Scan() | ||
line := scanner.Text() | ||
if line == "exit" { | ||
break | ||
} | ||
writer.WriteString(line + "\n") | ||
} | ||
return writer.Flush() | ||
} | ||
|
||
func displayFileContents(filename string) error { | ||
file, err := os.Open(filename) | ||
if err != nil { | ||
return err | ||
} | ||
defer file.Close() | ||
|
||
scanner := bufio.NewScanner(file) | ||
fmt.Println("\nСодержимое файла:") | ||
for scanner.Scan() { | ||
fmt.Println(scanner.Text()) | ||
} | ||
return scanner.Err() | ||
} | ||
|
||
func searchInFile(filename, searchTerm string) error { | ||
file, err := os.Open(filename) | ||
if err != nil { | ||
return err | ||
} | ||
defer file.Close() | ||
|
||
scanner := bufio.NewScanner(file) | ||
found := false | ||
fmt.Printf("\nПоиск текста '%s' в файле:\n", searchTerm) | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
if strings.Contains(line, searchTerm) { | ||
fmt.Printf("Найдено: %s\n", line) | ||
found = true | ||
} | ||
} | ||
if !found { | ||
fmt.Println("Текст не найден.") | ||
} | ||
return scanner.Err() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
2.5 | ||
3.0 | ||
1.1 | ||
2.4 | ||
3.6 | ||
1.7 | ||
3.9 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не увидел записи и поиска