Skip to content
Snippets Groups Projects
Commit cf413363 authored by Martin Schmollinger's avatar Martin Schmollinger
Browse files

Solution to exercise of unit 03-05

parent bf3971bd
No related branches found
No related tags found
No related merge requests found
module gitlab.reutlingen-university.de/go-exercises/go-starter/exercise_0305
go 1.20
package main
import "fmt"
type PhoneBook struct {
entries map[int]string
}
func (pb *PhoneBook) AddNumbers(person string, numbers ...int) {
for _, number := range numbers {
pb.entries[number] = person
}
}
func CreateEmptyPhoneBook() PhoneBook {
emptyPB := PhoneBook{
entries: make(map[int]string),
}
return emptyPB
}
func (pb *PhoneBook) PrintPhoneBook() {
for number, person := range pb.entries {
fmt.Printf("%s: %d\n", person, number)
}
}
func main() {
pb := PhoneBook{
entries: map[int]string{
4711: "Marcus",
4712: "Martin",
},
}
pb.AddNumbers("Dominik", 4713, 4714)
pb.PrintPhoneBook()
pb2 := CreateEmptyPhoneBook()
pb2.AddNumbers("Karlo", 1, 2, 3, 4, 5)
pb2.PrintPhoneBook()
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment