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

added lab5 #287

Open
wants to merge 1 commit into
base: Zhukov_Daniil_Evgenevich
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
59 changes: 59 additions & 0 deletions golang/internal/lab5/rabbitStruct.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package lab5

import (
"fmt"
"log"
)

type rabbit struct {
age int
name string
weight float64
}

func Newrabbit(age int, name string, weight float64) (rabbit, error) {
var r rabbit = rabbit{
name: name,
weight: weight,
}
var err = r.Setage(age)
return r, err
}

func (r *rabbit) Getage() int {
return r.age
}

func (r *rabbit) Setage(age int) error {
if age >= 0 && age <= 10 {
r.age = age
return nil
}
return fmt.Errorf("Rabbit %s's age is incorrect", (r.Getname()))
}

func (r *rabbit) Getname() string {
return r.name
}

func (r *rabbit) Setname(name string) {
r.name = name
}

func (r *rabbit) Getweight() float64 {
return r.weight
}

func (r *rabbit) Setweight(weight float64) {
r.weight = weight
}

func Rabbitinfo(r *rabbit) {
fmt.Println("rabbit's age is", r.Getage(), "\nrabbit's name is", r.Getname(), "\nrabbit's weight is", r.Getweight())
}

func Checkforeror(err error) {
if err != nil {
log.Fatal(err)
}
}
13 changes: 12 additions & 1 deletion golang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@ package main

import (
"fmt"

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

func main() {
fmt.Println("Жуков Даниил Евгеньевич")
fmt.Println("Жуков Даниил Евгеньевич")
fmt.Println(internal.TaskA(0.7, 2.2, 0.3))
fmt.Println(internal.TaskB([]float64{0.25, 0.36, 0.56, 0.94, 1.28}))
rabbit1, err := lab5.Newrabbit(3, "Benjamin", 5)
lab5.Checkforeror(err)
lab5.Rabbitinfo(&rabbit1)
rabbit2, err := lab5.Newrabbit(7, "Dima", 10)
lab5.Checkforeror(err)
lab5.Rabbitinfo(&rabbit2)
rabbit3, err := lab5.Newrabbit(20, "Alice", 15)
lab5.Checkforeror(err)
lab5.Rabbitinfo(&rabbit3)
}