-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathstruct_test1.go
44 lines (37 loc) · 1.03 KB
/
struct_test1.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// struct_test.go
package main
import (
"fmt"
)
type Book struct {
book_id int
author string
title string
subject string
}
func main() {
var book1 Book
var book2 Book
book1.book_id = 1
book1.author = "lryong1"
book1.title = "book test1"
book1.subject = "test1"
book2.book_id = 2
book2.author = "lryong2"
book2.title = "book test2"
book2.subject = "test2"
fmt.Printf("Book 1 title : %s\n", book1.title)
fmt.Printf("Book 1 author : %s\n", book1.author)
fmt.Printf("Book 1 subject : %s\n", book1.subject)
fmt.Printf("Book 1 book_id : %d\n", book1.book_id)
fmt.Printf("Cal's result is %d\n", book1.cal_pages_nums())
fmt.Println("==============================")
fmt.Printf("Book 1 title : %s\n", book2.title)
fmt.Printf("Book 1 author : %s\n", book2.author)
fmt.Printf("Book 1 subject : %s\n", book2.subject)
fmt.Printf("Book 1 book_id : %d\n", book2.book_id)
fmt.Printf("Cal's result is %d\n", book2.cal_pages_nums())
}
func (a Book) cal_pages_nums() int {
return a.book_id << 2
}