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

lab5 #299

Open
wants to merge 1 commit into
base: Jakovleva_Alena_Olegovna
Choose a base branch
from
Open

lab5 #299

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
57 changes: 57 additions & 0 deletions golang/internal/laba5/laba5.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package laba5
import (
"errors"
)
type (
Year int
Killogram int
)
const (
ErrIncorrectYear = "неправильный возраст"
ErrIncorrectKillogram = "неправильный вес"
)
type Dog struct {
age Year
ves Killogram
poroda string
}
func (d * Dog) SetAge(age Year) error{
if age >= 0 && age <= 20{
d.age = age
return nil
}
return errors.New(ErrIncorrectYear)
}
func (d * Dog) SetVes(ves Killogram) error{
if ves >= 5 && ves <= 65{
d.ves = ves
return nil
}
return errors.New(ErrIncorrectKillogram)
}
func (d * Dog) SetPoroda(poroda string){
d.poroda = poroda
}
func (d Dog) GetAge() Year{
return d.age
}
func (d Dog) GetVes() Killogram{
return d.ves
}
func (d Dog) GetPoroda() string{
return d.poroda
}
func NewDog(age Year, ves Killogram, poroda string)(*Dog, error){
tmp := &Dog{
age: age,
ves : ves,
poroda: poroda,
}
if err := tmp.SetAge(age); err != nil{
return nil, err
}
if err := tmp.SetVes(ves); err != nil{
return nil, err
}
return tmp, nil
}
9 changes: 9 additions & 0 deletions golang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@ import (
"fmt"

"isuct.ru/informatics2022/internal/laba4"
"isuct.ru/informatics2022/internal/laba5"
)

func main() {
fmt.Println("Яковлева Алёна")
dog, err := laba5.NewDog(20, 65, "Овчарка")
if err == nil {
fmt.Printf("Dog age is %d\n", dog.GetAge())
fmt.Printf("Dog ves is %d\n", dog.GetVes())
fmt.Printf("Dog poroda is %s\n", dog.GetPoroda())
}else{
fmt.Println(err)
}
y1 := laba4.Task1(0.22, 0.92, 0.14)
y2 := laba4.Task2([]float64{0.1, 0.35, 0.4, 0.55, 0.6})
fmt.Println(y1)
Expand Down
Loading