Skip to content

Commit

Permalink
Merge pull request #244 from Keezo0/Kostina_Polina_Alekseevna
Browse files Browse the repository at this point in the history
lab5
  • Loading branch information
jskonst authored Dec 23, 2023
2 parents 06d089f + 8263417 commit 3f981bc
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
45 changes: 45 additions & 0 deletions golang/internal/lab5/lab5.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package lab5

import "fmt"

type Employee struct {
name string
age int
date string
}

func (e Employee) Getname() string {
return e.name
}

func (e Employee) Getage() int {
return e.age
}

func (e Employee) Getdate() string {
return e.date
}
func (e *Employee) SetName(name string) {
e.name = name
}

func (e *Employee) SetDate(date string) {
e.date = date
}

func Newemployee(name string, age int, date string) (Employee, error) {
var e Employee = Employee{
name: name,
date: date,
}
var err = e.SetAge(age)
return e, err
}

func (e *Employee) SetAge(age int) error {
if age > 17 && age < 80 {
e.age = age
return nil
}
return fmt.Errorf(e.Getname(), "age is incorrect", e.Getdate())
}
16 changes: 16 additions & 0 deletions golang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,30 @@ package main

import (
"fmt"
"log"

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

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

func main() {
n1 := lab4.Task1(4.1, 2.7, 1.2, 5.2, 0.7)
fmt.Println(n1)
n2 := lab4.Task2(4.1, 2.7, []float64{1.9, 2.15, 2.34, 2.73, 3.16})
fmt.Println(n2)

fmt.Println("Полина Костина")

employee, err := lab5.Newemployee("Павел Павлов", 30, "01/01/2023")
checkForError(err)

fmt.Printf("Employee's age is %d\n", employee.Getage())
fmt.Printf("Eployee's name is %s\n", employee.Getname())
fmt.Printf("Date is %s\n", employee.Getdate())
}

0 comments on commit 3f981bc

Please sign in to comment.