From 01290664ea8b303c7105bb38724d25eb4face4ac Mon Sep 17 00:00:00 2001 From: Agurchic Date: Tue, 21 Jan 2025 17:38:23 +0300 Subject: [PATCH 1/8] Create lab4.go --- golang/lab/lab4.go | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 golang/lab/lab4.go diff --git a/golang/lab/lab4.go b/golang/lab/lab4.go new file mode 100644 index 00000000..a4ee52c7 --- /dev/null +++ b/golang/lab/lab4.go @@ -0,0 +1,54 @@ +package labs + +import ( + "fmt" + "math" +) + +func CalculateY(a, b, x float64) float64 { + return math.Pow((a*x+b), 1.0/3.0) / math.Pow(math.Log10(x), 2) +} + +func TaskA(a, b, xStart, xEnd, step float64) []float64 { + var result []float64 + for x := xStart; x <= xEnd; x += step { + result = append(result, CalculateY(a, b, x)) + } + return result +} + +func TaskB(a, b float64, xValues []float64) []float64 { + var result []float64 + for _, x := range xValues { + result = append(result, CalculateY(a, b, x)) + } + return result +} + +func labs() { + var a, b, xStart, xEnd, step float64 + + a = 0.1 + b = 0.5 + xStart = 0.33 + xEnd = 1.23 + step = 0.18 + var xValues []float64 = []float64{0.5, 0.36, 0.40, 0.62, 0.78} + var resultA []float64 = TaskA(a, b, xStart, xEnd, step) + var resultB []float64 = TaskB(a, b, xValues) + + fmt.Println("Результаты задачи A:") + for i, y := range resultA { + x := xStart + step*float64(i) + fmt.Printf("x = %.2f, y = %.4f\n", x, y) + } + + fmt.Println("\nРезультаты задачи B:") + for i, y := range resultB { + fmt.Printf("x = %.2f, y = %.4f\n", xValues[i], y) + } +} + +func lab4() { + labs() +} From ef9951310941d9f2d0934ff4da801837d722e3e8 Mon Sep 17 00:00:00 2001 From: Agurchic Date: Tue, 21 Jan 2025 17:47:56 +0300 Subject: [PATCH 2/8] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=206=20=D0=B8=207?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- golang/lab/lab6.go | 29 +++++++++++++++++ golang/lab/lab7.go | 80 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 golang/lab/lab6.go create mode 100644 golang/lab/lab7.go diff --git a/golang/lab/lab6.go b/golang/lab/lab6.go new file mode 100644 index 00000000..67aeacea --- /dev/null +++ b/golang/lab/lab6.go @@ -0,0 +1,29 @@ +package tests + +import "fmt" + +type Dog struct { + Name string + Breed string + Age int +} + +func NewDog(name string, breed string, age int) Dog { + return Dog{Name: name, Breed: breed, Age: age} +} +func (d Dog) GetAge() int { + return d.Age +} +func (d *Dog) SetAge(age int) { + d.Age = age +} +func (d Dog) GetInfo() string { + return fmt.Sprintf("Name: %s, Breed: %s, Age: %d", d.Name, d.Breed, d.Age) +} +func inf() { + myDog := NewDog("Buddy", "Labrador", 3) + fmt.Println(myDog.GetInfo()) + fmt.Println("Age:", myDog.GetAge()) + myDog.SetAge(4) + fmt.Println(myDog.GetInfo()) +} diff --git a/golang/lab/lab7.go b/golang/lab/lab7.go new file mode 100644 index 00000000..7f828993 --- /dev/null +++ b/golang/lab/lab7.go @@ -0,0 +1,80 @@ +package labs + +import ( + "fmt" +) + +type Product interface { + GetPrice() float64 + SetPrice(price float64) + ApplyDiscount(percent float64) + GetDetails() string +} + +type Book struct { + title string + author string + price float64 +} + +func (b *Book) GetPrice() float64 { + return b.price +} + +func (b *Book) SetPrice(price float64) { + b.price = price +} + +func (b *Book) ApplyDiscount(percent float64) { + b.price -= b.price * percent / 100 +} + +func (b *Book) GetDetails() string { + return fmt.Sprintf("Book: %s, Author: %s, Price: %.2f", b.title, b.author, b.price) +} + +type Electronics struct { + name string + brand string + price float64 +} + +func (e *Electronics) GetPrice() float64 { + return e.price +} + +func (e *Electronics) SetPrice(price float64) { + e.price = price + + percent := + e.price -= e.price * percent / 100 +} +func (e *Electronics) GetDetails() string { + return fmt.Sprintf("Electronics: %s, Brand: %s, Price: %.2f", e.name, e.brand, e.price) +} +func CalculateTotalPrice(products []Product) float64 { + total := 0.0 + for _, product := range products { + total += product.GetPrice() + } + return total +} + +func main() { + book1 := Book{title: "The Go Programming Language", author: "Alan Donovan", price: 40.0} + book2 := Book{title: "Programming in Go", author: "Mark Summerfield", price: 35.0} + electronics1 := Electronics{name: "iPhone 13", brand: "Apple", price: 1000.0} + + products := []Product{&book1, &book2, &electronics1} + + fmt.Println("Initial Total Price:", CalculateTotalPrice(products)) + + book1.ApplyDiscount(10) + electronics1.SetPrice(900.0) + + fmt.Println("Total Price after discounts:", CalculateTotalPrice(products)) + + for _, product := range products { + fmt.Println(product.GetDetails()) + } +} \ No newline at end of file From 63b8910ce16e1fe77ac06cabae51716ad61220c8 Mon Sep 17 00:00:00 2001 From: Agurchic Date: Wed, 22 Jan 2025 00:01:10 +0300 Subject: [PATCH 3/8] linter --- golang/lab/{ => lab4}/lab4.go | 2 +- golang/lab/{ => lab6}/lab6.go | 0 golang/lab/{ => lab7}/lab7.go | 12 +++++++----- 3 files changed, 8 insertions(+), 6 deletions(-) rename golang/lab/{ => lab4}/lab4.go (98%) rename golang/lab/{ => lab6}/lab6.go (100%) rename golang/lab/{ => lab7}/lab7.go (94%) diff --git a/golang/lab/lab4.go b/golang/lab/lab4/lab4.go similarity index 98% rename from golang/lab/lab4.go rename to golang/lab/lab4/lab4.go index a4ee52c7..46802966 100644 --- a/golang/lab/lab4.go +++ b/golang/lab/lab4/lab4.go @@ -1,4 +1,4 @@ -package labs +package lab4_test import ( "fmt" diff --git a/golang/lab/lab6.go b/golang/lab/lab6/lab6.go similarity index 100% rename from golang/lab/lab6.go rename to golang/lab/lab6/lab6.go diff --git a/golang/lab/lab7.go b/golang/lab/lab7/lab7.go similarity index 94% rename from golang/lab/lab7.go rename to golang/lab/lab7/lab7.go index 7f828993..b1b7c031 100644 --- a/golang/lab/lab7.go +++ b/golang/lab/lab7/lab7.go @@ -34,9 +34,9 @@ func (b *Book) GetDetails() string { } type Electronics struct { - name string - brand string - price float64 + name string + brand string + price float64 } func (e *Electronics) GetPrice() float64 { @@ -45,13 +45,15 @@ func (e *Electronics) GetPrice() float64 { func (e *Electronics) SetPrice(price float64) { e.price = price +} - percent := +func (e *Electronics) ApplyDiscount(percent float64) { e.price -= e.price * percent / 100 } func (e *Electronics) GetDetails() string { return fmt.Sprintf("Electronics: %s, Brand: %s, Price: %.2f", e.name, e.brand, e.price) } + func CalculateTotalPrice(products []Product) float64 { total := 0.0 for _, product := range products { @@ -77,4 +79,4 @@ func main() { for _, product := range products { fmt.Println(product.GetDetails()) } -} \ No newline at end of file +} From 058d692b82e0fccb9bd3b7e185fba81d85a2f683 Mon Sep 17 00:00:00 2001 From: Agurchic Date: Wed, 22 Jan 2025 00:11:43 +0300 Subject: [PATCH 4/8] linter --- golang/lab/lab4/lab4.go | 53 ++++++++------------------------- golang/lab/lab6/lab6.go | 21 +++++-------- golang/lab/lab7/lab7.go | 66 +++++++++++++++-------------------------- 3 files changed, 43 insertions(+), 97 deletions(-) diff --git a/golang/lab/lab4/lab4.go b/golang/lab/lab4/lab4.go index 46802966..63e3c70e 100644 --- a/golang/lab/lab4/lab4.go +++ b/golang/lab/lab4/lab4.go @@ -1,54 +1,25 @@ package lab4_test import ( - "fmt" - "math" + "math" ) func CalculateY(a, b, x float64) float64 { - return math.Pow((a*x+b), 1.0/3.0) / math.Pow(math.Log10(x), 2) + return math.Pow((a*x+b), 1.0/3.0) / math.Pow(math.Log10(x), 2) } func TaskA(a, b, xStart, xEnd, step float64) []float64 { - var result []float64 - for x := xStart; x <= xEnd; x += step { - result = append(result, CalculateY(a, b, x)) - } - return result + var result []float64 + for x := xStart; x <= xEnd; x += step { + result = append(result, CalculateY(a, b, x)) + } + return result } func TaskB(a, b float64, xValues []float64) []float64 { - var result []float64 - for _, x := range xValues { - result = append(result, CalculateY(a, b, x)) - } - return result -} - -func labs() { - var a, b, xStart, xEnd, step float64 - - a = 0.1 - b = 0.5 - xStart = 0.33 - xEnd = 1.23 - step = 0.18 - var xValues []float64 = []float64{0.5, 0.36, 0.40, 0.62, 0.78} - var resultA []float64 = TaskA(a, b, xStart, xEnd, step) - var resultB []float64 = TaskB(a, b, xValues) - - fmt.Println("Результаты задачи A:") - for i, y := range resultA { - x := xStart + step*float64(i) - fmt.Printf("x = %.2f, y = %.4f\n", x, y) - } - - fmt.Println("\nРезультаты задачи B:") - for i, y := range resultB { - fmt.Printf("x = %.2f, y = %.4f\n", xValues[i], y) - } -} - -func lab4() { - labs() + var result []float64 + for _, x := range xValues { + result = append(result, CalculateY(a, b, x)) + } + return result } diff --git a/golang/lab/lab6/lab6.go b/golang/lab/lab6/lab6.go index 67aeacea..5c77e702 100644 --- a/golang/lab/lab6/lab6.go +++ b/golang/lab/lab6/lab6.go @@ -3,27 +3,20 @@ package tests import "fmt" type Dog struct { - Name string - Breed string - Age int + Name string + Breed string + Age int } func NewDog(name string, breed string, age int) Dog { - return Dog{Name: name, Breed: breed, Age: age} + return Dog{Name: name, Breed: breed, Age: age} } func (d Dog) GetAge() int { - return d.Age + return d.Age } func (d *Dog) SetAge(age int) { - d.Age = age + d.Age = age } func (d Dog) GetInfo() string { - return fmt.Sprintf("Name: %s, Breed: %s, Age: %d", d.Name, d.Breed, d.Age) -} -func inf() { - myDog := NewDog("Buddy", "Labrador", 3) - fmt.Println(myDog.GetInfo()) - fmt.Println("Age:", myDog.GetAge()) - myDog.SetAge(4) - fmt.Println(myDog.GetInfo()) + return fmt.Sprintf("Name: %s, Breed: %s, Age: %d", d.Name, d.Breed, d.Age) } diff --git a/golang/lab/lab7/lab7.go b/golang/lab/lab7/lab7.go index b1b7c031..a32f2702 100644 --- a/golang/lab/lab7/lab7.go +++ b/golang/lab/lab7/lab7.go @@ -1,82 +1,64 @@ package labs import ( - "fmt" + "fmt" ) type Product interface { - GetPrice() float64 - SetPrice(price float64) - ApplyDiscount(percent float64) - GetDetails() string + GetPrice() float64 + SetPrice(price float64) + ApplyDiscount(percent float64) + GetDetails() string } type Book struct { - title string - author string - price float64 + title string + author string + price float64 } func (b *Book) GetPrice() float64 { - return b.price + return b.price } func (b *Book) SetPrice(price float64) { - b.price = price + b.price = price } func (b *Book) ApplyDiscount(percent float64) { - b.price -= b.price * percent / 100 + b.price -= b.price * percent / 100 } func (b *Book) GetDetails() string { - return fmt.Sprintf("Book: %s, Author: %s, Price: %.2f", b.title, b.author, b.price) + return fmt.Sprintf("Book: %s, Author: %s, Price: %.2f", b.title, b.author, b.price) } type Electronics struct { - name string - brand string - price float64 + name string + brand string + price float64 } func (e *Electronics) GetPrice() float64 { - return e.price + return e.price } func (e *Electronics) SetPrice(price float64) { - e.price = price + e.price = price } func (e *Electronics) ApplyDiscount(percent float64) { - e.price -= e.price * percent / 100 + e.price -= e.price * percent / 100 } func (e *Electronics) GetDetails() string { - return fmt.Sprintf("Electronics: %s, Brand: %s, Price: %.2f", e.name, e.brand, e.price) + return fmt.Sprintf("Electronics: %s, Brand: %s, Price: %.2f", e.name, e.brand, e.price) } func CalculateTotalPrice(products []Product) float64 { - total := 0.0 - for _, product := range products { - total += product.GetPrice() - } - return total + total := 0.0 + for _, product := range products { + total += product.GetPrice() + } + return total } -func main() { - book1 := Book{title: "The Go Programming Language", author: "Alan Donovan", price: 40.0} - book2 := Book{title: "Programming in Go", author: "Mark Summerfield", price: 35.0} - electronics1 := Electronics{name: "iPhone 13", brand: "Apple", price: 1000.0} - - products := []Product{&book1, &book2, &electronics1} - - fmt.Println("Initial Total Price:", CalculateTotalPrice(products)) - - book1.ApplyDiscount(10) - electronics1.SetPrice(900.0) - - fmt.Println("Total Price after discounts:", CalculateTotalPrice(products)) - - for _, product := range products { - fmt.Println(product.GetDetails()) - } -} From 3f970f593674e2be542d1d51d0e56966c5add4b4 Mon Sep 17 00:00:00 2001 From: Agurchic Date: Wed, 22 Jan 2025 18:11:27 +0300 Subject: [PATCH 5/8] launching programs --- golang/lab/lab4/lab4.go | 54 +++++++++++++++++++++++++--------- golang/lab/lab6/lab6.go | 29 +++++++++++++------ golang/lab/lab7/lab7.go | 64 +++++++++++++++++++++++++---------------- 3 files changed, 101 insertions(+), 46 deletions(-) diff --git a/golang/lab/lab4/lab4.go b/golang/lab/lab4/lab4.go index 63e3c70e..ab3b84d3 100644 --- a/golang/lab/lab4/lab4.go +++ b/golang/lab/lab4/lab4.go @@ -1,25 +1,53 @@ -package lab4_test +package main import ( - "math" + "fmt" + "math" ) func CalculateY(a, b, x float64) float64 { - return math.Pow((a*x+b), 1.0/3.0) / math.Pow(math.Log10(x), 2) + return math.Pow((a*x+b), 1.0/3.0) / math.Pow(math.Log10(x), 2) } func TaskA(a, b, xStart, xEnd, step float64) []float64 { - var result []float64 - for x := xStart; x <= xEnd; x += step { - result = append(result, CalculateY(a, b, x)) - } - return result + var result []float64 + for x := xStart; x <= xEnd; x += step { + result = append(result, CalculateY(a, b, x)) + } + return result } func TaskB(a, b float64, xValues []float64) []float64 { - var result []float64 - for _, x := range xValues { - result = append(result, CalculateY(a, b, x)) - } - return result + var result []float64 + for _, x := range xValues { + result = append(result, CalculateY(a, b, x)) + } + return result +} + +func main() { + a := 2.0 + b := 3.0 + + xStart := 1.0 + xEnd := 5.0 + step := 1.0 + resultsA := TaskA(a, b, xStart, xEnd, step) + fmt.Println("Результаты TaskA:") + for i, y := range resultsA { + fmt.Printf("x = %.2f, y = %.6f\n", xStart+float64(i)*step, y) + } + + fmt.Println() + + xValues := []float64{1.5, 2.5, 3.5, 4.5} + resultsB := TaskB(a, b, xValues) + fmt.Println("Результаты TaskB:") + for i, y := range resultsB { + fmt.Printf("x = %.2f, y = %.6f\n", xValues[i], y) + } + fmt.Println() + x := 3.0 + resultY := CalculateY(a, b, x) + fmt.Printf("Результат CalculateY: x= %.2f, y = %.6f\n", x, resultY) } diff --git a/golang/lab/lab6/lab6.go b/golang/lab/lab6/lab6.go index 5c77e702..a0b5e56f 100644 --- a/golang/lab/lab6/lab6.go +++ b/golang/lab/lab6/lab6.go @@ -1,22 +1,35 @@ -package tests +package main import "fmt" type Dog struct { - Name string - Breed string - Age int + Name string + Breed string + Age int } func NewDog(name string, breed string, age int) Dog { - return Dog{Name: name, Breed: breed, Age: age} + return Dog{Name: name, Breed: breed, Age: age} } func (d Dog) GetAge() int { - return d.Age + return d.Age } func (d *Dog) SetAge(age int) { - d.Age = age + d.Age = age } func (d Dog) GetInfo() string { - return fmt.Sprintf("Name: %s, Breed: %s, Age: %d", d.Name, d.Breed, d.Age) + return fmt.Sprintf("Name: %s, Breed: %s, Age: %d", d.Name, d.Breed, d.Age) +} + +func main() { + dog1 := NewDog("Buddy", "Golden Retriever", 3) + fmt.Println(dog1.GetInfo()) + + fmt.Println("Возраст:", dog1.GetAge()) + dog1.SetAge(5) + fmt.Println("Новый возраст:", dog1.GetAge()) + fmt.Println(dog1.GetInfo()) + + dog2 := NewDog("Bella", "Labrador", 7) + fmt.Println(dog2.GetInfo()) } diff --git a/golang/lab/lab7/lab7.go b/golang/lab/lab7/lab7.go index a32f2702..766d1240 100644 --- a/golang/lab/lab7/lab7.go +++ b/golang/lab/lab7/lab7.go @@ -1,64 +1,78 @@ -package labs +package main import ( - "fmt" + "fmt" ) type Product interface { - GetPrice() float64 - SetPrice(price float64) - ApplyDiscount(percent float64) - GetDetails() string + GetPrice() float64 + SetPrice(price float64) + ApplyDiscount(percent float64) + GetDetails() string } type Book struct { - title string - author string - price float64 + title string + author string + price float64 } func (b *Book) GetPrice() float64 { - return b.price + return b.price } func (b *Book) SetPrice(price float64) { - b.price = price + b.price = price } func (b *Book) ApplyDiscount(percent float64) { - b.price -= b.price * percent / 100 + b.price -= b.price * percent / 100 } func (b *Book) GetDetails() string { - return fmt.Sprintf("Book: %s, Author: %s, Price: %.2f", b.title, b.author, b.price) + return fmt.Sprintf("Book: %s, Author: %s, Price: %.2f", b.title, b.author, b.price) } type Electronics struct { - name string - brand string - price float64 + name string + brand string + price float64 } func (e *Electronics) GetPrice() float64 { - return e.price + return e.price } func (e *Electronics) SetPrice(price float64) { - e.price = price + e.price = price } func (e *Electronics) ApplyDiscount(percent float64) { - e.price -= e.price * percent / 100 + e.price -= e.price * percent / 100 } func (e *Electronics) GetDetails() string { - return fmt.Sprintf("Electronics: %s, Brand: %s, Price: %.2f", e.name, e.brand, e.price) + return fmt.Sprintf("Electronics: %s, Brand: %s, Price: %.2f", e.name, e.brand, e.price) } func CalculateTotalPrice(products []Product) float64 { - total := 0.0 - for _, product := range products { - total += product.GetPrice() - } - return total + total := 0.0 + for _, product := range products { + total += product.GetPrice() + } + return total } +func main() { + book := Book{title: "The Go Programming Language", author: "Alan Donovan", price: 50.00} + electronics := Electronics{name: "Laptop", brand: "XYZ", price: 1200.00} + + fmt.Println(book.GetDetails()) + fmt.Println(electronics.GetDetails()) + + products := []Product{&book, &electronics} + totalPrice := CalculateTotalPrice(products) + fmt.Printf("Общая стоимость: %.2f\n", totalPrice) + book.ApplyDiscount(10) + fmt.Println("Цена со скидкой:", book.GetDetails()) + +} From b2f9a5c6de2032be5c36e5ac03997ff2b7ddc1ed Mon Sep 17 00:00:00 2001 From: Agurchic Date: Wed, 22 Jan 2025 18:34:03 +0300 Subject: [PATCH 6/8] launching programs2 --- golang/lab/lab4/lab4.go | 75 +++++++++++++++++++++-------------------- golang/lab/lab6/lab6.go | 30 ++++++++--------- golang/lab/lab7/lab7.go | 67 ++++++++++++++++++------------------ 3 files changed, 86 insertions(+), 86 deletions(-) diff --git a/golang/lab/lab4/lab4.go b/golang/lab/lab4/lab4.go index ab3b84d3..958db95d 100644 --- a/golang/lab/lab4/lab4.go +++ b/golang/lab/lab4/lab4.go @@ -1,53 +1,54 @@ package main import ( - "fmt" - "math" + "fmt" + "math" ) func CalculateY(a, b, x float64) float64 { - return math.Pow((a*x+b), 1.0/3.0) / math.Pow(math.Log10(x), 2) + return math.Pow((a*x+b), 1.0/3.0) / math.Pow(math.Log10(x), 2) } func TaskA(a, b, xStart, xEnd, step float64) []float64 { - var result []float64 - for x := xStart; x <= xEnd; x += step { - result = append(result, CalculateY(a, b, x)) - } - return result + var result []float64 + for x := xStart; x <= xEnd; x += step { + result = append(result, CalculateY(a, b, x)) + } + return result } func TaskB(a, b float64, xValues []float64) []float64 { - var result []float64 - for _, x := range xValues { - result = append(result, CalculateY(a, b, x)) - } - return result + var result []float64 + for _, x := range xValues { + result = append(result, CalculateY(a, b, x)) + } + return result } func main() { - a := 2.0 - b := 3.0 - - xStart := 1.0 - xEnd := 5.0 - step := 1.0 - resultsA := TaskA(a, b, xStart, xEnd, step) - fmt.Println("Результаты TaskA:") - for i, y := range resultsA { - fmt.Printf("x = %.2f, y = %.6f\n", xStart+float64(i)*step, y) - } - - fmt.Println() - - xValues := []float64{1.5, 2.5, 3.5, 4.5} - resultsB := TaskB(a, b, xValues) - fmt.Println("Результаты TaskB:") - for i, y := range resultsB { - fmt.Printf("x = %.2f, y = %.6f\n", xValues[i], y) - } - fmt.Println() - x := 3.0 - resultY := CalculateY(a, b, x) - fmt.Printf("Результат CalculateY: x= %.2f, y = %.6f\n", x, resultY) + a := 2.0 + b := 3.0 + + xStart := 1.0 + xEnd := 5.0 + step := 1.0 + resultsA := TaskA(a, b, xStart, xEnd, step) + fmt.Println("Результаты TaskA:") + for i, y := range resultsA { + fmt.Printf("x = %.2f, y = %.6f\n", xStart+float64(i)*step, y) + } + + fmt.Println() + + xValues := []float64{1.5, 2.5, 3.5, 4.5} + resultsB := TaskB(a, b, xValues) + fmt.Println("Результаты TaskB:") + for i, y := range resultsB { + fmt.Printf("x = %.2f, y = %.6f\n", xValues[i], y) + } + fmt.Println() + x := 3.0 + resultY := CalculateY(a, b, x) + fmt.Printf("Результат CalculateY: x= %.2f, y = %.6f\n", x, resultY) } + diff --git a/golang/lab/lab6/lab6.go b/golang/lab/lab6/lab6.go index a0b5e56f..c6f945f9 100644 --- a/golang/lab/lab6/lab6.go +++ b/golang/lab/lab6/lab6.go @@ -3,33 +3,33 @@ package main import "fmt" type Dog struct { - Name string - Breed string - Age int + Name string + Breed string + Age int } func NewDog(name string, breed string, age int) Dog { - return Dog{Name: name, Breed: breed, Age: age} + return Dog{Name: name, Breed: breed, Age: age} } func (d Dog) GetAge() int { - return d.Age + return d.Age } func (d *Dog) SetAge(age int) { - d.Age = age + d.Age = age } func (d Dog) GetInfo() string { - return fmt.Sprintf("Name: %s, Breed: %s, Age: %d", d.Name, d.Breed, d.Age) + return fmt.Sprintf("Name: %s, Breed: %s, Age: %d", d.Name, d.Breed, d.Age) } func main() { - dog1 := NewDog("Buddy", "Golden Retriever", 3) - fmt.Println(dog1.GetInfo()) + dog1 := NewDog("Buddy", "Golden Retriever", 3) + fmt.Println(dog1.GetInfo()) - fmt.Println("Возраст:", dog1.GetAge()) - dog1.SetAge(5) - fmt.Println("Новый возраст:", dog1.GetAge()) - fmt.Println(dog1.GetInfo()) + fmt.Println("Возраст:", dog1.GetAge()) + dog1.SetAge(5) + fmt.Println("Новый возраст:", dog1.GetAge()) + fmt.Println(dog1.GetInfo()) - dog2 := NewDog("Bella", "Labrador", 7) - fmt.Println(dog2.GetInfo()) + dog2 := NewDog("Bella", "Labrador", 7) + fmt.Println(dog2.GetInfo()) } diff --git a/golang/lab/lab7/lab7.go b/golang/lab/lab7/lab7.go index 766d1240..b506fb9d 100644 --- a/golang/lab/lab7/lab7.go +++ b/golang/lab/lab7/lab7.go @@ -1,78 +1,77 @@ package main import ( - "fmt" + "fmt" ) type Product interface { - GetPrice() float64 - SetPrice(price float64) - ApplyDiscount(percent float64) - GetDetails() string + GetPrice() float64 + SetPrice(price float64) + ApplyDiscount(percent float64) + GetDetails() string } type Book struct { - title string - author string - price float64 + title string + author string + price float64 } func (b *Book) GetPrice() float64 { - return b.price + return b.price } func (b *Book) SetPrice(price float64) { - b.price = price + b.price = price } func (b *Book) ApplyDiscount(percent float64) { - b.price -= b.price * percent / 100 + b.price -= b.price * percent / 100 } func (b *Book) GetDetails() string { - return fmt.Sprintf("Book: %s, Author: %s, Price: %.2f", b.title, b.author, b.price) + return fmt.Sprintf("Book: %s, Author: %s, Price: %.2f", b.title, b.author, b.price) } type Electronics struct { - name string - brand string - price float64 + name string + brand string + price float64 } func (e *Electronics) GetPrice() float64 { - return e.price + return e.price } func (e *Electronics) SetPrice(price float64) { - e.price = price + e.price = price } func (e *Electronics) ApplyDiscount(percent float64) { - e.price -= e.price * percent / 100 + e.price -= e.price * percent / 100 } func (e *Electronics) GetDetails() string { - return fmt.Sprintf("Electronics: %s, Brand: %s, Price: %.2f", e.name, e.brand, e.price) + return fmt.Sprintf("Electronics: %s, Brand: %s, Price: %.2f", e.name, e.brand, e.price) } func CalculateTotalPrice(products []Product) float64 { - total := 0.0 - for _, product := range products { - total += product.GetPrice() - } - return total + total := 0.0 + for _, product := range products { + total += product.GetPrice() + } + return total } func main() { - book := Book{title: "The Go Programming Language", author: "Alan Donovan", price: 50.00} - electronics := Electronics{name: "Laptop", brand: "XYZ", price: 1200.00} + book := Book{title: "The Go Programming Language", author: "Alan Donovan", price: 50.00} + electronics := Electronics{name: "Laptop", brand: "XYZ", price: 1200.00} - fmt.Println(book.GetDetails()) - fmt.Println(electronics.GetDetails()) - - products := []Product{&book, &electronics} - totalPrice := CalculateTotalPrice(products) - fmt.Printf("Общая стоимость: %.2f\n", totalPrice) - book.ApplyDiscount(10) - fmt.Println("Цена со скидкой:", book.GetDetails()) + fmt.Println(book.GetDetails()) + fmt.Println(electronics.GetDetails()) + products := []Product{&book, &electronics} + totalPrice := CalculateTotalPrice(products) + fmt.Printf("Общая стоимость: %.2f\n", totalPrice) + book.ApplyDiscount(10) + fmt.Println("Цена со скидкой:", book.GetDetails()) } From 0646f8764b00eb3ec6a02ee04accb7e3f551ffc0 Mon Sep 17 00:00:00 2001 From: Agurchic Date: Wed, 22 Jan 2025 20:36:45 +0300 Subject: [PATCH 7/8] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=20=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D1=83=D1=80=D1=8B=20?= =?UTF-8?q?=D0=B8=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- golang/lab/Book struct.go | 27 +++++++++++ golang/lab/Electronics struct.go | 26 +++++++++++ golang/lab/{lab4 => }/lab4.go | 0 golang/lab/{lab6 => }/lab6.go | 0 golang/lab/lab7.go | 79 ++++++++++++++++++++++++++++++++ golang/lab/lab7/lab7.go | 77 ------------------------------- golang/lab/product.go | 8 ++++ 7 files changed, 140 insertions(+), 77 deletions(-) create mode 100644 golang/lab/Book struct.go create mode 100644 golang/lab/Electronics struct.go rename golang/lab/{lab4 => }/lab4.go (100%) rename golang/lab/{lab6 => }/lab6.go (100%) create mode 100644 golang/lab/lab7.go delete mode 100644 golang/lab/lab7/lab7.go create mode 100644 golang/lab/product.go diff --git a/golang/lab/Book struct.go b/golang/lab/Book struct.go new file mode 100644 index 00000000..db0a8337 --- /dev/null +++ b/golang/lab/Book struct.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" +) + +type Book struct { + title string + author string + price float64 +} + +func (b *Book) GetPrice() float64 { + return b.price +} + +func (b *Book) SetPrice(price float64) { + b.price = price +} + +func (b *Book) ApplyDiscount(percent float64) { + b.price -= b.price * percent / 100 +} + +func (b *Book) GetDetails() string { + return fmt.Sprintf("Book: %s, Author: %s, Price: %.2f", b.title, b.author, b.price) +} diff --git a/golang/lab/Electronics struct.go b/golang/lab/Electronics struct.go new file mode 100644 index 00000000..1c0a603c --- /dev/null +++ b/golang/lab/Electronics struct.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" +) + +type Electronics struct { + name string + brand string + price float64 +} + +func (e *Electronics) GetPrice() float64 { + return e.price +} + +func (e *Electronics) SetPrice(price float64) { + e.price = price +} + +func (e *Electronics) ApplyDiscount(percent float64) { + e.price -= e.price * percent / 100 +} +func (e *Electronics) GetDetails() string { + return fmt.Sprintf("Electronics: %s, Brand: %s, Price: %.2f", e.name, e.brand, e.price) +} diff --git a/golang/lab/lab4/lab4.go b/golang/lab/lab4.go similarity index 100% rename from golang/lab/lab4/lab4.go rename to golang/lab/lab4.go diff --git a/golang/lab/lab6/lab6.go b/golang/lab/lab6.go similarity index 100% rename from golang/lab/lab6/lab6.go rename to golang/lab/lab6.go diff --git a/golang/lab/lab7.go b/golang/lab/lab7.go new file mode 100644 index 00000000..ea2c5b2e --- /dev/null +++ b/golang/lab/lab7.go @@ -0,0 +1,79 @@ +package main + +import ( + "fmt" +) + +type Product interface { + GetPrice() float64 + SetPrice(price float64) + ApplyDiscount(percent float64) + GetDetails() string +} + +type Book struct { + title string + author string + price float64 +} + +func (b *Book) GetPrice() float64 { + return b.price +} + +func (b *Book) SetPrice(price float64) { + b.price = price +} + +func (b *Book) ApplyDiscount(percent float64) { + b.price -= b.price * percent / 100 +} + +func (b *Book) GetDetails() string { + return fmt.Sprintf("Book: %s, Author: %s, Price: %.2f", b.title, b.author, b.price) +} + +type Electronics struct { + name string + brand string + price float64 +} + +func (e *Electronics) GetPrice() float64 { + return e.price +} + +func (e *Electronics) SetPrice(price float64) { + e.price = price +} + +func (e *Electronics) ApplyDiscount(percent float64) { + e.price -= e.price * percent / 100 +} + +func (e *Electronics) GetDetails() string { + return fmt.Sprintf("Electronics: %s, Brand: %s, Price: %.2f", e.name, e.brand, e.price) +} + +func CalculateTotalPrice(products []Product) float64 { + total := 0.0 + for _, product := range products { + total += product.GetPrice() + } + return total +} + +func main() { + book := Book{title: "The Go Programming Language", author: "Alan Donovan", price: 50.00} + electronics := Electronics{name: "Laptop", brand: "XYZ", price: 1200.00} + + fmt.Println(book.GetDetails()) + fmt.Println(electronics.GetDetails()) + + products := []Product{&book, &electronics} + totalPrice := CalculateTotalPrice(products) + fmt.Printf("Общая стоимость: %.2f\n", totalPrice) + fmt.Println() + book.ApplyDiscount(10) + fmt.Println("Цена со скидкой:", book.GetDetails()) +} diff --git a/golang/lab/lab7/lab7.go b/golang/lab/lab7/lab7.go deleted file mode 100644 index b506fb9d..00000000 --- a/golang/lab/lab7/lab7.go +++ /dev/null @@ -1,77 +0,0 @@ -package main - -import ( - "fmt" -) - -type Product interface { - GetPrice() float64 - SetPrice(price float64) - ApplyDiscount(percent float64) - GetDetails() string -} - -type Book struct { - title string - author string - price float64 -} - -func (b *Book) GetPrice() float64 { - return b.price -} - -func (b *Book) SetPrice(price float64) { - b.price = price -} - -func (b *Book) ApplyDiscount(percent float64) { - b.price -= b.price * percent / 100 -} - -func (b *Book) GetDetails() string { - return fmt.Sprintf("Book: %s, Author: %s, Price: %.2f", b.title, b.author, b.price) -} - -type Electronics struct { - name string - brand string - price float64 -} - -func (e *Electronics) GetPrice() float64 { - return e.price -} - -func (e *Electronics) SetPrice(price float64) { - e.price = price -} - -func (e *Electronics) ApplyDiscount(percent float64) { - e.price -= e.price * percent / 100 -} -func (e *Electronics) GetDetails() string { - return fmt.Sprintf("Electronics: %s, Brand: %s, Price: %.2f", e.name, e.brand, e.price) -} - -func CalculateTotalPrice(products []Product) float64 { - total := 0.0 - for _, product := range products { - total += product.GetPrice() - } - return total -} - -func main() { - book := Book{title: "The Go Programming Language", author: "Alan Donovan", price: 50.00} - electronics := Electronics{name: "Laptop", brand: "XYZ", price: 1200.00} - - fmt.Println(book.GetDetails()) - fmt.Println(electronics.GetDetails()) - - products := []Product{&book, &electronics} - totalPrice := CalculateTotalPrice(products) - fmt.Printf("Общая стоимость: %.2f\n", totalPrice) - book.ApplyDiscount(10) - fmt.Println("Цена со скидкой:", book.GetDetails()) -} diff --git a/golang/lab/product.go b/golang/lab/product.go new file mode 100644 index 00000000..acada0e8 --- /dev/null +++ b/golang/lab/product.go @@ -0,0 +1,8 @@ +package main + +type Product interface { + GetPrice() float64 + SetPrice(price float64) + ApplyDiscount(percent float64) + GetDetails() string +} From 13d4b7c3ebfbfaaf09bd136c37f337147f710f27 Mon Sep 17 00:00:00 2001 From: Agurchic Date: Wed, 22 Jan 2025 21:43:58 +0300 Subject: [PATCH 8/8] fix --- golang/lab/Book struct.go | 27 --------------------------- golang/lab/Electronics struct.go | 26 -------------------------- golang/lab/product.go | 8 -------- 3 files changed, 61 deletions(-) delete mode 100644 golang/lab/Book struct.go delete mode 100644 golang/lab/Electronics struct.go delete mode 100644 golang/lab/product.go diff --git a/golang/lab/Book struct.go b/golang/lab/Book struct.go deleted file mode 100644 index db0a8337..00000000 --- a/golang/lab/Book struct.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -import ( - "fmt" -) - -type Book struct { - title string - author string - price float64 -} - -func (b *Book) GetPrice() float64 { - return b.price -} - -func (b *Book) SetPrice(price float64) { - b.price = price -} - -func (b *Book) ApplyDiscount(percent float64) { - b.price -= b.price * percent / 100 -} - -func (b *Book) GetDetails() string { - return fmt.Sprintf("Book: %s, Author: %s, Price: %.2f", b.title, b.author, b.price) -} diff --git a/golang/lab/Electronics struct.go b/golang/lab/Electronics struct.go deleted file mode 100644 index 1c0a603c..00000000 --- a/golang/lab/Electronics struct.go +++ /dev/null @@ -1,26 +0,0 @@ -package main - -import ( - "fmt" -) - -type Electronics struct { - name string - brand string - price float64 -} - -func (e *Electronics) GetPrice() float64 { - return e.price -} - -func (e *Electronics) SetPrice(price float64) { - e.price = price -} - -func (e *Electronics) ApplyDiscount(percent float64) { - e.price -= e.price * percent / 100 -} -func (e *Electronics) GetDetails() string { - return fmt.Sprintf("Electronics: %s, Brand: %s, Price: %.2f", e.name, e.brand, e.price) -} diff --git a/golang/lab/product.go b/golang/lab/product.go deleted file mode 100644 index acada0e8..00000000 --- a/golang/lab/product.go +++ /dev/null @@ -1,8 +0,0 @@ -package main - -type Product interface { - GetPrice() float64 - SetPrice(price float64) - ApplyDiscount(percent float64) - GetDetails() string -}