diff --git a/golang/lab7/Cosmetic.go b/golang/lab7/Cosmetic.go new file mode 100644 index 00000000..c7ebe6bc --- /dev/null +++ b/golang/lab7/Cosmetic.go @@ -0,0 +1,28 @@ +package lab7 +import "fmt" + +type Cosmetic struct { + Name string + Brend string + Price float32 +} + +func (c Cosmetic) GetInformation() { + fmt.Println("У нас есть в наличии", c.Name, "из бренда", c.Brend, "и стоит", c.Price) +} + +func (c Cosmetic) GetPrice() float32 { + return c.Price +} + +func (c *Cosmetic) ApplyDiscount(x float32) { + (*c).Price = (c.Price / 100) * (100 - x) +} + +func (c *Cosmetic) ChangePrice(x float32) { + (*c).Price = x +} + +func (c *Cosmetic) ChangeDescription(x string) { + (*c).Brend = x +} diff --git a/golang/lab7/Sweets.go b/golang/lab7/Sweets.go new file mode 100644 index 00000000..9c8798ab --- /dev/null +++ b/golang/lab7/Sweets.go @@ -0,0 +1,27 @@ +package lab7 +import "fmt" +type Sweets struct { + Name string + Taste string + Price float32 +} + +func (s Sweets) GetInformation() { + fmt.Println("У нас есть в наличии", s.Name, "вкуса", s.Taste, "стоимостью", s.Price) +} + +func (s Sweets) GetPrice() float32 { + return s.Price +} + +func (s *Sweets) ApplyDiscount(x float32) { + (*s).Price = (s.Price / 100) * (100 - x) +} + +func (s *Sweets) ChangePrice(x float32) { + (*s).Price = x +} + +func (s *Sweets) ChangeDescription(x string) { + (*s).Taste = x +} diff --git a/golang/lab7/lab7.go b/golang/lab7/lab7.go new file mode 100644 index 00000000..0bc9dc90 --- /dev/null +++ b/golang/lab7/lab7.go @@ -0,0 +1,43 @@ +package lab7 + +import "fmt" + +type Products interface { + GetInformation() + GetPrice() float32 + ApplyDiscount(float32) + ChangePrice(float32) + ChangeDescription(string) +} + + +func CalculateBuy(list []Products) float32 { + var sum float32 = 0 + for _, price := range list { + sum += price.GetPrice() + } + return sum +} + +func RunLab7Tasks() { + var cosmetic Products = &Cosmetic{"помада", "Gucci", 5000} + var techcic Products = &Technic{"ноутбук", "Apple", 169660} + var sweets Products = &Sweets{"Сникерс", "Солёная карамель", 85} + cosmetic.GetInformation() + techcic.GetInformation() + sweets.GetInformation() + var buy []Products = []Products{cosmetic , techcic, sweets} + sum := CalculateBuy(buy) + fmt.Println("Товары стоят",sum) + techcic.ChangePrice(150000) + cosmetic.ChangeDescription("LV") + cosmetic.ApplyDiscount(5) + sweets.ApplyDiscount(60) + sweets.ChangeDescription("Белый шоколад") + techcic.GetInformation() + cosmetic.GetInformation() + sweets.GetInformation() + + sum = CalculateBuy(buy) + fmt.Println("Товары стоят",sum) +} diff --git a/golang/lab7/technic.go b/golang/lab7/technic.go new file mode 100644 index 00000000..67d22d1e --- /dev/null +++ b/golang/lab7/technic.go @@ -0,0 +1,27 @@ +package lab7 +import "fmt" +type Technic struct { + Name string + Brend string + Price float32 +} + +func (t Technic) GetInformation() { + fmt.Println("У нас есть в наличии", t.Name, "от компании", t.Brend, "и стоит", t.Price) +} + +func (t Technic) GetPrice() float32 { + return t.Price +} + +func (t *Technic) ApplyDiscount(x float32) { + (*t).Price = (t.Price / 100) * (100 - x) +} + +func (t *Technic) ChangePrice(x float32) { + (*t).Price = x +} + +func (t *Technic) ChangeDescription(x string) { + (*t).Brend = x +} diff --git a/golang/main.go b/golang/main.go index 71c1bbcd..232912b8 100644 --- a/golang/main.go +++ b/golang/main.go @@ -1,10 +1,10 @@ - package main import ( "fmt" "isuct.ru/informatics2022/lab4" "isuct.ru/informatics2022/lab6" + "isuct.ru/informatics2022/lab7" ) @@ -12,4 +12,5 @@ func main() { fmt.Println("Рукина Полина Владимировна") lab4.RunLab4Tasks() lab6.Runlab6() -} \ No newline at end of file + lab7.RunLab7Tasks() +}