Skip to content
34 changes: 34 additions & 0 deletions golang/lab4/lab4.go
Original file line number Diff line number Diff line change
@@ -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}))
}
30 changes: 30 additions & 0 deletions golang/lab6/lab6.go
Original file line number Diff line number Diff line change
@@ -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())
}
26 changes: 26 additions & 0 deletions golang/lab7/headphones.go
Original file line number Diff line number Diff line change
@@ -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)
}
39 changes: 39 additions & 0 deletions golang/lab7/lab7.go
Original file line number Diff line number Diff line change
@@ -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())
}
29 changes: 29 additions & 0 deletions golang/lab7/laptop.go
Original file line number Diff line number Diff line change
@@ -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)
}
26 changes: 26 additions & 0 deletions golang/lab7/phone.go
Original file line number Diff line number Diff line change
@@ -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)
}
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"

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()
}