Skip to content
Open

Lab7 #629

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
2 changes: 0 additions & 2 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
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=
42 changes: 42 additions & 0 deletions golang/lab7/lab7.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package lab7

import "fmt"

func Lab7() {
phone1 := Phone{
Size: 100,
Model: "Iphone",
Price: 10000,
}
PC1 := PC{
Model: "Model123",
Price: 5000,
RAM: 30,
}
Laptop1 := Laptop{
Model: "ASUS",
Price: 3000,
ROM: 20,
}
ProductsList := []Product{&phone1, &PC1, &Laptop1}
defoultCost := GetTotalPrice(ProductsList)
fmt.Println("За товары вы заплатите:", defoultCost)
for _, product := range ProductsList {
product.SetDiscount(30)
}

defoultCost = GetTotalPrice(ProductsList)
fmt.Println("С учетом всех скидок вы заплатите:", defoultCost)
phone1.SetSize(660)
PC1.SetRAM(50)
Laptop1.SetROM(106)
}

func GetTotalPrice(ProductsList []Product) float64 {
var defoultCost float64

for _, product := range ProductsList {
defoultCost += product.GetPrice()
}
return defoultCost
}
28 changes: 28 additions & 0 deletions golang/lab7/laptop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package lab7

type Laptop struct {
Model string
Price float64
ROM float64
}

func (l *Laptop) SetModel(Model string) {
l.Model = Model
}
func (l *Laptop) GetModel() string {
return l.Model
}
func (l *Laptop) SetPrice(Price float64) {
l.Price = Price
}
func (l *Laptop) GetPrice() float64 {
return l.Price
}

func (l *Laptop) SetROM(ROM float64) {
l.ROM = ROM
}

func (l *Laptop) SetDiscount(percent float64) {
l.Price -= (l.Price / 100) * percent
}
35 changes: 35 additions & 0 deletions golang/lab7/pc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package lab7

type PC struct {
Model string
Price float64
RAM float64
}

func (c *PC) SetModel(Model string) {
c.Model = Model
}

func (c *PC) SetPrice(Price float64) {
c.Price = Price
}

func (c *PC) GetPrice() float64 {
return c.Price
}

func (c *PC) GetModel() string {
return c.Model
}

func (c *PC) SetDiscount(percent float64) {
c.Price -= (c.Price / 100) * percent
}

func (c *PC) SetRAM(RAM float64) {
c.RAM = RAM
}

func (c *PC) GetRAM() float64 {
return c.RAM
}
30 changes: 30 additions & 0 deletions golang/lab7/phone.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package lab7

type Phone struct {
Size float64
Model string
Price float64
}

func (p *Phone) SetSize(Size float64) {
p.Size = Size
}

func (p *Phone) GetSize() float64 {
return p.Size
}
func (p *Phone) SetModel(Model string) {
p.Model = Model
}

func (p *Phone) SetPrice(Price float64) {
p.Price = Price
}

func (p *Phone) GetPrice() float64 {
return p.Price
}

func (p *Phone) SetDiscount(percent float64) {
p.Price -= (p.Price / 100) * percent
}
7 changes: 7 additions & 0 deletions golang/lab7/productinterface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package lab7

type Product interface {
GetPrice() float64
SetPrice(price float64)
SetDiscount(discount float64)
}
4 changes: 3 additions & 1 deletion golang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"fmt"

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

func main() {
lab4.Lab4()
fmt.Println("Нерабеев Кирилл Сергеевич")
lab4.Lab4()
lab7.Lab7()
}
Loading