-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmethodschallenge01.go
More file actions
52 lines (41 loc) · 1.08 KB
/
methodschallenge01.go
File metadata and controls
52 lines (41 loc) · 1.08 KB
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
45
46
47
48
49
50
51
52
/* Alta3 Research | RZFeeser
Methods - defining bookup() to increase the value of books by 1 */
// Go program to illustrate the
// method with struct type receiver
package main
import "fmt"
// Author structure
type author struct {
name string
branch string
books int
salary int
}
// increase value of books by 1
func (a *author) bookup() {
a.books++ // increment name by 1
}
// Method with a receiver
// of author type
func (a author) show() {
fmt.Println("Author's Name: ", a.name)
fmt.Println("Branch Name: ", a.branch)
fmt.Println("Number of books authored: ", a.books)
fmt.Println("Salary: ", a.salary)
}
// Main function
func main() {
// Initializing the values
// of the author structure
res := author{
name: "RZFeeser",
branch: "Pennsylvania",
books: 14,
salary: 34000,
}
// Calling the method
res.show()
// run our new method
res.bookup() // increase books by 1
res.show() // display the new values stored within struct
}