Skip to content
Open

lab5 #276

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
53 changes: 53 additions & 0 deletions golang/internal/lab5/lab5.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package lab5

import (
"fmt"
)

type tv struct {
model string
color string
sound int
}

func NewTv(tv_model, tv_color string, tv_sound int) (tv, error) {
var t tv = tv{
model: tv_model,
}
t.SetColor(tv_color)
var err = t.SetSound(tv_sound)
return t, err
}

func (t *tv) TurnOn() {
fmt.Printf("%s включился", t.GetModel())
}

func (t *tv) SetModel(model string) {
t.model = model
}

func (t *tv) SetColor(color string) {
t.color = color
}

func (t *tv) SetSound(sound int) error {
if sound <= 100 && sound >= 0 {
t.sound = sound
return nil
} else {
return fmt.Errorf("Громкость может быть от 0 до 100")
}
}

func (t *tv) GetModel() string {
return t.model
}

func (t *tv) GetColor() string {
return t.color
}

func (t *tv) GetSound() int {
return t.sound
}
19 changes: 18 additions & 1 deletion golang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,28 @@ import (
"fmt"

"isuct.ru/informatics2022/internal"
"isuct.ru/informatics2022/internal/lab5"
)

func main() {
fmt.Println("Иванова Анастасия Евгеньевна")
fmt.Println("Вариант 7")
fmt.Println(internal.Task_A(3.2, 6.2, 0.6))
fmt.Println(internal.Task_B([]float64{4.48, 3.56, 2.78, 5.28, 3.21}))

fmt.Println("Lab 5")
fmt.Println("Телевизор 1")
tv1, err := lab5.NewTv("Samsung", "Black", 63)
if err != nil {
fmt.Printf("%v", err)
}
fmt.Println(tv1.GetSound())
tv1.SetSound(25)
fmt.Println(tv1.GetSound())
tv1.TurnOn()
fmt.Println("\nТелевизор 2")
tv2, err := lab5.NewTv("Xiaomi", "White", 120)
if err != nil {
fmt.Printf("%v\n", err)
}
fmt.Println(tv2.GetModel())
}