Skip to content

Commit

Permalink
laba_5
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxthrew committed Dec 26, 2023
1 parent 235a051 commit a890aca
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
53 changes: 53 additions & 0 deletions golang/internal/cat/cat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package cat

import (
"fmt"
)

type cat struct {
name string
age uint8
color string
}

func NewCat(name_cat string, age_cat uint8, color string) (cat, error) {
var c cat = cat{
name: name_cat,
}
c.SetColor(color)
var err = c.SetAge(age_cat)
return c, err
}

func (c *cat) Meow() {
fmt.Printf("%s мяукнул", c.GetName())
}

func (c *cat) SetName(name string) {
c.name = name
}

func (c *cat) SetColor(color string) {
c.color = color
}

func (c *cat) SetAge(age uint8) error {
if age <= 50 {
c.age = age
return nil
} else {
return fmt.Errorf("Кошки не живут больше 50 лет!")
}
}

func (c *cat) GetName() string {
return c.name
}

func (c *cat) GetAge() uint8 {
return c.age
}

func (c *cat) GetColor() string {
return c.color
}
19 changes: 19 additions & 0 deletions golang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,29 @@ import (
"fmt"

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

func main() {
fmt.Println("Алексеев Максим Алексеевич | Вариант 1")
fmt.Println(internal.Zadacha_A(1.28, 3.28, 0.4))
fmt.Println(internal.Zadacha_B([]float64{1.1, 2.4, 3.6, 1.7, 3.9}))

cat1, err := cat.NewCat("Барсик", 10, "black")
if err != nil {
fmt.Printf("%v", err)
}
cat1.Meow()
fmt.Printf("\n%v\n", cat1.GetColor())
cat1.SetColor("white")
fmt.Printf("%v\n", cat1.GetColor())
fmt.Printf("%v\n", cat1.GetAge())
cat1.SetAge(30)
fmt.Printf("%v\n", cat1.GetAge())
cat2, err := cat.NewCat("Кузя", 77, "orange")
if err != nil {
fmt.Printf("%v\n", err)
}
fmt.Println(cat2.GetName())
fmt.Println(cat2.GetAge())
}

0 comments on commit a890aca

Please sign in to comment.