diff --git a/golang/lab7/Car.go b/golang/lab7/Car.go new file mode 100644 index 00000000..ea902a3d --- /dev/null +++ b/golang/lab7/Car.go @@ -0,0 +1,25 @@ +package lab7 + +type Car struct { + name string + price float64 + model string + color string + +} + +func (c *Car) GetName() string { + return c.name +} + +func (c *Car) GetPrice() float64 { + return c.price +} + +func (c *Car) SetPrice(price float64) { + c.price = price +} + +func (c *Car) ApplyDiscount(discount float64) { + c.price -= c.price * discount / 100 +} \ No newline at end of file diff --git a/golang/lab7/Fruit.go b/golang/lab7/Fruit.go new file mode 100644 index 00000000..75f46988 --- /dev/null +++ b/golang/lab7/Fruit.go @@ -0,0 +1,24 @@ +package lab7 + +type Fruit struct { + Name string + Price float64 + Freshness string + Color string +} + +func (f *Fruit) GetName() string { + return f.Name +} + +func (f Fruit) GetPrice() float64 { + return f.Price +} + +func (f *Fruit) SetPrice(price float64) { + f.Price = price +} + +func (f *Fruit) ApplyDiscount(discount float64) { + f.Price -= f.Price * discount / 100 +} \ No newline at end of file diff --git a/golang/lab7/Mobile.go b/golang/lab7/Mobile.go new file mode 100644 index 00000000..e30ec8fc --- /dev/null +++ b/golang/lab7/Mobile.go @@ -0,0 +1,24 @@ +package lab7 + +type Mobile struct { + Name string + Price float64 + Brand string + Color string +} + +func (m *Mobile) GetName() string { + return m.Name +} + +func (m *Mobile) GetPrice() float64 { + return m.Price +} + +func (m *Mobile) SetPrice(price float64) { + m.Price = price +} + +func (m *Mobile) ApplyDiscount(discount float64) { + m.Price -= m.Price * discount / 100 +} \ No newline at end of file diff --git a/golang/lab7/Product.go b/golang/lab7/Product.go new file mode 100644 index 00000000..35685edc --- /dev/null +++ b/golang/lab7/Product.go @@ -0,0 +1,8 @@ +package lab7 + +type Product interface { + GetName() string + GetPrice() float64 + SetPrice(price float64) + ApplyDiscount(discount float64) +} \ No newline at end of file diff --git a/golang/lab7/laba7.go b/golang/lab7/laba7.go new file mode 100644 index 00000000..758e239b --- /dev/null +++ b/golang/lab7/laba7.go @@ -0,0 +1,24 @@ +package lab7 + +import "fmt" + +func GetTotalPrice(products []Product) float64 { + var TotalPrice float64 = 0 + for _, product := range products { + TotalPrice += product.GetPrice() + } + return TotalPrice +} + +func Lab7() { + Mobile := &Mobile{"Айфон 11 pro max", 50000, "Iphone", "gold"} + Fruit := &Fruit{"Манго", 250, "свежее", "yellow"} + Car := &Car{"Reno Logan", 500000, "Reno", "black"} + products := []Product{Mobile, Fruit, Car} + fmt.Println("Стоимость без скидок:", GetTotalPrice(products)) + + Mobile.ApplyDiscount(25) + Fruit.ApplyDiscount(40) + Car.ApplyDiscount(10) + fmt.Println("Стоимость после учёта скидки:", GetTotalPrice(products)) +} \ No newline at end of file diff --git a/golang/main.go b/golang/main.go index 2036b3fb..0af1b53e 100644 --- a/golang/main.go +++ b/golang/main.go @@ -1,12 +1,13 @@ package main import ( - "fmt" - "isuct.ru/informatics2022/lab6" - "isuct.ru/informatics2022/lab4" + + "fmt" + + "isuct.ru/informatics2022/lab7" ) func main() { - fmt.Println("Лахтин Максим Сергеевич") - lab4.RunLab4() - lab6.RunLab6() -} \ No newline at end of file + fmt.Println("Лаборатнорная 7:") + lab7.Lab7() +} +