Skip to content

Commit

Permalink
HW04 complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Олег Владимирович Евдокимов committed Jan 22, 2024
1 parent 94c81ba commit 3f0c9cf
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions hw04_struct_comparator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,47 @@ import (
"fmt"
)

type book struct {
Id int
Title, Author string
Year, Size int
Rate float32
type Book struct {
id int
title, author string
year, size int
rate float32
}

func (p *book) Print() {
fmt.Println("Id:", p.Id)
fmt.Println("Title:", p.Title)
fmt.Println("Author:", p.Author)
fmt.Println("Year:", p.Year)
fmt.Println("Size:", p.Size)
fmt.Println("Rate:", p.Rate)
type Num int

const (
Year Num = iota
Size
Rate
)

func (p *Book) Print() {
fmt.Println("Id:", p.id)
fmt.Println("Title:", p.title)
fmt.Println("Author:", p.author)
fmt.Println("Year:", p.year)
fmt.Println("Size:", p.size)
fmt.Println("Rate:", p.rate)
}

func main() {
book1 := &book{1, "skazki", "Pushkin", 1825, 23, 4.3}
book2 := &book{2, "drama", "Lermontov", 1817, 302, 4.6}
book1 := &Book{1, "skazki", "Pushkin", 1825, 23, 4.3}
book2 := &Book{2, "drama", "Lermontov", 1817, 302, 4.6}
book1.Print()
fmt.Println("--------------")
book2.Print()
fmt.Println("--------------")

var s string

fmt.Printf("Введите поле для сравнения Year, Size или Rate: ")
fmt.Scanf("%s", &s)
switch {
case s == "Year" || s == "year":
fmt.Println(book1.Year > book2.Year)
fmt.Println(book1.year > book2.year)
case s == "Size" || s == "size":
fmt.Println(book1.Size > book2.Size)
fmt.Println(book1.size > book2.size)
case s == "Rate" || s == "rate":
fmt.Println(book1.Rate > book2.Rate)
fmt.Println(book1.rate > book2.rate)
}
}

0 comments on commit 3f0c9cf

Please sign in to comment.