Skip to content
Open

lab7 #631

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
4 changes: 1 addition & 3 deletions golang/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module isuct.ru/informatics2022

go 1.16

require github.com/stretchr/testify v1.8.1
go 1.16
17 changes: 0 additions & 17 deletions golang/go.sum
Original file line number Diff line number Diff line change
@@ -1,17 +0,0 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
40 changes: 40 additions & 0 deletions golang/labs/lab7/clothes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package labs

import "fmt"

type Clothes struct {
name string
price float64
brand string
material string
season string
}

func (c *Clothes) GetName() string {
return c.name
}

func (c *Clothes) GetPrice() float64 {
return c.price
}

func (c *Clothes) Setdiscount(discount float64) {
c.price -= c.price * discount / 100
}

func (c *Clothes) SetPrice(newPrice float64) {
c.price = newPrice
}

func (c *Clothes) GetBrand() string {
return c.brand
}
func (c *Clothes) GetSeason() string {
return c.season
}
func (c *Clothes) GetMaterial() string {
return c.material
}
func (c *Clothes) GetInfo() string {
return fmt.Sprintf("Название: %s, Цена: %.2f, Бренд: %s, Материал: %s,Сезон: %s", c.name, c.price, c.brand, c.material, c.season)
}
27 changes: 27 additions & 0 deletions golang/labs/lab7/cosmetics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package labs

import "fmt"

type Cosmetics struct {
name string
price float64
brand string
}

func (c *Cosmetics) GetName() string {
return c.name
}
func (c *Cosmetics) GetPrice() float64 {
return c.price
}

func (c *Cosmetics) Setdiscount(discount float64) {
c.price -= c.price * discount / 100
}

func (c *Cosmetics) SetPrice(newPrice float64) {
c.price = newPrice
}
func (c *Cosmetics) GetInfo() string {
return fmt.Sprintf("Название: %s, Бренд: %s, Цена: %.2f", c.name, c.brand, c.price)
}
28 changes: 28 additions & 0 deletions golang/labs/lab7/food.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package labs

import "fmt"

type Food struct {
price float64
name string
brand string
calories int
}

func (f *Food) GetName() string {
return f.name
}
func (f *Food) GetPrice() float64 {
return f.price
}

func (f *Food) Setdiscount(discount float64) {
f.price -= f.price * discount / 100
}

func (f *Food) SetPrice(newPrice float64) {
f.price = newPrice
}
func (f *Food) GetInfo() string {
return fmt.Sprintf("Название: %s, Цена: %.2f, Калорийность: %d , Бренд: %s", f.name, f.price, f.calories, f.brand)
}
33 changes: 33 additions & 0 deletions golang/labs/lab7/lab7.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package labs

import "fmt"

func CalculateProductsSum(products []Product) float64 {
var sum float64 = 0
for _, product := range products {
sum += product.GetPrice()
}
return sum
}

func RunLab7() {
potato := &Food{50.15, "картошка", "вкусвилл", 17}
lipstick := &Cosmetics{"помада", 1700, "Chanel"}
sweatshirt := &Clothes{"толстовка", 3000.99, "Levi`s", "хлопок", "осень"}
products := []Product{potato, lipstick, sweatshirt}
fmt.Println("Товары")
fmt.Println("Общая стоимость:", CalculateProductsSum(products), "рублей")
for _, product := range products {
fmt.Println(product.GetInfo())
}

for _, product := range products {
product.Setdiscount(20)
}
fmt.Println("Общая стоимость товаров после применения скидки 20%:", CalculateProductsSum(products), "рублей")

fmt.Println("Информация про товар толстовка")
fmt.Println("материал:", sweatshirt.GetMaterial())
fmt.Println("сезон:", sweatshirt.GetSeason())
fmt.Println("бренд:", sweatshirt.GetBrand())
}
9 changes: 9 additions & 0 deletions golang/labs/lab7/product.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package labs

type Product interface {
Setdiscount(discount float64)
SetPrice(newPrice float64)
GetPrice() float64
GetName() string
GetInfo() string
}
10 changes: 8 additions & 2 deletions golang/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package main

import "fmt"
import (
"fmt"

lab7 "isuct.ru/informatics2022/labs/lab7"
)

func main() {
fmt.Println("Hello world")
fmt.Println("Maksimov Daniil Andreevich")

lab7.RunLab7()
}
Loading