Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lab 5(var 24(2)) #285

Open
wants to merge 4 commits into
base: Spiridonova_Polina_Alekseevna
Choose a base branch
from
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
89 changes: 89 additions & 0 deletions golang/lab5/lab5.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package lab5

import (
"errors"
"fmt"
)

// структура лисичка
type fox struct {
name string
age int
color colors
}

func (f fox) GetView() string {
return `
⣿⣿⣿⣿⣿⡟⣦⣌⡙⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠿⠿⣿
⣿⣿⣿⣿⣿⡇⣿⣿⣿⣦⠈⠻⣿⣿⣿⡿⣿⣿⣿⣿⣿⣿⣿⢟⣩⣶⣶⡏⠀⣿
⣿⣿⣿⣿⣿⣇⢻⣿⢹⣿⠇⢀⣿⡿⢿⠿⠮⠯⢾⣿⣿⡿⢡⣿⡿⣽⢿⡇⠀⣿
⣿⣿⣿⣿⣿⣿⣌⠛⠛⣫⠜⠋⠁⢠⠁⠀⠀⠀⠀⠀⠛⣷⡈⢿⡿⣃⡾⠁⣸⣿
⣿⣿⣿⣿⣿⣿⣿⣷⣾⠓⠚⠉⠓⡆⠦⠤⠖⣤⡀⠀⠀⢹⣿⣧⣉⣉⣠⣾⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⠇⣶⣶⣮⣂⢑⣬⣮⣔⢄⠀⠀⠀⠀⢿⠹⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣴⣿⣥⣭⣿⣼⣿⣿⡙⣇⣂⣀⣀⣀⡈⠀⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡿⠛⠛⠉⠙⠻⢿⣛⠿⡻⠀⠀⠀⠀⠀⢀⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣇⣸⠉⢠⢐⡄⠀⠀⠀⠀⠈⣿⠁⠈⣣⠀⠀⠀⠺⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣷⣿⣭⣵⢤⢤⣤⡤⣤⣶⣾⣿⣤⠴⠃⠀⠀⠀⠀⣸⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⢸⡀⣀⣀⣠⣴⣾⣶⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⢟⣿⣿⣿⢟⡟⠁⠀⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⡿⠣⣹⣻⣟⠿⠕⠁⢀⣠⣾⡟⠛⠋⠉⡟⠁⠀⠀⠙⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣠⣶⢻⣷⣀⣠⣤⣖⣿⢏⡾⠀⠀⠀⠘⣇⣀⣤⣶⠟⠛⢻⣿⣿⣿
⣿⣿⣿⣿⡿⠉⢸⣯⡴⠻⣋⣛⣛⣻⡏⠃⠀⠀⠀⠸⣿⣿⡟⠁⡠⠂⠁⠀⠉⠻
`
}
func (f fox) GetName() string {
return f.name
}
func (f fox) GetAge() int {
return f.age
}
func (f fox) GetColor() colors {
return f.color
}

// проверка возраста
func (f *fox) SetAge(age int) error {
if age >= 0 && age < 33 {
f.age = age
return nil
}
ErrorAgeIsIncorrect := errors.New("foxes don't live so long")
return ErrorAgeIsIncorrect
}

// тип colors - установка цвета и проверка
type colors string

const (
red colors = "red"
white colors = "white"
grey colors = "grey"
black colors = "black"
)

// проверка цвета
func (f *fox) SetColor(color colors) error {
switch color {
case red, white, grey, black:
f.color = color
return nil
}
ErrorColorIsIncorrect := errors.New("foxes don't have such color")
return ErrorColorIsIncorrect
}
func NewFox(name string, age int, color colors) (fox, error) {
var f fox = fox{
name: name,
age: age,
color: color}
var err = f.SetAge(age)
if err != nil {
return f, err
} else if err = f.SetColor(color); err != nil {
return f, err
}
return f, err
}
func (f fox) DisplayFox() {
fmt.Printf(" Name - %s\n Age - %d\n Color - %s", f.name, f.age, f.color)
}
20 changes: 20 additions & 0 deletions golang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package main

import (
"fmt"
"log"

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

func main() {
Expand All @@ -22,4 +24,22 @@ func main() {
fmt.Println("Решение задачи под буквой B")
answers = lab4.TaskB(a, b, []float64{2.4, 2.8, 3.9, 4.7, 3.16})
lab4.Output(answers)

fmt.Printf("Структура\n")
foxy, err := lab5.NewFox("Foxy", 5, "red")
if err != nil {
log.Fatal(err)
}
err = foxy.SetAge(5)
if err != nil {
log.Fatal(err)
}

err = foxy.SetColor("red")
if err != nil {
log.Fatal(err)
}
image := foxy.GetView()
fmt.Printf(image)
foxy.DisplayFox()
}