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

laba_5 #274

Open
wants to merge 1 commit into
base: Alekseev_Maksim_Alekseevich
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
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())
}