Accessing promoted fields directly

Report a typo

Below you will see another implementation of the Team and FootballPlayer structs. Please add the Team struct as an anonymous field within the FootballPlayer struct, and also write the additional code required to assign the variables tn and cn to the promoted fields teamName and coachName.

Finally, the program should print the player struct.

Sample Input 1:

Neuer 35 Goalkeeper
Bayern Nagelsmann

Sample Output 1:

{Neuer 35 Goalkeeper {Bayern Nagelsmann}}
Write a program in Go
package main

import "fmt"

type FootballPlayer struct {
Name string
Age int
Position string
? // add 'Team' as an anonymous field within the FootballPlayer struct
}

type Team struct {
teamName string
coachName string
}

func main() {
// do not delete the 'player' FootballPlayer declaration!
var player FootballPlayer
fmt.Scanln(&player.Name, &player.Age, &player.Position)

// do not delete the code block below:
var tn, cn string
fmt.Scanln(&tn, &cn)

// Assign the two variables 'tn' and 'cn' to the promoted fields:
player.? = ?
player.? = ?

fmt.Println(?) // print the player struct here!
}
___

Create a free account to access the full topic