-
Notifications
You must be signed in to change notification settings - Fork 112
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
Prokudina lab8 #457
base: Prokudina_Khristina
Are you sure you want to change the base?
Prokudina lab8 #457
Conversation
golang/lab8/Lab8.go
Outdated
fmt.Println("Введите данные для записи в файл (введите 'exit' для завершения):") | ||
scanner := bufio.NewScanner(os.Stdin) | ||
for { | ||
scanner.Scan() | ||
input := scanner.Text() | ||
if strings.ToLower(input) == "exit" { | ||
break | ||
} | ||
if _, err := file.WriteString(input + "\n"); err != nil { | ||
fmt.Printf("Ошибка при записи в файл: %v\n", err) | ||
} | ||
} |
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.
По названию функции я ожидаю что она только записывает в файл, уберите ввод в другое место, а внутрь передавайте строчку с данными
func readInputFileA(filename string) (float64, float64, float64) { | ||
file, err := os.Open(filename) | ||
if err != nil { | ||
fmt.Printf("Ошибка при открытии файла: %v\n", err) | ||
return 0, 0, 0 | ||
} | ||
defer file.Close() | ||
|
||
scanner := bufio.NewScanner(file) | ||
var values []float64 | ||
|
||
for scanner.Scan() { | ||
value, err := strconv.ParseFloat(scanner.Text(), 64) | ||
if err == nil { | ||
values = append(values, value) | ||
} | ||
} | ||
|
||
if err := scanner.Err(); err != nil { | ||
fmt.Printf("Ошибка при чтении файла: %v\n", err) | ||
} | ||
|
||
if len(values) < 3 { | ||
fmt.Println("Ошибка: недостаточно данных в файле.") | ||
return 0, 0, 0 | ||
} | ||
|
||
return values[0], values[1], values[2] | ||
} |
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.
Пожалуйста, разделите все корректно на разные файлы. Такое сложно было бы поддерживать в будущем, будь это настоящий проект. Да и проверять тоже не самое приятное дело
golang/lab8/Lab8.go
Outdated
func taskA(Xn float64, Xk float64, deltaX float64) ([]float64, []float64) { | ||
var results []float64 | ||
var xValues []float64 | ||
|
||
for x := Xn; x <= Xk; x += deltaX { | ||
y := calculateY(x) | ||
if !math.IsNaN(y) { | ||
results = append(results, y) | ||
xValues = append(xValues, x) | ||
} | ||
} | ||
return results, xValues | ||
} | ||
|
||
func taskB(values []float64) []float64 { | ||
var results []float64 | ||
for _, x := range values { | ||
y := calculateY(x) | ||
if !math.IsNaN(y) { | ||
results = append(results, y) | ||
} | ||
} | ||
return results | ||
} |
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.
Что за копипаст из двух файлов? Снова подозреваю у вас GPT, либо списывание, либо невнимательность
No description provided.