From e831e11d9f689a48595962a2b043499bcc2a9864 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 16 Dec 2024 23:03:56 +0300 Subject: [PATCH 1/7] =?UTF-8?q?=D0=B2=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=207=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D1=83=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- golang/lab7/book.go | 41 ++++++++++++++++++++++++++++ golang/lab7/clothes.go | 41 ++++++++++++++++++++++++++++ golang/lab7/electronics.go | 41 ++++++++++++++++++++++++++++ golang/lab7/lab7.go | 55 ++++++++++++++++++++++++++++++++++++++ golang/main.go | 2 ++ 5 files changed, 180 insertions(+) create mode 100644 golang/lab7/book.go create mode 100644 golang/lab7/clothes.go create mode 100644 golang/lab7/electronics.go create mode 100644 golang/lab7/lab7.go diff --git a/golang/lab7/book.go b/golang/lab7/book.go new file mode 100644 index 00000000..ef1fd6e6 --- /dev/null +++ b/golang/lab7/book.go @@ -0,0 +1,41 @@ +package lab7 + +import "fmt" + +type Book struct { + name string + author string + price float64 + description string +} + +func NewBook(name string, author string, price float64, description string) *Book { + book := &Book{name: name, author: author, price: price, description: description} + return book +} + +func (b *Book) getName() string { + return b.name +} + +func (b *Book) setPrice(newPrice float64) { + b.price = newPrice +} + +func (b *Book) getPrice() float64 { + return b.price +} + +func (b *Book) changeData(name string, price float64, description string) { + b.name = name + b.price = price + b.description = description +} + +func (b *Book) getData() { + fmt.Printf("name: %s\nauthor: %s\nprice: %.2f\ndescription: %s\n\n", b.name, b.author, b.price, b.description) +} + +func (b *Book) applyDiscount(perDiscount float64) { + b.price = b.price * (1 - (perDiscount / 100)) +} \ No newline at end of file diff --git a/golang/lab7/clothes.go b/golang/lab7/clothes.go new file mode 100644 index 00000000..fc7df14b --- /dev/null +++ b/golang/lab7/clothes.go @@ -0,0 +1,41 @@ +package lab7 + +import "fmt" + +type Clothes struct { + name string + brand string + price float64 + description string +} + +func NewClothes(name string, brand string, price float64, description string) *Clothes { + clothes := &Clothes{name: name, brand: brand, price: price, description: description} + return clothes +} + +func (c *Clothes) getName() string { + return c.name +} + +func (c *Clothes) setPrice(newPrice float64) { + c.price = newPrice +} + +func (c *Clothes) getPrice() float64 { + return c.price +} + +func (c *Clothes) changeData(name string, price float64, description string) { + c.name = name + c.price = price + c.description = description +} + +func (c *Clothes) getData() { + fmt.Printf("name: %s\nbrand: %s\nprice: %.2f\ndescription: %s\n\n", c.name, c.brand, c.price, c.description) +} + +func (c *Clothes) applyDiscount(perDiscount float64) { + c.price = c.price * (1 - (perDiscount / 100)) +} \ No newline at end of file diff --git a/golang/lab7/electronics.go b/golang/lab7/electronics.go new file mode 100644 index 00000000..b8eef4a8 --- /dev/null +++ b/golang/lab7/electronics.go @@ -0,0 +1,41 @@ +package lab7 + +import "fmt" + +type Electronics struct { + name string + model string + price float64 + description string +} + +func NewElectronics(name string, model string, price float64, description string) *Electronics { + electronics := &Electronics{name: name, model: model, price: price, description: description} + return electronics +} + +func (e *Electronics) getName() string { + return e.name +} + +func (e *Electronics) setPrice(newPrice float64) { + e.price = newPrice +} + +func (e *Electronics) getPrice() float64 { + return e.price +} + +func (e *Electronics) changeData(name string, price float64, description string) { + e.name = name + e.price = price + e.description = description +} + +func (e *Electronics) getData() { + fmt.Printf("name: %s\nmodel: %s\nprice: %.2f\ndescription: %s\n\n", e.name, e.electronics, e.price, e.description) +} + +func (e *Electronics) applyDiscount(perDiscount float64) { + e.price = e.price * (1 - (perDiscount / 100)) +} \ No newline at end of file diff --git a/golang/lab7/lab7.go b/golang/lab7/lab7.go new file mode 100644 index 00000000..5c56e43d --- /dev/null +++ b/golang/lab7/lab7.go @@ -0,0 +1,55 @@ +package lab7 + +import ( + "fmt" +) + +type Products interface { + getName() string + setPrice(float64) + getPrice() float64 + changeData(string, float64, string) + getData() + applyDiscount(float64) +} + +func calculateDiscount(products []Products) float64 { + var sum float64 = 0 + for _, product := range products { + sum += product.getPrice() + } + + return sum +} + +func RunLab7() { + product1 := NewBook("Harry Potter", "JK Rowling", 1000.0, "A book on Harry Potter") + product2 := NewClothes("T-shirt", "Nike", 900.0, "Nice T-shirt") + product3 := NewElectronics("Lamp", "Diode", 100.0, "Wonderful lamp") + + listOfProduct := []Products{product1, product2, product3} + + fmt.Printf("\nПродукты до изменения\n\n") + product1.getData() + product2.getData() +product1.changeData("Improved book Harry Potter", 1500.0, "Interesting book") +product2.changeData("Premium T-shirt", 1000.0, "A high-quality cotton T-shirt.") + fmt.Printf("\nПродукты после изменения\n\n") + product1.getData() + product2.getData() + + fmt.Println("Товар-----------Цена") + for _, product := range listOfProduct { + fmt. Printf("%s-------%.2f $\n", product.getName(),product.getPrice()) + } + fmt.Printf("Цена корзины до скидки: %.2f $\n\n", calculateDiscount(listOfProduct)) + +listOfProduct[0].ApplyDiscount(10) +listOfProduct[1].ApplyDiscount(5) + + fmt. Println("Товар-----------Цена") + for _, product := range listOfProduct { + fmt.Printf("%s-------%.2f $\n", product.getName(), product.getPrice()) + } + fmt.Printf("Цена корзины после скидки: %.2f $\n", calculateDiscount(listOfProduct)) +} \ No newline at end of file diff --git a/golang/main.go b/golang/main.go index d13e6b80..684ec5f9 100644 --- a/golang/main.go +++ b/golang/main.go @@ -2,9 +2,11 @@ package main import ("fmt" "isuct.ru/informatics2022/lab6" +"isuct.ru/informatics2022/lab7" ) func main() { lab6.RunLab6() + lab7.RunLab7() fmt.Println("Krukova Kristina Ivanovna") } From 8e0cac9d22690f25c70592497b57a83b6d2163e7 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 17 Dec 2024 00:07:00 +0300 Subject: [PATCH 2/7] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- golang/lab7/lab7.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/golang/lab7/lab7.go b/golang/lab7/lab7.go index 5c56e43d..bac1e538 100644 --- a/golang/lab7/lab7.go +++ b/golang/lab7/lab7.go @@ -40,7 +40,7 @@ product2.changeData("Premium T-shirt", 1000.0, "A high-quality cotton T-shirt.") fmt.Println("Товар-----------Цена") for _, product := range listOfProduct { - fmt. Printf("%s-------%.2f $\n", product.getName(),product.getPrice()) + fmt.Printf("%s-------%.2f $\n", product.getName(),product.getPrice()) } fmt.Printf("Цена корзины до скидки: %.2f $\n\n", calculateDiscount(listOfProduct)) @@ -49,7 +49,7 @@ listOfProduct[1].ApplyDiscount(5) fmt. Println("Товар-----------Цена") for _, product := range listOfProduct { - fmt.Printf("%s-------%.2f $\n", product.getName(), product.getPrice()) + fmt.Printf("%s-------%.2f $\n", product.getName(), product.getPrice()) } fmt.Printf("Цена корзины после скидки: %.2f $\n", calculateDiscount(listOfProduct)) } \ No newline at end of file From 1be5c0f0cd8f5e4a4f8a0b1f79e4b191a41db3fc Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 17 Dec 2024 00:10:37 +0300 Subject: [PATCH 3/7] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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 bac1e538..1ea09733 100644 --- a/golang/lab7/lab7.go +++ b/golang/lab7/lab7.go @@ -40,7 +40,7 @@ product2.changeData("Premium T-shirt", 1000.0, "A high-quality cotton T-shirt.") fmt.Println("Товар-----------Цена") for _, product := range listOfProduct { - fmt.Printf("%s-------%.2f $\n", product.getName(),product.getPrice()) + fmt.Printf("%s-------%.2f $\n", product.getName(),product.getPrice()) } fmt.Printf("Цена корзины до скидки: %.2f $\n\n", calculateDiscount(listOfProduct)) From e4263884e892258a42d86cbf97ade8ba2d13be8d Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 17 Dec 2024 00:15:01 +0300 Subject: [PATCH 4/7] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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 1ea09733..d0101222 100644 --- a/golang/lab7/lab7.go +++ b/golang/lab7/lab7.go @@ -40,7 +40,7 @@ product2.changeData("Premium T-shirt", 1000.0, "A high-quality cotton T-shirt.") fmt.Println("Товар-----------Цена") for _, product := range listOfProduct { - fmt.Printf("%s-------%.2f $\n", product.getName(),product.getPrice()) + fmt.Printf("%s-------%.2f $\n", product.getName(), product.getPrice()) } fmt.Printf("Цена корзины до скидки: %.2f $\n\n", calculateDiscount(listOfProduct)) From cacd5a917e90cb9fba07858904570e12d0b55b2c Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 17 Dec 2024 00:19:53 +0300 Subject: [PATCH 5/7] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- golang/lab7/lab7.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/golang/lab7/lab7.go b/golang/lab7/lab7.go index d0101222..fd3a4df1 100644 --- a/golang/lab7/lab7.go +++ b/golang/lab7/lab7.go @@ -44,8 +44,9 @@ product2.changeData("Premium T-shirt", 1000.0, "A high-quality cotton T-shirt.") } fmt.Printf("Цена корзины до скидки: %.2f $\n\n", calculateDiscount(listOfProduct)) -listOfProduct[0].ApplyDiscount(10) -listOfProduct[1].ApplyDiscount(5) +product1.applyDiscount(10) +product2.applyDiscount(20) +product3.applyDiscount(15) fmt. Println("Товар-----------Цена") for _, product := range listOfProduct { From 02689fd2278bbece6fa9cc0589712d7f7c08fc8a Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 17 Dec 2024 19:08:29 +0300 Subject: [PATCH 6/7] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- golang/lab7/electronics.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/golang/lab7/electronics.go b/golang/lab7/electronics.go index b8eef4a8..7f59218f 100644 --- a/golang/lab7/electronics.go +++ b/golang/lab7/electronics.go @@ -33,7 +33,7 @@ func (e *Electronics) changeData(name string, price float64, description string) } func (e *Electronics) getData() { - fmt.Printf("name: %s\nmodel: %s\nprice: %.2f\ndescription: %s\n\n", e.name, e.electronics, e.price, e.description) + fmt.Printf("name: %s\nmodel: %s\nprice: %.2f\ndescription: %s\n\n", e.name, e.model, e.price, e.description) } func (e *Electronics) applyDiscount(perDiscount float64) { From 43ccfb413eeb85674962cdbcacf2dadda1b2924c Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 24 Dec 2024 21:27:37 +0300 Subject: [PATCH 7/7] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- golang/lab7/book.go | 12 ++++++------ golang/lab7/clothes.go | 12 ++++++------ golang/lab7/electronics.go | 12 ++++++------ golang/lab7/lab7.go | 36 ++++++++++++++++++------------------ 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/golang/lab7/book.go b/golang/lab7/book.go index ef1fd6e6..b393cc15 100644 --- a/golang/lab7/book.go +++ b/golang/lab7/book.go @@ -14,28 +14,28 @@ func NewBook(name string, author string, price float64, description string) *Boo return book } -func (b *Book) getName() string { +func (b *Book) GetName() string { return b.name } -func (b *Book) setPrice(newPrice float64) { +func (b *Book) SetPrice(newPrice float64) { b.price = newPrice } -func (b *Book) getPrice() float64 { +func (b *Book) GetPrice() float64 { return b.price } -func (b *Book) changeData(name string, price float64, description string) { +func (b *Book) ChangeData(name string, price float64, description string) { b.name = name b.price = price b.description = description } -func (b *Book) getData() { +func (b *Book) GetData() { fmt.Printf("name: %s\nauthor: %s\nprice: %.2f\ndescription: %s\n\n", b.name, b.author, b.price, b.description) } -func (b *Book) applyDiscount(perDiscount float64) { +func (b *Book) ApplyDiscount(perDiscount float64) { b.price = b.price * (1 - (perDiscount / 100)) } \ No newline at end of file diff --git a/golang/lab7/clothes.go b/golang/lab7/clothes.go index fc7df14b..7de8a08c 100644 --- a/golang/lab7/clothes.go +++ b/golang/lab7/clothes.go @@ -14,28 +14,28 @@ func NewClothes(name string, brand string, price float64, description string) *C return clothes } -func (c *Clothes) getName() string { +func (c *Clothes) GetName() string { return c.name } -func (c *Clothes) setPrice(newPrice float64) { +func (c *Clothes) SetPrice(newPrice float64) { c.price = newPrice } -func (c *Clothes) getPrice() float64 { +func (c *Clothes) GetPrice() float64 { return c.price } -func (c *Clothes) changeData(name string, price float64, description string) { +func (c *Clothes) ChangeData(name string, price float64, description string) { c.name = name c.price = price c.description = description } -func (c *Clothes) getData() { +func (c *Clothes) GetData() { fmt.Printf("name: %s\nbrand: %s\nprice: %.2f\ndescription: %s\n\n", c.name, c.brand, c.price, c.description) } -func (c *Clothes) applyDiscount(perDiscount float64) { +func (c *Clothes) ApplyDiscount(perDiscount float64) { c.price = c.price * (1 - (perDiscount / 100)) } \ No newline at end of file diff --git a/golang/lab7/electronics.go b/golang/lab7/electronics.go index 7f59218f..ae6556a4 100644 --- a/golang/lab7/electronics.go +++ b/golang/lab7/electronics.go @@ -14,28 +14,28 @@ func NewElectronics(name string, model string, price float64, description string return electronics } -func (e *Electronics) getName() string { +func (e *Electronics) GetName() string { return e.name } -func (e *Electronics) setPrice(newPrice float64) { +func (e *Electronics) SetPrice(newPrice float64) { e.price = newPrice } -func (e *Electronics) getPrice() float64 { +func (e *Electronics) GetPrice() float64 { return e.price } -func (e *Electronics) changeData(name string, price float64, description string) { +func (e *Electronics) ChangeData(name string, price float64, description string) { e.name = name e.price = price e.description = description } -func (e *Electronics) getData() { +func (e *Electronics) GetData() { fmt.Printf("name: %s\nmodel: %s\nprice: %.2f\ndescription: %s\n\n", e.name, e.model, e.price, e.description) } -func (e *Electronics) applyDiscount(perDiscount float64) { +func (e *Electronics) ApplyDiscount(perDiscount float64) { e.price = e.price * (1 - (perDiscount / 100)) } \ No newline at end of file diff --git a/golang/lab7/lab7.go b/golang/lab7/lab7.go index fd3a4df1..b23bec0d 100644 --- a/golang/lab7/lab7.go +++ b/golang/lab7/lab7.go @@ -5,18 +5,18 @@ import ( ) type Products interface { - getName() string - setPrice(float64) - getPrice() float64 - changeData(string, float64, string) - getData() - applyDiscount(float64) + GetName() string + SetPrice(float64) + GetPrice() float64 + ChangeData(string, float64, string) + GetData() + ApplyDiscount(float64) } func calculateDiscount(products []Products) float64 { var sum float64 = 0 for _, product := range products { - sum += product.getPrice() + sum += product.GetPrice() } return sum @@ -30,27 +30,27 @@ func RunLab7() { listOfProduct := []Products{product1, product2, product3} fmt.Printf("\nПродукты до изменения\n\n") - product1.getData() - product2.getData() -product1.changeData("Improved book Harry Potter", 1500.0, "Interesting book") -product2.changeData("Premium T-shirt", 1000.0, "A high-quality cotton T-shirt.") + product1.GetData() + product2.GetData() +product1.ChangeData("Improved book Harry Potter", 1500.0, "Interesting book") +product2.ChangeData("Premium T-shirt", 1000.0, "A high-quality cotton T-shirt.") fmt.Printf("\nПродукты после изменения\n\n") - product1.getData() - product2.getData() + product1.GetData() + product2.GetData() fmt.Println("Товар-----------Цена") for _, product := range listOfProduct { - fmt.Printf("%s-------%.2f $\n", product.getName(), product.getPrice()) + fmt.Printf("%s-------%.2f $\n", product.GetName(), product.GetPrice()) } fmt.Printf("Цена корзины до скидки: %.2f $\n\n", calculateDiscount(listOfProduct)) -product1.applyDiscount(10) -product2.applyDiscount(20) -product3.applyDiscount(15) +product1.ApplyDiscount(10) +product2.ApplyDiscount(20) +product3.ApplyDiscount(15) fmt. Println("Товар-----------Цена") for _, product := range listOfProduct { - fmt.Printf("%s-------%.2f $\n", product.getName(), product.getPrice()) + fmt.Printf("%s-------%.2f $\n", product.GetName(), product.GetPrice()) } fmt.Printf("Цена корзины после скидки: %.2f $\n", calculateDiscount(listOfProduct)) } \ No newline at end of file