From 2f4d62d2008df41ec462d5751043aadb5605a484 Mon Sep 17 00:00:00 2001 From: kokter Date: Sun, 24 Dec 2023 19:00:49 +0300 Subject: [PATCH] lab5 --- golang/internal/lab5/lab5.go | 29 +++++++++++++++++++++++++++++ golang/main.go | 10 ++++++++++ 2 files changed, 39 insertions(+) create mode 100644 golang/internal/lab5/lab5.go diff --git a/golang/internal/lab5/lab5.go b/golang/internal/lab5/lab5.go new file mode 100644 index 00000000..f0694a10 --- /dev/null +++ b/golang/internal/lab5/lab5.go @@ -0,0 +1,29 @@ +package lab5 + +import "fmt" + +type cat struct { + age uint64 + breed string + name string +} + +func CreateStruct(age uint64, breed, name string) cat { + return cat{age, breed, name} +} + +func SetAge(new_age uint64, c *cat) uint64 { + c.age = new_age + return c.age +} +func SetBreed(new_breed string, c *cat) string { + c.breed = new_breed + return c.breed +} +func SetName(new_name string, c *cat) string { + c.name = new_name + return c.name +} +func PrintInfCat(c *cat) { + fmt.Println("Cat's name is", c.name, "\nCat's breed is", c.breed, "\nCat's age is", c.age, "\n") +} diff --git a/golang/main.go b/golang/main.go index 894c7da8..92b51294 100644 --- a/golang/main.go +++ b/golang/main.go @@ -4,9 +4,11 @@ import ( "fmt" "isuct.ru/informatics2022/internal/lab4" + "isuct.ru/informatics2022/internal/lab5" ) func main() { + fmt.Println("lab 4") a := 2.25 Xs := 1.2 Xe := 2.7 @@ -22,4 +24,12 @@ func main() { for i := range y { fmt.Println("При x=", x[i], "y=", y[i]) } + // lab 5 + fmt.Println("lab 5") + cat := lab5.CreateStruct(5, "Siamese", "Alice") + lab5.PrintInfCat(&cat) + lab5.SetAge(7, &cat) + lab5.SetBreed("British", &cat) + lab5.SetName("Oleg", &cat) + lab5.PrintInfCat(&cat) }