diff --git a/golang/lab6/lab6.go b/golang/lab6/lab6.go new file mode 100644 index 00000000..72b92c74 --- /dev/null +++ b/golang/lab6/lab6.go @@ -0,0 +1,66 @@ +package lab6 + +import ( + "fmt" + "strconv" +) + +const maxPowerUsage = 800 + +type PC struct { + Brand string + GPU string + CPU string + PowerUsage int + Storage int +} + +func (pc *PC) SetBrand(brand string) { + pc.Brand = brand +} + +func (pc *PC) SetPowerUsage(powerUsage int) { + if powerUsage > maxPowerUsage { + fmt.Println("Ошибка: превышение максимальной мощности потребления!") + } else { + pc.PowerUsage = powerUsage + } +} + +func (pc *PC) SetGPU(gpu string) { + pc.GPU = gpu +} + +func (pc *PC) SetCPU(cpu string) { + pc.CPU = cpu +} + +func (pc *PC) SetStorage(storage int) { + pc.Storage = storage +} + +func (pc *PC) GetInfo() string { + return "Бренд: " + pc.Brand + "\n" + + "Процессор: " + pc.CPU + "\n" + + "Видеокарта: " + pc.GPU + "\n" + + "Жесткий диск: " + strconv.Itoa(pc.Storage) + " Гб\n" + + "Энергопотребление: " + strconv.Itoa(pc.PowerUsage) + " Вт" +} + +func RunLab6() { + pc := PC{ + Brand: "LG", + CPU: "Intel Xeon 231", + GPU: "Nvidia 1050 GTX", + Storage: 256, + PowerUsage: 300, + } + fmt.Println(pc.GetInfo()) + + pc.SetBrand("BMW") + pc.SetCPU("Razen Radeon 5632") + pc.SetGPU("Invoker RTX SunsrikeSuper 2090") + pc.SetStorage(512) + pc.SetPowerUsage(2000) + fmt.Println(pc.GetInfo()) +} diff --git a/golang/lab7/lab7.go b/golang/lab7/lab7.go new file mode 100644 index 00000000..26b5d7bf --- /dev/null +++ b/golang/lab7/lab7.go @@ -0,0 +1,36 @@ +package lab7 + +import ( + "fmt" +) + +type Product interface { + GetName() string + GetPrice() float64 + ApplyDiscount(discount float64) +} + +func Calculate(products []Product) float64 { + total := 0.0 + for _, product := range products { + total += product.GetPrice() + } + return total +} + +func RunLab7() { + phone := &Phone{"Самсунг Колдснеп эс 18", 2000.00, "Самсунг", 30} + tablet := &Tablet{"Эпл Торнадо Фордж 2", 4000.00, "Эпл", 40} + products := []Product{phone, tablet} + fmt.Println("Общая стоимость", Calculate(products)) + phone.ApplyDiscount(10) + tablet.ApplyDiscount(15) + fmt.Println("Стоимость товаров после скидок", Calculate(products)) + + fmt.Println("Объём памяти телефона:", phone.Storage, "ГБ") + fmt.Println("Объём памяти планшета:", tablet.Storage, "ГБ") + phone.ChangeStorage(128) + tablet.ChangeStorage(256) + fmt.Println("Изменённый объём памяти телефона:", phone.Storage, "ГБ") + fmt.Println("Изменённый объём памяти планшета:", tablet.Storage, "ГБ") +} diff --git a/golang/lab7/phone.go b/golang/lab7/phone.go new file mode 100644 index 00000000..1fb16cd5 --- /dev/null +++ b/golang/lab7/phone.go @@ -0,0 +1,28 @@ +package lab7 + +type Phone struct { + Name string + Price float64 + Brand string + Storage float64 +} + +func (p *Phone) GetName() string { + return p.Name +} + +func (p *Phone) GetPrice() float64 { + return p.Price +} + +func (p *Phone) GetBrand() string { + return p.Brand +} + +func (p *Phone) ApplyDiscount(discount float64) { + p.Price -= p.Price * discount / 100 +} + +func (p *Phone) ChangeStorage(newStorageSize float64) { + p.Storage = newStorageSize +} diff --git a/golang/lab7/tablet.go b/golang/lab7/tablet.go new file mode 100644 index 00000000..f2f5b6a3 --- /dev/null +++ b/golang/lab7/tablet.go @@ -0,0 +1,28 @@ +package lab7 + +type Tablet struct { + Name string + Price float64 + Brand string + Storage float64 +} + +func (t *Tablet) GetName() string { + return t.Name +} + +func (t *Tablet) GetPrice() float64 { + return t.Price +} + +func (t *Tablet) GetBrand() string { + return t.Brand +} + +func (t *Tablet) ApplyDiscount(discount float64) { + t.Price -= t.Price * discount / 100 +} + +func (t *Tablet) ChangeStorage(newStorageSize float64) { + t.Storage = newStorageSize +} diff --git a/golang/main.go b/golang/main.go index 216964da..9e596d44 100644 --- a/golang/main.go +++ b/golang/main.go @@ -4,9 +4,13 @@ import ( "fmt" "isuct.ru/informatics2022/lab4" + "isuct.ru/informatics2022/lab6" + "isuct.ru/informatics2022/lab7" ) func main() { fmt.Println("Ворошилов Ефим Александрович") lab4.RunLab4() + lab6.RunLab6() + lab7.RunLab7() }