-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* first commit * fixed * fixed * fixed * fixed * fixed * fixed * fixed * fixed * fixed * fixed * fixed * fixed * fixed * fixed * fixed * fixed * fixed * fixed * fixed * fixed * fixed * fixed * fixed * fixed
- Loading branch information
Showing
13 changed files
with
211 additions
and
20 deletions.
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package labs | ||
package lab6 | ||
|
||
import ( | ||
"fmt" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package laba7 | ||
package lab7 | ||
|
||
import ( | ||
"fmt" | ||
|
2 changes: 1 addition & 1 deletion
2
golang/labs/laba7/electronics.go → golang/labs/lab7/electronics.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package laba7 | ||
package lab7 | ||
|
||
import ( | ||
"fmt" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package laba7 | ||
package lab7 | ||
|
||
import ( | ||
"fmt" | ||
|
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package laba7 | ||
package lab7 | ||
|
||
import ( | ||
"errors" | ||
|
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,10 @@ | ||
0.05 | ||
0.06 | ||
0.2 | ||
0.95 | ||
0.15 | ||
0.15 | ||
0.26 | ||
0.37 | ||
0.48 | ||
0.56 |
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,52 @@ | ||
package lab8 | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os" | ||
"strconv" | ||
) | ||
|
||
type Parameters struct { | ||
A float64 | ||
B float64 | ||
Xn float64 | ||
Xk float64 | ||
Deltax float64 | ||
Slicex []float64 | ||
} | ||
|
||
func ReadDataFromFile(filename string) (Parameters, error) { | ||
file, err := os.Open(filename) | ||
if err != nil { | ||
return Parameters{}, fmt.Errorf("ошибка открытия файла: %w", err) | ||
} | ||
defer file.Close() | ||
|
||
scanner := bufio.NewScanner(file) | ||
var values []float64 | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
num, err := strconv.ParseFloat(line, 64) | ||
if err != nil { | ||
return Parameters{}, fmt.Errorf("ошибка парсинга float '%s': %w", line, err) | ||
} | ||
values = append(values, num) | ||
} | ||
|
||
if err := scanner.Err(); err != nil { | ||
return Parameters{}, fmt.Errorf("ошибка чтения файла: %w", err) | ||
} | ||
if len(values) < 6 { | ||
return Parameters{}, fmt.Errorf("нехватает значений! попробуй еще раз") | ||
} | ||
params := Parameters{ | ||
A: values[0], | ||
B: values[1], | ||
Xn: values[2], | ||
Xk: values[3], | ||
Deltax: values[4], | ||
Slicex: values[5:], | ||
} | ||
return params, 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,116 @@ | ||
package lab8 | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os" | ||
"strings" | ||
) | ||
|
||
func CreateFile(filename string) (string, error) { | ||
if _, err := os.Stat(filename); err == nil { | ||
return "", fmt.Errorf("файл %s уже существует", filename) | ||
} else if !os.IsNotExist(err) { | ||
return "", fmt.Errorf("ошибка проверки существования файла: %w", err) | ||
} | ||
file, err := os.Create(filename) | ||
if err != nil { | ||
return "", fmt.Errorf("ошибка создания файла: %w", err) | ||
} | ||
defer file.Close() | ||
return filename, nil | ||
} | ||
|
||
func WriteToFile(filepath string, content string) error { | ||
file, err := os.OpenFile(filepath, os.O_APPEND|os.O_WRONLY, 0644) | ||
if err != nil { | ||
return fmt.Errorf("ошибка открытия файла для записи: %w", err) | ||
} | ||
defer file.Close() | ||
|
||
_, err = file.WriteString(content) | ||
if err != nil { | ||
return fmt.Errorf("ошибка записи в файл: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
func ReadFile(filepath string) (string, error) { | ||
fileData, err := os.ReadFile(filepath) | ||
if err != nil { | ||
return "", fmt.Errorf("ошибка чтения файла: %w", err) | ||
} | ||
return string(fileData), nil | ||
} | ||
|
||
func SearchInFile(filedata string, searchText string) bool { | ||
return strings.Contains(filedata, searchText) | ||
} | ||
|
||
func GetUserInput() (string, int, string, string, string) { | ||
reader := bufio.NewReader(os.Stdin) | ||
|
||
fmt.Print("Введите имя: ") | ||
name, _ := reader.ReadString('\n') | ||
name = strings.TrimSpace(name) | ||
|
||
fmt.Print("Введите возраст: ") | ||
var age int | ||
fmt.Scanf("%d\n", &age) | ||
|
||
fmt.Print("Введите город: ") | ||
city, _ := reader.ReadString('\n') | ||
city = strings.TrimSpace(city) | ||
|
||
fmt.Print("Введите институт, в котором вы учитесь: ") | ||
university, _ := reader.ReadString('\n') | ||
university = strings.TrimSpace(university) | ||
|
||
fmt.Print("Введите любой текст: ") | ||
additionalText, _ := reader.ReadString('\n') | ||
additionalText = strings.TrimSpace(additionalText) | ||
|
||
return name, age, city, university, additionalText | ||
} | ||
|
||
func RunFileLab() { | ||
reader := bufio.NewReader(os.Stdin) | ||
fmt.Print("Введите имя файла: ") | ||
filename, _ := reader.ReadString('\n') | ||
filename = strings.TrimSpace(filename) | ||
|
||
filePath, err := CreateFile(filename) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
name, age, city, university, additionalText := GetUserInput() | ||
|
||
content := fmt.Sprintf("Имя: %s\nВозраст: %d\nГород: %s\nУниверситет: %s\nДополнительный текст: %s\n", name, age, city, university, additionalText) | ||
err = WriteToFile(filePath, content) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Println("Данные успешно записаны в файл", filename) | ||
|
||
fileData, err := ReadFile(filePath) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
fmt.Println("Содержимое файла:", fileData) | ||
|
||
var searchText string | ||
fmt.Print("Введите текст для поиска: ") | ||
searchText, _ = bufio.NewReader(os.Stdin).ReadString('\n') | ||
searchText = strings.TrimSpace(searchText) | ||
|
||
if SearchInFile(fileData, searchText) { | ||
fmt.Println("Текст найден в файле") | ||
} else { | ||
fmt.Println("Текст не найден в файле") | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
def summ(a: int, b: int) -> int: | ||
return a + b | ||
|
||
|