diff --git a/golang/lab4/lab4.go b/golang/lab4/lab4.go new file mode 100644 index 00000000..aebc37bf --- /dev/null +++ b/golang/lab4/lab4.go @@ -0,0 +1,34 @@ +package lab4 + +import ( + "fmt" + "math" +) + +func Calculate(x float64) float64 { + if math.Abs(x) >= 1 { + return (math.Pow(1.2, x)) - (math.Pow(x, 1.2)) + } + return math.Acos(x) +} + +func TaskA(Xmin, Xmax, Xdel float64) []float64 { + var y []float64 + for x := Xmin; x <= Xmax; x += Xdel { + y = append(y, Calculate(x)) + } + return y +} + +func TaskB(x [5]float64) []float64 { + var y []float64 + for _, value := range x { + y = append(y, Calculate(value)) + } + return y +} + +func Runlab4() { + fmt.Println(TaskA(0.2, 2.2, 0.4)) + fmt.Println(TaskB([5]float64{0.1, 0.9, 1.2, 1.5, 1.3})) +} diff --git a/golang/lab6/lab6.go b/golang/lab6/lab6.go new file mode 100644 index 00000000..505dfd4f --- /dev/null +++ b/golang/lab6/lab6.go @@ -0,0 +1,30 @@ +package lab6 + +import "fmt" + +type Phone struct { + Name string + Op string + Number string +} + +func NewPhone(name, op, number string) *Phone { + p := new(Phone) + p.Name = name + p.Op = op + p.Number = number + return p +} + +func (p *Phone) SetNumber(number string) { p.Number = number } +func (p Phone) GetNumber() string { return p.Number } +func (p Phone) GetOp() string { return p.Op } +func (p Phone) GetName() string { return p.Name } + +func Runlab6() { + phone := NewPhone("Влад", "Билайн", "89621658549") + phone.SetNumber("89012863969") + fmt.Println("Имя владельца:", phone.GetName()) + fmt.Println("Оператор сотовой связи:", phone.GetOp()) + fmt.Println("Номер телефона пользователя:", phone.GetNumber()) +} diff --git a/golang/lab7/headphones.go b/golang/lab7/headphones.go new file mode 100644 index 00000000..50d6b5b0 --- /dev/null +++ b/golang/lab7/headphones.go @@ -0,0 +1,26 @@ +package lab7 + +import "fmt" + +type Headphones struct { + Name string + Color string + Price float64 + ReleaseDate string +} + +func (h *Headphones) ApplyDiscount(discount float64) { + h.Price = h.Price * (1 - discount/100) +} +func (h *Headphones) GetPrice() float64 { + return h.Price +} +func (h *Headphones) SetPrice(newPrice float64) { + h.Price = newPrice +} +func (h *Headphones) ChangeColor(newColor string) { + h.Color = newColor +} +func (h *Headphones) getInfo() string { + return fmt.Sprintf("Name: %s, Color: %s, Price: %.2f,ReleaseDate: %s", h.Name, h.Color, h.Price, h.ReleaseDate) +} diff --git a/golang/lab7/lab7.go b/golang/lab7/lab7.go new file mode 100644 index 00000000..4f68b702 --- /dev/null +++ b/golang/lab7/lab7.go @@ -0,0 +1,39 @@ +package lab7 + +import "fmt" + +type Product interface { + ApplyDiscount(discount float64) + SetPrice(newPrice float64) + GetPrice() float64 + getInfo() string +} + +func GetTotalPrice(products []Product) float64 { + var TotalPrice float64 = 0 + for _, Product := range products { + TotalPrice += Product.GetPrice() + } + return TotalPrice +} + +func Runlab7() { + Product1 := &Phones{"iPhone 13", "128gb blue", 50000.0, "13 октября 2020 года"} + Product2 := &Headphones{"Marshall Major IV", "Black", 7200.0, "14 октября 2020 года"} + Product3 := &Laptop{"Huawei matepad 16", 1024, 130000.0, "AMD Ryzen 7 7840U"} + ProductsWithoutDiscount := []Product{Product1, Product2, Product3} + fmt.Printf("Цена без скидки: %2.f рублей\n", GetTotalPrice(ProductsWithoutDiscount)) + Product1.ApplyDiscount(5) + Product2.ApplyDiscount(20) + Product3.ApplyDiscount(25) + fmt.Printf("Цена со скидкой: %2.f рублей\n", GetTotalPrice(ProductsWithoutDiscount)) + fmt.Println(Product1.getInfo()) + fmt.Println(Product2.getInfo()) + fmt.Println(Product3.getInfo()) + Product1.UpdateCharacteristics("256gb red") + fmt.Println(Product1.getInfo()) + Product2.ChangeColor("Brown") + fmt.Println(Product2.getInfo()) + Product3.ChangeCPU("i5 13500H") + fmt.Println(Product3.getInfo()) +} diff --git a/golang/lab7/laptop.go b/golang/lab7/laptop.go new file mode 100644 index 00000000..e677c153 --- /dev/null +++ b/golang/lab7/laptop.go @@ -0,0 +1,29 @@ +package lab7 + +import "fmt" + +type Laptop struct { + Name string + GB float64 + Price float64 + CPU string +} + +func (l *Laptop) ApplyDiscount(discount float64) { + l.Price = l.Price * (1 - discount/100) +} + +func (l *Laptop) GetPrice() float64 { + return l.Price +} +func (l *Laptop) SetPrice(newPrice float64) { + l.Price = newPrice +} + +func (l *Laptop) ChangeCPU(newCPU string) { + l.CPU = newCPU +} + +func (l *Laptop) getInfo() string { + return fmt.Sprintf("Name: %s, GB: %.2f , Price: %.2f,CPU: %s", l.Name, l.GB, l.Price, l.CPU) +} diff --git a/golang/lab7/phone.go b/golang/lab7/phone.go new file mode 100644 index 00000000..af375703 --- /dev/null +++ b/golang/lab7/phone.go @@ -0,0 +1,26 @@ +package lab7 + +import "fmt" + +type Phones struct { + Name string + Characteristics string + Price float64 + ReleaseDate string +} + +func (p *Phones) ApplyDiscount(discount float64) { + p.Price = p.Price * (1 - discount/100) +} +func (p *Phones) GetPrice() float64 { + return p.Price +} +func (p *Phones) SetPrice(newPrice float64) { + p.Price = newPrice +} +func (p *Phones) UpdateCharacteristics(newCharacteristics string) { + p.Characteristics = newCharacteristics +} +func (p *Phones) getInfo() string { + return fmt.Sprintf("Name: %s, Characteristics: %s, Price: %.2f,ReleaseDate: %s", p.Name, p.Characteristics, p.Price, p.ReleaseDate) +} diff --git a/golang/main.go b/golang/main.go index 792a1dbc..91358159 100644 --- a/golang/main.go +++ b/golang/main.go @@ -1,7 +1,16 @@ package main -import "fmt" +import ( + "fmt" + + lab4 "isuct.ru/informatics2022/lab4" + lab6 "isuct.ru/informatics2022/lab6" + lab7 "isuct.ru/informatics2022/lab7" +) func main() { - fmt.Println("Гретченко Владислав") + fmt.Println("Гретченко Владислав Игоревич") + lab4.Runlab4() + lab6.Runlab6() + lab7.Runlab7() }