Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Сделал 7 лабу #512

Open
wants to merge 23 commits into
base: Kapitsyn_Danila
Choose a base branch
from
Open
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
18 changes: 1 addition & 17 deletions golang/go.sum
Original file line number Diff line number Diff line change
@@ -1,17 +1 @@
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=

26 changes: 26 additions & 0 deletions golang/lab4/lab4.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package lab4

import (
"fmt"
"math"
)

func lab4(a, x float64) float64 {
return (math.Pow(a, math.Pow(x, 2)-1) - math.Log10(math.Pow(x, 2)-1) + math.Cbrt(math.Pow(x, 2)-1))
}
func lab4A(imin float64, imax float64, razn float64, a float64) {
for i := imin; i < imax; i += razn {
fmt.Println(lab4(a, i))
}
}
func lab4B(x []float64, a float64) {
for _, value := range x {
fmt.Println(lab4(a, value))
}
}
func Lab4AB() {
var a float64 = 1.6
var x = []float64{1.28, 1.36, 2.47, 3.68, 4.56}
lab4A(1.2, 3.7, 0.5, a)
lab4B(x, a)
}
41 changes: 41 additions & 0 deletions golang/lab6/lab6.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package lab6

import (
"fmt"
)

type Person struct {
Name string
Age int
Country string
}

func (c *Person) SetAge(age int) {
c.Age = age
}

func (c *Person) SetCountry(country string) {
c.Country = country
}

func (c *Person) DisplayInfo() {
fmt.Println("Имя:", c.Name)
fmt.Println("Возраст:", c.Age)
fmt.Println("Страна:", c.Country)
}

func Lab6() {
Yan := Person{
Name: "Ян",
Age: 20,
Country: "Россия",
}

Yan.DisplayInfo()

Yan.SetAge(31)

Yan.SetCountry("Беларусь")

Yan.DisplayInfo()
}
64 changes: 64 additions & 0 deletions golang/lab7/lab7.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package lab7

import "fmt"

// Интерфейс Product
type Product interface {
GetPrice() float64
SetPrice(price float64)
GetDiscount() float64
SetDiscount(discount float64)
GetName() string
SetName(name string)
}

// Структура ProductBase
type ProductBase struct {
price float64
discount float64
name string
}

func (p *ProductBase) GetPrice() float64 {
return p.price
}

func (p *ProductBase) SetPrice(price float64) {
p.price = price
}

func (p *ProductBase) GetDiscount() float64 {
return p.discount
}

func (p *ProductBase) SetDiscount(discount float64) {
p.discount = discount
}

func (p *ProductBase) GetName() string {
return p.name
}

func (p *ProductBase) SetName(name string) {
p.name = name
}

// Функция для расчета стоимости списка товаров
func CalculateTotalPrice(products []Product) float64 {
totalPrice := 0.0
for _, product := range products {
totalPrice += product.GetPrice() * (1 - product.GetDiscount())
}
return totalPrice
}

func Lab7() {
// Создание продуктов
iphone := &ProductBase{price: 100, discount: 0.1, name: "Айфон"}
ipad := &ProductBase{price: 200, discount: 0.2, name: "Айпад"}

// Расчет стоимости списка товаров
totalPrice := CalculateTotalPrice([]Product{iphone, ipad})
fmt.Println("Общая цена:", totalPrice)
}

13 changes: 11 additions & 2 deletions golang/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
package main

import "fmt"
import (
"fmt"

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

func main() {
fmt.Println("Капицын Данила Сергеевич")
fmt.Println("TEST")
lab4.Lab4AB()
lab6.Lab6()
lab7.Lab7()
}
Loading