diff --git a/golang/Laba7/book.go b/golang/Laba7/book.go new file mode 100644 index 00000000..62f8946b --- /dev/null +++ b/golang/Laba7/book.go @@ -0,0 +1,31 @@ +package lab7 + +type Book struct { + name string + price float64 + varieties string +} + +func (b *Book) GetName() string { + return b.name +} + +func (b *Book) SetName(NewName string) { + b.name = NewName +} + +func (b *Book) GetPrice() float64 { + return b.price +} + +func (b *Book) SetPrice(NewPrice float64) { + b.price = NewPrice +} + +func (b *Book) ApplyDiscount(discount float64) { + b.price = b.price * (100 - discount) / 100 +} + +func (b *Book) SetVarieties(NewVarieties string) { + b.varieties = NewVarieties +} diff --git a/golang/Laba7/chocolate.go b/golang/Laba7/chocolate.go new file mode 100644 index 00000000..c0c85eef --- /dev/null +++ b/golang/Laba7/chocolate.go @@ -0,0 +1,31 @@ +package lab7 + +type Chocolate struct { + name string + price float64 + brand string +} + +func (ch *Chocolate) GetName() string { + return ch.name +} + +func (ch *Chocolate) SetName(NewName string) { + ch.name = NewName +} + +func (ch *Chocolate) GetPrice() float64 { + return ch.price +} + +func (ch *Chocolate) SetPrice(NewPrice float64) { + ch.price = NewPrice +} + +func (ch *Chocolate) ApplyDiscount(discount float64) { + ch.price = ch.price * (100 - discount) / 100 +} + +func (ch *Chocolate) SetBrand(NewBrand string) { + ch.brand = NewBrand +} diff --git a/golang/Laba7/clothes.go b/golang/Laba7/clothes.go new file mode 100644 index 00000000..9a15a0f5 --- /dev/null +++ b/golang/Laba7/clothes.go @@ -0,0 +1,31 @@ +package lab7 + +type Clothes struct { + name string + price float64 + material string +} + +func (c *Clothes) GetName() string { + return c.name +} + +func (c *Clothes) SetName(NewName string) { + c.name = NewName +} + +func (c *Clothes) GetPrice() float64 { + return c.price +} + +func (c *Clothes) SetPrice(NewPrice float64) { + c.price = NewPrice +} + +func (c *Clothes) ApplyDiscount(discount float64) { + c.price = c.price * (100 - discount) / 100 +} + +func (c *Clothes) SetMaterial(NewMaterial string) { + c.material = NewMaterial +} diff --git a/golang/Laba7/lab7.go b/golang/Laba7/lab7.go new file mode 100644 index 00000000..b481e2b7 --- /dev/null +++ b/golang/Laba7/lab7.go @@ -0,0 +1,44 @@ +package lab7 + +import ( + "fmt" +) + +func CalculationSumProduct(listProducts []Product) string { + var sum float64 = 0 + for _, product := range listProducts { + sum += product.GetPrice() + } + s := fmt.Sprintf("%.2f", sum) + return s +} + +func Laba7() { + var jeans Product = &Clothes{name: "джинсы", price: 3000, material: "полиэстер"} + var chocolate Product = &Chocolate{name: "молочный шоколад", price: 70, brand: "Россия щедрая душа"} + var comic Product = &Book{name: "Sailor Moon", price: 700, varieties: "манга"} + + if c, ok := jeans.(*Clothes); ok { + c.SetMaterial("вискоза") + } else { + fmt.Println("Ошибка приведения типа для Clothes") + } + + if ch, ok := chocolate.(*Chocolate); ok { + ch.SetBrand("Alpen Gold") + } else { + fmt.Println("Ошибка приведения типа для Chocolate") + } + + comic.SetPrice(800) + + listProducts := []Product{jeans, chocolate, comic} + fmt.Printf("Сумма товаров, без учета скидки, равна: %v рублей \n", CalculationSumProduct(listProducts)) + jeans.ApplyDiscount(10) + chocolate.ApplyDiscount(5) + comic.ApplyDiscount(15) + fmt.Printf("Сумма товаров, c учетом скидки, равна: %v рублей \n", CalculationSumProduct(listProducts)) + fmt.Println(jeans) + fmt.Println(chocolate) + fmt.Println(comic) +} diff --git a/golang/Laba7/product.go b/golang/Laba7/product.go new file mode 100644 index 00000000..3d23730c --- /dev/null +++ b/golang/Laba7/product.go @@ -0,0 +1,9 @@ +package lab7 + +type Product interface { + GetName() string + SetName(NewName string) + GetPrice() float64 + SetPrice(NewPrice float64) + ApplyDiscount(discount float64) +} diff --git a/golang/Laba8/input.txt b/golang/Laba8/input.txt new file mode 100644 index 00000000..f18d9f8a --- /dev/null +++ b/golang/Laba8/input.txt @@ -0,0 +1,10 @@ +7.2 +1.3 +1.56 +4.71 +0.63 +2.4 +2.8 +3.9 +4.7 +3.16 \ No newline at end of file diff --git a/golang/Laba8/lab8.go b/golang/Laba8/lab8.go new file mode 100644 index 00000000..6a44e96a --- /dev/null +++ b/golang/Laba8/lab8.go @@ -0,0 +1,28 @@ +package lab8 + +import ( + "fmt" +) + +func Laba8() { + var err error + + err = CreateFile() + if err != nil { + panic(err) + } + err = WriteFile() + if err != nil { + panic(err) + } + text, err := ReadFile() + if err != nil { + panic(err) + } + fmt.Println(text) + + err = task1() + if err != nil { + panic(err) + } +} diff --git a/golang/Laba8/task1.go b/golang/Laba8/task1.go new file mode 100644 index 00000000..7a167462 --- /dev/null +++ b/golang/Laba8/task1.go @@ -0,0 +1,49 @@ +package lab8 + +import ( + "io" + "os" + "strconv" + "strings" + + lab4 "isuct.ru/informatics2022/Laba4" +) + +const PathTask1 = "Laba8/input.txt" + +func task1() error { + file, err := os.Open(PathTask1) + if err != nil { + return err + } + defer file.Close() + + var text string + data := make([]byte, 64) + for { + n, err := file.Read(data) + if err == io.EOF { + break + } + text = string(data[:n]) + } + var result []float64 + Parameters := strings.Split(text, "\r\n") + for _, P := range Parameters { + number, err := strconv.ParseFloat(P, 64) + if err != nil { + return err + } + result = append(result, number) + } + + a := result[0] + b := result[1] + xMin := result[2] + xMax := result[3] + xDelta := result[4] + lab4.CompleteTaskA(a, b, xMin, xMax, xDelta) + lab4.CompleteTaskB(a, b, result[6:]) + + return nil +} diff --git a/golang/Laba8/task2.go b/golang/Laba8/task2.go new file mode 100644 index 00000000..1e87a1dd --- /dev/null +++ b/golang/Laba8/task2.go @@ -0,0 +1,68 @@ +package lab8 + +import ( + "bufio" + "fmt" + "io" + "os" + "strings" +) + +const Path = "Laba8/text.txt" + +func CreateFile() error { + file, err := os.Create(Path) + if err != nil { + return err + } + file.Close() + + return nil +} + +func WriteFile() error { + file, err := os.OpenFile(Path, os.O_WRONLY, 0666) + if err != nil { + return err + } + defer file.Close() + + fmt.Println("Ввидите текст для поиска в файле") + var in *bufio.Reader = bufio.NewReader(os.Stdin) + text, err := in.ReadString('\n') + if err != nil { + return err + } + + file.WriteString(text) + + return nil +} + +func ReadFile() (string, error) { + file, err := os.Open(Path) + if err != nil { + return "", err + } + defer file.Close() + + var text string + data := make([]byte, 64) + for { + n, err := file.Read(data) + if err == io.EOF { + break + } + text = string(data[:n]) + } + return text, nil +} + +func SearchText(searchText string) (bool, error) { + text, err := ReadFile() + if err != nil { + return false, err + } + search := strings.Contains(text, searchText) + return search, nil +} diff --git a/golang/main.go b/golang/main.go index b3231b58..0ba14747 100644 --- a/golang/main.go +++ b/golang/main.go @@ -5,10 +5,14 @@ import ( lab4 "isuct.ru/informatics2022/Laba4" lab6 "isuct.ru/informatics2022/Laba6" + lab7 "isuct.ru/informatics2022/Laba7" + lab8 "isuct.ru/informatics2022/Laba8" ) func main() { fmt.Println("Рындина Ксения Александровна") lab4.CompleteLab4() lab6.Laba6() + lab7.Laba7() + lab8.Laba8() } diff --git a/golang/vendor/modules.txt b/golang/vendor/modules.txt new file mode 100644 index 00000000..d2b40a71 --- /dev/null +++ b/golang/vendor/modules.txt @@ -0,0 +1,2 @@ +# github.com/stretchr/testify v1.8.1 +## explicit