From 88a3d0ebbd8b035147f3d79cc67b908943c4fc62 Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Sun, 1 Dec 2024 20:22:35 +0300 Subject: [PATCH 01/28] Add files via upload --- golang/lab7/Clothes.go | 0 golang/lab7/HouseholdGoods.go | 0 golang/lab7/PetFood.go | 0 golang/lab7/lab7.go | 46 +++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 golang/lab7/Clothes.go create mode 100644 golang/lab7/HouseholdGoods.go create mode 100644 golang/lab7/PetFood.go create mode 100644 golang/lab7/lab7.go diff --git a/golang/lab7/Clothes.go b/golang/lab7/Clothes.go new file mode 100644 index 00000000..e69de29b diff --git a/golang/lab7/HouseholdGoods.go b/golang/lab7/HouseholdGoods.go new file mode 100644 index 00000000..e69de29b diff --git a/golang/lab7/PetFood.go b/golang/lab7/PetFood.go new file mode 100644 index 00000000..e69de29b diff --git a/golang/lab7/lab7.go b/golang/lab7/lab7.go new file mode 100644 index 00000000..4515d510 --- /dev/null +++ b/golang/lab7/lab7.go @@ -0,0 +1,46 @@ +package lab7 + +import "fmt" + +type Product interface { + GetDescription() + GetPrice() float64 + ApplyDiscount(discount float64) + SetNewPrice(newPrice float64) + SetNewDescription(newDescription string) +} + +func CalculatePrice(list []Product) float64 { + var sum float64 = 0 + for _, price := range list { + sum += price.GetPrice() + } + return sum +} + +func RunLab7() { + var CatFood Product = &PetFood{"Orijen Cat&Kitten Grin Free", "Orijen", 9900} + var Microwave_oven Product = &HouseholdGoods{"Hotpoint MWHA 201", 10490} + var Dress Product = &Clothes{"гипюровое платье", "полиэстера", "DStrend", 5983} + + CatFood.GetDescription() + Microwave_oven.GetDescription() + Dress.GetDescription() + + var purchase []Product = []Product{CatFood, Microwave_oven, Dress} + sum := CalculatePrice(purchase) + fmt.Println("Общая стоимость списка товаров:", sum) + + CatFood.SetNewPrice(9400) + Microwave_oven.SetNewDescription("Samsung") + Microwave_oven.ApplyDiscount(0.1) + Dress.ApplyDiscount(0.2) + Dress.SetNewDescription("хлопка") + + CatFood.GetDescription() + Microwave_oven.GetDescription() + Dress.GetDescription() + + sum = CalculatePrice(purchase) + fmt.Println("Общая стоимость списка товаров с учетом скидок:", sum) +} From d04c3575a3e032c6905a786c03beaa105cfea455 Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Sun, 1 Dec 2024 20:23:34 +0300 Subject: [PATCH 02/28] Update Clothes.go --- golang/lab7/Clothes.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/golang/lab7/Clothes.go b/golang/lab7/Clothes.go index e69de29b..9bbc1040 100644 --- a/golang/lab7/Clothes.go +++ b/golang/lab7/Clothes.go @@ -0,0 +1,30 @@ +package lab7 + +import "fmt" + +type Clothes struct { + Description string + Fabric string + Brand string + Price float64 +} + +func (f Clothes) GetDescription() { + fmt.Println("Это", f.Description, "из", f.Fabric, "от бренда", f.Brand ,"стоимостью", f.Price) +} + +func (f Clothes) GetPrice() float64 { + return f.Price +} + +func (f *Clothes) ApplyDiscount(x float64) { + (*f).Price = (f.Price) * (x) +} + +func (f *Clothes) SetNewPrice(x float64) { + (*f).Price = x +} + +func (f *Clothes) SetNewDescription(x string) { + (*f).Fabric = x +} From d974fb3d9cf7672a70f2c420631b3ec218b441a0 Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Sun, 1 Dec 2024 20:24:07 +0300 Subject: [PATCH 03/28] Update lab7 --- golang/lab7/HouseholdGoods.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/golang/lab7/HouseholdGoods.go b/golang/lab7/HouseholdGoods.go index e69de29b..b662889c 100644 --- a/golang/lab7/HouseholdGoods.go +++ b/golang/lab7/HouseholdGoods.go @@ -0,0 +1,28 @@ +package lab7 + +import "fmt" + +type HouseholdGoods struct { + Name string + Price float64 +} + +func (f HouseholdGoods) GetDescription() { + fmt.Println("Микроволновая печь", f.Name, "стоимостью", f.Price) +} + +func (f HouseholdGoods) GetPrice() float64 { + return f.Price +} + +func (f *HouseholdGoods) ApplyDiscount(x float64) { + (*f).Price = (f.Price) * (x) +} + +func (f *HouseholdGoods) SetNewPrice(x float64) { + (*f).Price = x +} + +func (f *HouseholdGoods) SetNewDescription(x string) { + (*f).Name = x +} From 82251a93003792998938da748a81038fa9c3c93c Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Sun, 1 Dec 2024 20:24:29 +0300 Subject: [PATCH 04/28] Update lab7 --- golang/lab7/PetFood.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/golang/lab7/PetFood.go b/golang/lab7/PetFood.go index e69de29b..a960f1be 100644 --- a/golang/lab7/PetFood.go +++ b/golang/lab7/PetFood.go @@ -0,0 +1,29 @@ +package lab7 + +import "fmt" + +type PetFood struct { + Name string + Brand string + Price float64 +} + +func (f PetFood) GetDescription() { + fmt.Println("Корм для кошек", f.Name, "от бренда", f.Brand, "он стоит", f.Price) +} + +func (f PetFood) GetPrice() float64 { + return f.Price +} + +func (f *PetFood) ApplyDiscount(x float64) { + (*f).Price = (f.Price) * (x) +} + +func (f *PetFood) SetNewPrice(x float64) { + (*f).Price = x +} + +func (f *PetFood) SetNewDescription(x string) { + (*f).Name = x +} From 3de0a0ff919988b61b5af24e27b4f26460ee879b Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Sun, 1 Dec 2024 20:25:38 +0300 Subject: [PATCH 05/28] Update main.go --- golang/main.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/golang/main.go b/golang/main.go index 74f53540..f2e206bf 100644 --- a/golang/main.go +++ b/golang/main.go @@ -3,12 +3,14 @@ package main import ( "isuct.ru/informatics2022/lab4" "isuct.ru/informatics2022/lab6" + "isuct.ru/informatics2022/lab7" "fmt" ) func main() { Lab4.RunLab4() lab6.RunLab6() + lab7.RunLab7() fmt.Println("Istomina_Elena_Sergeevna") } From 19cd7404455fbc9bbf7d6ee8c3006e9359152a36 Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Sun, 1 Dec 2024 20:33:53 +0300 Subject: [PATCH 06/28] Update lab7.go --- golang/lab7/lab7.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/golang/lab7/lab7.go b/golang/lab7/lab7.go index 4515d510..4dad1c4d 100644 --- a/golang/lab7/lab7.go +++ b/golang/lab7/lab7.go @@ -42,5 +42,5 @@ func RunLab7() { Dress.GetDescription() sum = CalculatePrice(purchase) - fmt.Println("Общая стоимость списка товаров с учетом скидок:", sum) + fmt.Println("Общая стоимость списка товаров с учетом всех скидок:", sum) } From 201ddbf53200a97677aaa628f8ab201f13e201ff Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Fri, 20 Dec 2024 10:35:58 +0300 Subject: [PATCH 07/28] Update lab7 --- golang/lab7/PetFood.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/golang/lab7/PetFood.go b/golang/lab7/PetFood.go index a960f1be..c137fa54 100644 --- a/golang/lab7/PetFood.go +++ b/golang/lab7/PetFood.go @@ -2,28 +2,28 @@ package lab7 import "fmt" -type PetFood struct { +type CatFood struct { Name string Brand string Price float64 } -func (f PetFood) GetDescription() { +func (f CatFood) GetDescription() { fmt.Println("Корм для кошек", f.Name, "от бренда", f.Brand, "он стоит", f.Price) } -func (f PetFood) GetPrice() float64 { +func (f CatFood) GetPrice() float64 { return f.Price } -func (f *PetFood) ApplyDiscount(x float64) { +func (f *CatFood) ApplyDiscount(x float64) { (*f).Price = (f.Price) * (x) } -func (f *PetFood) SetNewPrice(x float64) { +func (f *CatFood) SetNewPrice(x float64) { (*f).Price = x } -func (f *PetFood) SetNewDescription(x string) { +func (f *CatFood) SetNewDescription(x string) { (*f).Name = x } From fc87ec070b69d81f4ea9a12678a9e83285c279d8 Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Fri, 20 Dec 2024 10:36:51 +0300 Subject: [PATCH 08/28] Update lab7 --- golang/lab7/HouseholdGoods.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/golang/lab7/HouseholdGoods.go b/golang/lab7/HouseholdGoods.go index b662889c..19d0f5ec 100644 --- a/golang/lab7/HouseholdGoods.go +++ b/golang/lab7/HouseholdGoods.go @@ -2,27 +2,27 @@ package lab7 import "fmt" -type HouseholdGoods struct { +type Microwave_oven struct { Name string Price float64 } -func (f HouseholdGoods) GetDescription() { +func (f Microwave_oven) GetDescription() { fmt.Println("Микроволновая печь", f.Name, "стоимостью", f.Price) } -func (f HouseholdGoods) GetPrice() float64 { +func (f Microwave_oven) GetPrice() float64 { return f.Price } -func (f *HouseholdGoods) ApplyDiscount(x float64) { +func (f *Microwave_oven) ApplyDiscount(x float64) { (*f).Price = (f.Price) * (x) } -func (f *HouseholdGoods) SetNewPrice(x float64) { +func (f *Microwave_oven) SetNewPrice(x float64) { (*f).Price = x } -func (f *HouseholdGoods) SetNewDescription(x string) { +func (f *Microwave_oven) SetNewDescription(x string) { (*f).Name = x } From d193052384a5bd741c80e3dfdae814441b588333 Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Fri, 20 Dec 2024 10:37:21 +0300 Subject: [PATCH 09/28] Update lab7 --- golang/lab7/Clothes.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/golang/lab7/Clothes.go b/golang/lab7/Clothes.go index 9bbc1040..b03561f2 100644 --- a/golang/lab7/Clothes.go +++ b/golang/lab7/Clothes.go @@ -2,29 +2,29 @@ package lab7 import "fmt" -type Clothes struct { +type Dress struct { Description string Fabric string Brand string Price float64 } -func (f Clothes) GetDescription() { +func (f Dress) GetDescription() { fmt.Println("Это", f.Description, "из", f.Fabric, "от бренда", f.Brand ,"стоимостью", f.Price) } -func (f Clothes) GetPrice() float64 { +func (f Dress) GetPrice() float64 { return f.Price } -func (f *Clothes) ApplyDiscount(x float64) { +func (f *Dress) ApplyDiscount(x float64) { (*f).Price = (f.Price) * (x) } -func (f *Clothes) SetNewPrice(x float64) { +func (f *Dress) SetNewPrice(x float64) { (*f).Price = x } -func (f *Clothes) SetNewDescription(x string) { +func (f *Dress) SetNewDescription(x string) { (*f).Fabric = x } From dc4a0997f3d19f7dfa27af2a9614cb7971151f74 Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Fri, 20 Dec 2024 10:37:52 +0300 Subject: [PATCH 10/28] Update lab7.go --- golang/lab7/lab7.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/golang/lab7/lab7.go b/golang/lab7/lab7.go index 4dad1c4d..713b155e 100644 --- a/golang/lab7/lab7.go +++ b/golang/lab7/lab7.go @@ -19,9 +19,9 @@ func CalculatePrice(list []Product) float64 { } func RunLab7() { - var CatFood Product = &PetFood{"Orijen Cat&Kitten Grin Free", "Orijen", 9900} - var Microwave_oven Product = &HouseholdGoods{"Hotpoint MWHA 201", 10490} - var Dress Product = &Clothes{"гипюровое платье", "полиэстера", "DStrend", 5983} + var CatFood Product = &CatFood{"Orijen Cat&Kitten Grin Free", "Orijen", 9900} + var Microwave_oven Product = &Microwave_oven{"Hotpoint MWHA 201", 10490} + var Dress Product = &Dress{"гипюровое платье", "полиэстера", "DStrend", 5983} CatFood.GetDescription() Microwave_oven.GetDescription() From 0119a470ff87bf876cadf85f4389017e20915029 Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Fri, 27 Dec 2024 23:23:33 +0300 Subject: [PATCH 11/28] Add files via upload --- golang/lab8/lab8.go | 83 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 golang/lab8/lab8.go diff --git a/golang/lab8/lab8.go b/golang/lab8/lab8.go new file mode 100644 index 00000000..0251aa61 --- /dev/null +++ b/golang/lab8/lab8.go @@ -0,0 +1,83 @@ +package lab8 + +import ( + "fmt" + "io" + "os" + "strings" +) + +func CreateNewFile(name string) { + file, err := os.Create(name) + if err != nil { + panic(err) + } + defer file.Close() +} + +func EditFile(name string, count int) { + var value string + file, err := os.OpenFile(name, os.O_RDWR, 0666) + if err != nil { + panic(err) + } + defer file.Close() + for i := 1; i <= count; i++ { + fmt.Print("Добавление в файл: ") + fmt.Fscan(os.Stdin, &value) + file.WriteString(value + "\n") + } +} + +func ReadFile(name string) []string { + var arr []string + file, err := os.Open(name) + if err != nil { + panic(err) + } + defer file.Close() + for { + data := make([]byte, 64) + for { + n, err := file.Read(data) + if err == io.EOF { + break + } + arr = append(arr, string(data[:n])) + break + } + return arr + } +} + +func SearchInFile(name string, ValueFile string) { + arr := strings.Split(ReadFile(name)[0], "\n") + for _, value := range arr { + if value == ValueFile { + fmt.Println("Значение в файле найдено") + break + } + } +} + +func RunLab8() []string { + var NameFile string + fmt.Print("Введите название файла: ") + fmt.Fscan(os.Stdin, &NameFile) + CreateNewFile(NameFile) + + var Count int + fmt.Print("Введите сколько значений хотите занести в файл: ") + fmt.Fscan(os.Stdin, &Count) + EditFile(NameFile, Count) + + arr := strings.Split(ReadFile(NameFile)[0], "\n") + arr = arr[0 : len(arr)-1] + + var Search string + fmt.Print("Какое значение вы хотите найти в файле: ") + fmt.Fscan(os.Stdin, &Search) + SearchInFile(NameFile, Search) + + return arr +} From dfbcb458e76070325bab00c02b7d735dd76c0593 Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Fri, 27 Dec 2024 23:24:07 +0300 Subject: [PATCH 12/28] Update lab8.go --- golang/lab8/lab8.go | 1 + 1 file changed, 1 insertion(+) diff --git a/golang/lab8/lab8.go b/golang/lab8/lab8.go index 0251aa61..ac046b8b 100644 --- a/golang/lab8/lab8.go +++ b/golang/lab8/lab8.go @@ -60,6 +60,7 @@ func SearchInFile(name string, ValueFile string) { } } + func RunLab8() []string { var NameFile string fmt.Print("Введите название файла: ") From 15b6c4334c3964d304ee249aaecaa885eae459a9 Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Fri, 27 Dec 2024 23:28:27 +0300 Subject: [PATCH 13/28] Update lab8 --- golang/lab4/Calculate.go | 48 +++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/golang/lab4/Calculate.go b/golang/lab4/Calculate.go index 97b0ebf1..e3e0c040 100644 --- a/golang/lab4/Calculate.go +++ b/golang/lab4/Calculate.go @@ -1,8 +1,11 @@ -package Lab4 +package lab4 import ( - "math" "fmt" + "math" + "strconv" + + "isuct.ru/informatics2022/lab8" ) func Calculate(a,b,x float64) float64 { @@ -18,19 +21,42 @@ func TaskA(a, b, x1, x2, dx float64) []float64 { return y } -func TaskB(a float64, b float64, x[5] float64) []float64 { +func TaskB(a float64, b float64, x[] float64) []float64 { var y []float64 + var arr []float64 for _, value := range x { - y = append(y, Calculate(a,b,value)) + arr = append(arr, Calculate(a,b, value)) + } + return arr +} + +func PrintValue(Values []float64) { + for _, value := range Values { + fmt.Println(value) } - return y } +func ReadFileTask4() []float64 { + fmt.Println("Введите X1, X2, dX для задачи A и список значений для задачи B") + arr := lab8.RunLab8() + var numbers []float64 + for _, values := range arr { + value, _ := strconv.ParseFloat(values, 64) + numbers = append(numbers, value) + } + return numbers +} + + func RunLab4 () { - a := 1.1 - b := 0.09 - - fmt.Println(TaskA(a,b,1.2,2.2,0.2)) - var s = [5]float64{1.21,1.76,2.53,3.48,4.52} - fmt.Println(TaskB(a, b, s)) + const a = 1.1 + const b = 0.09 + arr := ReadFileTask4() + slice := arr[3:] + + ValuesA := TaskA(a, b, arr[0], arr[1], arr[2]) + ValuesB := TaskB(a, b, slice) + + PrintValue(ValuesA) + PrintValue(ValuesB) } From f2d46cd1d6e737234775d7c8bfd4987c6efdfcaa Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Fri, 27 Dec 2024 23:35:22 +0300 Subject: [PATCH 14/28] Update lab8.go --- golang/lab4/Calculate.go | 1 - 1 file changed, 1 deletion(-) diff --git a/golang/lab4/Calculate.go b/golang/lab4/Calculate.go index e3e0c040..76157df0 100644 --- a/golang/lab4/Calculate.go +++ b/golang/lab4/Calculate.go @@ -22,7 +22,6 @@ func TaskA(a, b, x1, x2, dx float64) []float64 { } func TaskB(a float64, b float64, x[] float64) []float64 { - var y []float64 var arr []float64 for _, value := range x { arr = append(arr, Calculate(a,b, value)) From debe2ff81133571a454ae607350928d8bcfe7ac4 Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Fri, 27 Dec 2024 23:39:12 +0300 Subject: [PATCH 15/28] Update main.go --- golang/main.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/golang/main.go b/golang/main.go index f2e206bf..e58bc2aa 100644 --- a/golang/main.go +++ b/golang/main.go @@ -1,14 +1,12 @@ package main import ( - "isuct.ru/informatics2022/lab4" "isuct.ru/informatics2022/lab6" "isuct.ru/informatics2022/lab7" "fmt" ) func main() { - Lab4.RunLab4() lab6.RunLab6() lab7.RunLab7() From 37c0e49d52c6d0e85825620f59e3439dc43bb41f Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Sat, 28 Dec 2024 00:56:37 +0300 Subject: [PATCH 16/28] Update main.go --- golang/main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/golang/main.go b/golang/main.go index e58bc2aa..508994ba 100644 --- a/golang/main.go +++ b/golang/main.go @@ -9,6 +9,7 @@ import ( func main() { lab6.RunLab6() lab7.RunLab7() + lab8.RunLab8() fmt.Println("Istomina_Elena_Sergeevna") } From 9d1365e0db98187c2ade77c4eaf9218c66297d27 Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Sat, 28 Dec 2024 01:00:56 +0300 Subject: [PATCH 17/28] Update main.go --- golang/main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/golang/main.go b/golang/main.go index 508994ba..b034dc82 100644 --- a/golang/main.go +++ b/golang/main.go @@ -3,6 +3,7 @@ package main import ( "isuct.ru/informatics2022/lab6" "isuct.ru/informatics2022/lab7" + "isuct.ru/informatics2022/lab8" "fmt" ) From 7a7518f2b0d8300aafc0f850adece39a3958921f Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Sat, 28 Dec 2024 01:12:53 +0300 Subject: [PATCH 18/28] update lab8 --- golang/lab8/lab8-1.go | 52 +++++++++++++++++++++++++++++++++++++++++++ golang/lab8/lab8-2.go | 0 2 files changed, 52 insertions(+) create mode 100644 golang/lab8/lab8-1.go create mode 100644 golang/lab8/lab8-2.go diff --git a/golang/lab8/lab8-1.go b/golang/lab8/lab8-1.go new file mode 100644 index 00000000..aa0d9040 --- /dev/null +++ b/golang/lab8/lab8-1.go @@ -0,0 +1,52 @@ +package lab8 + +import ( + "bufio" + "fmt" + "os" + "strconv" +) + +type Parameters struct { + A float64 + B float64 + x1 float64 + x2 float64 + dx float64 + slice []float64 +} + +func ReadFromFile(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], + x1: values[2], + x2: values[3], + dx: values[4], + slice: values[5:], + } + return params, nil +} diff --git a/golang/lab8/lab8-2.go b/golang/lab8/lab8-2.go new file mode 100644 index 00000000..e69de29b From e78ab84c93c4e0128aa6946b29fcb55291d1de67 Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Sat, 28 Dec 2024 01:14:03 +0300 Subject: [PATCH 19/28] Delete golang/lab8/lab8-1.go --- golang/lab8/lab8-1.go | 52 ------------------------------------------- 1 file changed, 52 deletions(-) delete mode 100644 golang/lab8/lab8-1.go diff --git a/golang/lab8/lab8-1.go b/golang/lab8/lab8-1.go deleted file mode 100644 index aa0d9040..00000000 --- a/golang/lab8/lab8-1.go +++ /dev/null @@ -1,52 +0,0 @@ -package lab8 - -import ( - "bufio" - "fmt" - "os" - "strconv" -) - -type Parameters struct { - A float64 - B float64 - x1 float64 - x2 float64 - dx float64 - slice []float64 -} - -func ReadFromFile(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], - x1: values[2], - x2: values[3], - dx: values[4], - slice: values[5:], - } - return params, nil -} From 8a370f5052fae5bbd04c84d181c0e3177be85363 Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Sat, 28 Dec 2024 01:14:52 +0300 Subject: [PATCH 20/28] Update lab8_1.go --- golang/lab8/lab8.go | 84 ------------------------------------------- golang/lab8/lab8_1.go | 52 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 84 deletions(-) delete mode 100644 golang/lab8/lab8.go create mode 100644 golang/lab8/lab8_1.go diff --git a/golang/lab8/lab8.go b/golang/lab8/lab8.go deleted file mode 100644 index ac046b8b..00000000 --- a/golang/lab8/lab8.go +++ /dev/null @@ -1,84 +0,0 @@ -package lab8 - -import ( - "fmt" - "io" - "os" - "strings" -) - -func CreateNewFile(name string) { - file, err := os.Create(name) - if err != nil { - panic(err) - } - defer file.Close() -} - -func EditFile(name string, count int) { - var value string - file, err := os.OpenFile(name, os.O_RDWR, 0666) - if err != nil { - panic(err) - } - defer file.Close() - for i := 1; i <= count; i++ { - fmt.Print("Добавление в файл: ") - fmt.Fscan(os.Stdin, &value) - file.WriteString(value + "\n") - } -} - -func ReadFile(name string) []string { - var arr []string - file, err := os.Open(name) - if err != nil { - panic(err) - } - defer file.Close() - for { - data := make([]byte, 64) - for { - n, err := file.Read(data) - if err == io.EOF { - break - } - arr = append(arr, string(data[:n])) - break - } - return arr - } -} - -func SearchInFile(name string, ValueFile string) { - arr := strings.Split(ReadFile(name)[0], "\n") - for _, value := range arr { - if value == ValueFile { - fmt.Println("Значение в файле найдено") - break - } - } -} - - -func RunLab8() []string { - var NameFile string - fmt.Print("Введите название файла: ") - fmt.Fscan(os.Stdin, &NameFile) - CreateNewFile(NameFile) - - var Count int - fmt.Print("Введите сколько значений хотите занести в файл: ") - fmt.Fscan(os.Stdin, &Count) - EditFile(NameFile, Count) - - arr := strings.Split(ReadFile(NameFile)[0], "\n") - arr = arr[0 : len(arr)-1] - - var Search string - fmt.Print("Какое значение вы хотите найти в файле: ") - fmt.Fscan(os.Stdin, &Search) - SearchInFile(NameFile, Search) - - return arr -} diff --git a/golang/lab8/lab8_1.go b/golang/lab8/lab8_1.go new file mode 100644 index 00000000..aa0d9040 --- /dev/null +++ b/golang/lab8/lab8_1.go @@ -0,0 +1,52 @@ +package lab8 + +import ( + "bufio" + "fmt" + "os" + "strconv" +) + +type Parameters struct { + A float64 + B float64 + x1 float64 + x2 float64 + dx float64 + slice []float64 +} + +func ReadFromFile(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], + x1: values[2], + x2: values[3], + dx: values[4], + slice: values[5:], + } + return params, nil +} From f335374cc39a7369392dbee867f525433ba409aa Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Sat, 28 Dec 2024 01:15:40 +0300 Subject: [PATCH 21/28] Update lab8_2.go --- golang/lab8/lab8-2.go | 0 golang/lab8/lab8_2.go | 77 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) delete mode 100644 golang/lab8/lab8-2.go create mode 100644 golang/lab8/lab8_2.go diff --git a/golang/lab8/lab8-2.go b/golang/lab8/lab8-2.go deleted file mode 100644 index e69de29b..00000000 diff --git a/golang/lab8/lab8_2.go b/golang/lab8/lab8_2.go new file mode 100644 index 00000000..a28cb7dd --- /dev/null +++ b/golang/lab8/lab8_2.go @@ -0,0 +1,77 @@ +package lab8 + +import ( + "fmt" + "os" + "strings" +) + +func CreateFile(name string) { + file, err := os.Create(name) + if err != nil { + panic(err) + } + defer file.Close() +} + + +func ReadFile(name string) []string { + var arr []string + file, err := os.Open(name) + if err != nil { + panic(err) + } + defer file.Close() + for { + data := make([]byte, 64) + for { + n, err := file.Read(data) + if err == io.EOF { + break + } + arr = append(arr, string(data[:n])) + break + } + return arr + } +} + +func WriteInFile(name string, count int) { + var value string + file, err := os.OpenFile(name, os.O_RDWR, 0666) + if err != nil { + panic(err) + } + defer file.Close() + for i := 1; i <= count; i++ { + fmt.Print("Введите данные: ") + fmt.Fscan(os.Stdin, &value) + file.WriteString(value + "\n") + } +} + +func SearchInFile(data string, search string) bool { + return strings.Contains(data, search) +} + +func RunLab8() []string { + var NameFile string + fmt.Print("Введите название файла: ") + fmt.Fscan(os.Stdin, &NameFile) + CreateFile(NameFile) + + var Count int + fmt.Print("Cколько значений вы хотите занести в файл: ") + fmt.Fscan(os.Stdin, &Count) + WriteInFile(NameFile, Count) + + arr := strings.Split(ReadFile(NameFile)[0], "\n") + arr = arr[0 : len(arr)-1] + + var Search string + fmt.Print("Какое значение вы хотите найти в файле: ") + fmt.Fscan(os.Stdin, &Search) + SearchInFile(NameFile, Search) + + return arr +} From d02a28f88a110c55f2b78108f4137b0178350624 Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Sat, 28 Dec 2024 01:18:35 +0300 Subject: [PATCH 22/28] Update lab8_2.go --- golang/lab8/lab8_2.go | 1 + 1 file changed, 1 insertion(+) diff --git a/golang/lab8/lab8_2.go b/golang/lab8/lab8_2.go index a28cb7dd..2621484c 100644 --- a/golang/lab8/lab8_2.go +++ b/golang/lab8/lab8_2.go @@ -3,6 +3,7 @@ package lab8 import ( "fmt" "os" + "io" "strings" ) From b386c73d05092b203c1d7d037d4113cc08d66e81 Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Sat, 28 Dec 2024 09:28:57 +0300 Subject: [PATCH 23/28] Update lab8_1.go --- golang/lab8/lab8_1.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/golang/lab8/lab8_1.go b/golang/lab8/lab8_1.go index aa0d9040..ee60030a 100644 --- a/golang/lab8/lab8_1.go +++ b/golang/lab8/lab8_1.go @@ -7,7 +7,7 @@ import ( "strconv" ) -type Parameters struct { +type Params struct { A float64 B float64 x1 float64 @@ -16,10 +16,10 @@ type Parameters struct { slice []float64 } -func ReadFromFile(filename string) (Parameters, error) { +func LoadParameters(filename string) (Params, error) { file, err := os.Open(filename) if err != nil { - return Parameters{}, fmt.Errorf("Ошибка открытия: %w", err) + return Params{}, fmt.Errorf("Не удалось открыть файл: %w", err) } defer file.Close() @@ -29,18 +29,18 @@ func ReadFromFile(filename string) (Parameters, error) { line := scanner.Text() num, err := strconv.ParseFloat(line, 64) if err != nil { - return Parameters{}, fmt.Errorf("ошибка парсинга float '%s': %w", line, err) + return Params{}, fmt.Errorf("Ошибка преобразования строки '%s' в float: %w", line, err) } values = append(values, num) } if err := scanner.Err(); err != nil { - return Parameters{}, fmt.Errorf("ошибка чтения файла: %w", err) + return Params{}, fmt.Errorf("ошибка при чтении файла: %w", err) } if len(values) < 6 { - return Parameters{}, fmt.Errorf("Недостаточно значений. Введите еще раз") + return Params{}, fmt.Errorf("Недостаточно значений. Введите еще раз") } - params := Parameters{ + parameters := Params{ A: values[0], B: values[1], x1: values[2], @@ -48,5 +48,5 @@ func ReadFromFile(filename string) (Parameters, error) { dx: values[4], slice: values[5:], } - return params, nil + return parameters, nil } From a02f097d0b8304a69d140b9bf880f66ba84768a9 Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Sat, 28 Dec 2024 09:40:36 +0300 Subject: [PATCH 24/28] Update lab7.go --- golang/lab7/lab7.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/golang/lab7/lab7.go b/golang/lab7/lab7.go index 713b155e..0e6b8a89 100644 --- a/golang/lab7/lab7.go +++ b/golang/lab7/lab7.go @@ -6,8 +6,8 @@ type Product interface { GetDescription() GetPrice() float64 ApplyDiscount(discount float64) - SetNewPrice(newPrice float64) - SetNewDescription(newDescription string) + UpdatePrice(newPrice float64) + UpdateDescription(newDescription string) } func CalculatePrice(list []Product) float64 { @@ -28,19 +28,19 @@ func RunLab7() { Dress.GetDescription() var purchase []Product = []Product{CatFood, Microwave_oven, Dress} - sum := CalculatePrice(purchase) - fmt.Println("Общая стоимость списка товаров:", sum) + totalCost := CalculatePrice(purchase) + fmt.Println("Общая стоимость списка товаров:", totalCost) - CatFood.SetNewPrice(9400) - Microwave_oven.SetNewDescription("Samsung") + CatFood.UpdatePrice(9400) + Microwave_oven.UpdateDescription("Samsung") Microwave_oven.ApplyDiscount(0.1) Dress.ApplyDiscount(0.2) - Dress.SetNewDescription("хлопка") + Dress.UpdateDescription("хлопка") CatFood.GetDescription() Microwave_oven.GetDescription() Dress.GetDescription() - sum = CalculatePrice(purchase) - fmt.Println("Общая стоимость списка товаров с учетом всех скидок:", sum) + TotalCost = CalculatePrice(purchase) + fmt.Println("Общая стоимость списка товаров с учетом всех скидок:", totalCost) } From c52e1d32402c273ed12ad4c51c71bd4705414094 Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Sat, 28 Dec 2024 09:41:09 +0300 Subject: [PATCH 25/28] Update lab7.go --- golang/lab7/HouseholdGoods.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/golang/lab7/HouseholdGoods.go b/golang/lab7/HouseholdGoods.go index 19d0f5ec..79c8e897 100644 --- a/golang/lab7/HouseholdGoods.go +++ b/golang/lab7/HouseholdGoods.go @@ -19,10 +19,10 @@ func (f *Microwave_oven) ApplyDiscount(x float64) { (*f).Price = (f.Price) * (x) } -func (f *Microwave_oven) SetNewPrice(x float64) { +func (f *Microwave_oven) UpdatePrice(x float64) { (*f).Price = x } -func (f *Microwave_oven) SetNewDescription(x string) { +func (f *Microwave_oven) UpdateDescription(x string) { (*f).Name = x } From 6876302511bdae3cdd2a4128792efb11e2773554 Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Sat, 28 Dec 2024 09:41:47 +0300 Subject: [PATCH 26/28] Update lab7.go --- golang/lab7/Clothes.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/golang/lab7/Clothes.go b/golang/lab7/Clothes.go index b03561f2..d2c8acaa 100644 --- a/golang/lab7/Clothes.go +++ b/golang/lab7/Clothes.go @@ -21,10 +21,10 @@ func (f *Dress) ApplyDiscount(x float64) { (*f).Price = (f.Price) * (x) } -func (f *Dress) SetNewPrice(x float64) { +func (f *Dress) UpdatePrice(x float64) { (*f).Price = x } -func (f *Dress) SetNewDescription(x string) { +func (f *Dress) UpdateDescription(x string) { (*f).Fabric = x } From ca2c5e6b795e154a747ad92380166470fd947eb9 Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Sat, 28 Dec 2024 09:42:10 +0300 Subject: [PATCH 27/28] Update lab7.go --- golang/lab7/PetFood.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/golang/lab7/PetFood.go b/golang/lab7/PetFood.go index c137fa54..b371e3fb 100644 --- a/golang/lab7/PetFood.go +++ b/golang/lab7/PetFood.go @@ -20,10 +20,10 @@ func (f *CatFood) ApplyDiscount(x float64) { (*f).Price = (f.Price) * (x) } -func (f *CatFood) SetNewPrice(x float64) { +func (f *CatFood) UpdatePrice(x float64) { (*f).Price = x } -func (f *CatFood) SetNewDescription(x string) { +func (f *CatFood) UpdateDescription(x string) { (*f).Name = x } From 61d96f8ee78b53fb801100543fe061cffebe07a5 Mon Sep 17 00:00:00 2001 From: HelenIstomina Date: Sat, 28 Dec 2024 09:44:33 +0300 Subject: [PATCH 28/28] Update lab7.go --- golang/lab7/lab7.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/golang/lab7/lab7.go b/golang/lab7/lab7.go index 0e6b8a89..18441cc0 100644 --- a/golang/lab7/lab7.go +++ b/golang/lab7/lab7.go @@ -41,6 +41,6 @@ func RunLab7() { Microwave_oven.GetDescription() Dress.GetDescription() - TotalCost = CalculatePrice(purchase) + totalCost = CalculatePrice(purchase) fmt.Println("Общая стоимость списка товаров с учетом всех скидок:", totalCost) }