Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- {
- "created_at" : "Sat Dec 10 07:27:03 IST 2016",
- "aim_of_program" : "Structure"
- "coded_by" : "Rishikesh Agrawani"
- }
- */
- package main
- import "fmt"
- func main() {
- //Defining structure for storing the details of a Person
- type Book struct{
- Name string
- Author string
- Price float32
- Pages int32
- }
- //1st way
- var book1 Book
- book1 = Book{"Go In Action","William Kennedy",430.50,320}
- //2nd way (Direct way of creating Book object)
- book2 := Book{"Playing With Golang", "Rishikesh Agrawani", 300.67,400}
- //3rd way
- var book3 Book = Book{"The Basics Of programming","Rob Pike",500.50,450}
- //Slice of Book (i.e 3 books)
- booksList :=[]Book{book1,book2,book3}
- //Displaying the details of all the 3 books using for loop
- for index,book := range booksList {
- fmt.Println("Book",index+1,"'s details :-\n")
- fmt.Println("Book's name :\t",book.Name)
- fmt.Println("Book's author :\t",book.Author)
- fmt.Println("Book's price :\t",book.Price)
- fmt.Println("Number of pages :\t",book.Pages)
- fmt.Println() //Newline
- }
- }
- /*OUTPUT:-
- Book 1 's details :-
- Book's name : Go In Action
- Book's author : William Kennedy
- Book's price : 430.5
- Number of pages : 320
- Book 2 's details :-
- Book's name : Playing With Golang
- Book's author : Rishikesh Agrawani
- Book's price : 300.67
- Number of pages : 400
- Book 3 's details :-
- Book's name : The Basics Of programming
- Book's author : Rob Pike
- Book's price : 500.5
- Number of pages : 450
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement