Skip to content
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
36 changes: 36 additions & 0 deletions golang/LAB_4/LAB_4.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package LAB_4

import (
"fmt"
"math"
)

const a = 2.0

func calculateY(x float64) float64 {
y := math.Tan(math.Pow(math.Log10(a+x), 3)) / math.Pow(math.Pow((a+x), 2), 1/7)
return y
}

func TaskA(xn, xk, delx float64) []float64 {
var ValuesY []float64
for x := xn; x <= xk; x += delx {
ValuesY = append(ValuesY, calculateY(x))
}
return ValuesY
}

func TaskB(xv []float64) []float64 {
var ValuesY []float64
for _, x := range xv {
ValuesY = append(ValuesY, calculateY(x))
}
return ValuesY
}

func Lab4() {
xn, xk, delx := 1.08, 1.88, 0.16
xv := []float64{1.16, 1.35, 1.48, 1.52, 1.96}
fmt.Println("Задача А:", TaskA(xn, xk, delx))
fmt.Println("Задача B:", TaskB(xv))
}
44 changes: 44 additions & 0 deletions golang/LAB_6/LAB_6.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package LAB_6

import (
"fmt"
"strconv"
)

const maxRabbitAge = 12

type Rabbit struct {
Name string
Age int
Color string
}

func (rabbit *Rabbit) SetName(name string) {
rabbit.Name = name
}

func (rabbit *Rabbit) SetColor(color string) {
rabbit.Color = color
}
func (rabbit *Rabbit) SetAge(age int) {
if age <= maxRabbitAge {
rabbit.Age = age
} else {
fmt.Println("Ошибка: указанный возраст превышает максимальный возраст кроликов!")
}
}

func (rabbit Rabbit) GetInfo() string {
return "Имя кролика: " + rabbit.Name + "\nВозраст кролика: " + strconv.Itoa(rabbit.Age) + "\nЦвет кролика: " + rabbit.Color
}

func Lab6() {
rabbit := Rabbit{Name: "Беляш", Age: 1, Color: "Белый"}

fmt.Println(rabbit.GetInfo())

rabbit.SetName("Пушок")
rabbit.SetAge(3)

fmt.Println(rabbit.GetInfo())
}
50 changes: 50 additions & 0 deletions golang/LAB_7/LAB_7.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package LAB_7

import "fmt"

type Product interface {
GetName() string
GetPrice() float64
SetPrice(price float64)
ApplyDiscount(discount float64)
}

func Calculate(products []Product) float64 {
total := 0.0
for _, product := range products {
total += product.GetPrice()
}
return total
}

func Lab7() {
iceCream := &IceCream{
Name: "Ванильное",
Brand: "Веселая коровка",
Price: 50.00,
Flavor: "Ваниль",
}
sofa := &Sofa{
Name: "Классический диван",
Price: 20000.00,
Brand: "IKEA",
Color: "Коричневый",
Material: "Кожа",
}

products := []Product{iceCream, sofa}
fmt.Println("Общая стоимость:", Calculate(products))
iceCream.ApplyDiscount(10)
sofa.ApplyDiscount(15)
fmt.Println("Общая стоимость товаров после применения скидок:", Calculate(products))

fmt.Println("Материал дивана:", sofa.Material)
fmt.Println("Цвет дивана:", sofa.Color)
fmt.Println("Вкус мороженого:", iceCream.Flavor)
sofa.ChangeColor("Черный")
sofa.ChangeMaterial("Замша")
iceCream.ChangeFlavor("Шоколад")
fmt.Println("Цвет дивана изменен на:", sofa.Color)
fmt.Println("Материал дивана изменен на:", sofa.Material)
fmt.Println("Вкус мороженого изменен на:", iceCream.Flavor)
}
28 changes: 28 additions & 0 deletions golang/LAB_7/icecream.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package LAB_7

type IceCream struct {
Name string
Brand string
Price float64
Flavor string
}

func (i *IceCream) GetName() string {
return i.Name
}

func (i *IceCream) GetPrice() float64 {
return i.Price
}

func (i *IceCream) SetPrice(price float64) {
i.Price = price
}

func (i *IceCream) ApplyDiscount(discount float64) {
i.Price -= i.Price * discount / 100
}

func (i *IceCream) ChangeFlavor(newFlavor string) {
i.Flavor = newFlavor
}
32 changes: 32 additions & 0 deletions golang/LAB_7/sofa.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package LAB_7

type Sofa struct {
Name string
Price float64
Brand string
Color string
Material string
}

func (s *Sofa) GetName() string {
return s.Name
}

func (s *Sofa) GetPrice() float64 {
return s.Price
}

func (s *Sofa) SetPrice(price float64) {
s.Price = price
}

func (s *Sofa) ApplyDiscount(discount float64) {
s.Price -= s.Price * discount / 100
}

func (s *Sofa) ChangeColor(newColor string) {
s.Color = newColor
}
func (s *Sofa) ChangeMaterial(newMaterial string) {
s.Material = newMaterial
}
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/LAB_4"
"isuct.ru/informatics2022/LAB_6"
"isuct.ru/informatics2022/LAB_7"
)

func main() {
fmt.Println("Hello world")
fmt.Println("Чернов Максим Александрович")
LAB_4.Lab4()
LAB_6.Lab6()
LAB_7.Lab7()
}