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 @ #291

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

import (
"fmt"
)

type dog struct {
age int
name string
gender string
}

func (d dog) GetAge() int {
return d.age
}

func (d dog) GetName() string {
return d.name
}

func (d dog) GetGender() string {
return d.gender
}

func TheDog(dog_age int, dog_name, dog_gender string) (dog, error) {
var d dog = dog{
name: dog_name,
gender: dog_gender,
}
var err = d.SetAge(dog_age)
return d, err
}

func (d *dog) SetAge(age int) error {
if age > 0 && age < 15 {
d.age = age
return nil
}
return fmt.Errorf("Sobaka %s s defektom", d.GetName())
}
17 changes: 17 additions & 0 deletions golang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ package main

import (
"fmt"
"log"

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

func checkForError(err error) {
if err != nil {
log.Fatal(err)
}
}

const a float64 = 2.0
const b float64 = 0.95
const xStart float64 = 1.25
Expand All @@ -22,4 +30,13 @@ func main() {
fmt.Println("Задача Б:")
xesResults := internal.CalculateFuncForXes(a, b, []float64{2.2, 3.78, 4.51, 6.58, 1.2})
fmt.Println(xesResults)

fmt.Println("Lab 5")

dog, err := lab5.TheDog(16, "Oleg", "male")
checkForError(err)

fmt.Printf("Sobake %d let\n", dog.GetAge())
fmt.Printf("Imya %s\n", dog.GetName())
fmt.Printf("Sobaka - %s", dog.GetGender())
}