Skip to content
Open

lab7 #608

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions golang/lab7/Clothes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package lab7

import "fmt"

type Clothes struct {
Name string
Price float64
Size string
Color string
}

func (c *Clothes) make_sale(discount float64) {
c.Price = c.Price * (1 - discount/100)
}
func (c *Clothes) get_price() float64 {
return c.Price
}
func (c *Clothes) get_productInfo() string {
return fmt.Sprintf("Name: %s, Size: %s, Color: %s, Price: %.2f", c.Name, c.Size, c.Color, c.Price)
}
19 changes: 19 additions & 0 deletions golang/lab7/Food.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package lab7

import "fmt"

type Food struct {
Name string
Weight float64
Price float64
}

func (f *Food) make_sale(discount float64) {
f.Price = f.Price * (1 - discount/100)
}
func (f *Food) get_price() float64 {
return f.Price
}
func (f *Food) get_productInfo() string {
return fmt.Sprintf("Name: %s, Weight: %.2f, Price: %.2f", f.Name, f.Weight, f.Price)
}
15 changes: 15 additions & 0 deletions golang/lab7/Product.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package lab7

type Product interface {
make_sale(discount float64)
get_price() float64
get_productInfo() string
}

func get_priceAllProducts(products []Product) float64 {
var totalCost float64
for _, product := range products {
totalCost += product.get_price()
}
return totalCost
}
21 changes: 21 additions & 0 deletions golang/lab7/RunLab.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package lab7

import "fmt"

func CompleteLab7() {
product1 := &Clothes{Name: "Худи", Price: 1200, Size: "XL", Color: "Black"}
product1.make_sale(15)
product2 := &Food{Name: "Ананас", Weight: 1000, Price: 200}
product2.make_sale(25)
product3 := &Vehicle{Brand: "Mitsubishi", Model: "ASX", Color: "Orange", Price: 1400000}
product3.make_sale(5)

products := []Product{product1, product2, product3}

for _, product := range products {
fmt.Println(product.get_productInfo())
}

totalPrice := get_priceAllProducts(products)
fmt.Printf("Общая стоимость: %.2f\n", totalPrice)
}
20 changes: 20 additions & 0 deletions golang/lab7/Vehicle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package lab7

import "fmt"

type Vehicle struct {
Brand string
Model string
Color string
Price float64
}

func (v *Vehicle) make_sale(discount float64) {
v.Price = v.Price * (1 - discount/100)
}
func (v *Vehicle) get_price() float64 {
return v.Price
}
func (v *Vehicle) get_productInfo() string {
return fmt.Sprintf("Brand: %s, Model: %s, Color: %s, Price: %.2f", v.Brand, v.Model, v.Color, v.Price)
}
3 changes: 3 additions & 0 deletions golang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import (
"isuct.ru/informatics2022/lab4"

"isuct.ru/informatics2022/lab6"

"isuct.ru/informatics2022/lab7"
)

func main() {
fmt.Println("Кулибаба Никита Андреевич")
lab4.CompleteLab4()
lab6.CompleteLab6()
lab7.CompleteLab7()
}
Loading