A field with the slice of struct type

Report a typo

Below you will see a Go program that has the Artist struct.

As you know, an Artist usually has one or more songs. Your task is to do the following:

  1. Create the Song struct. It must have two fields: Title of the string type and Duration of the int type.
  2. Update the Artist struct and add the field Songs of the []Song type, so every Artist can have one or more songs.

Sample Input 1:

Metallica
One Fuel
447 270

Sample Output 1:

{Metallica [{One 447} {Fuel 270}]}
Write a program in Go
package main

import "fmt"

// Add the field 'Songs' of the '[]Song' type to the Artist struct below:
type Artist struct {
Name string
? ?
}

type Song struct {
? ? // song title
? ? // song duration in seconds
}

// DO NOT modify the code within the main function!
func main() {
artist := createArtist()
fmt.Println(artist)
}
___

Create a free account to access the full topic