Chain of functions

Report a typo

You have an instance of the Musician class. Try to write a chain of three scope functions, which could perform the following actions:

  1. First function body: print the data class and calculate the length of the field name.

  2. Second function body: pass the calculated length of the field name as a parameter, divide it by 4, and print the result on a new line.

  3. Third function body: pass the result of division of length by 4 as a parameter, add 10 to it, and pass this value to a variable num.

After these steps, print the value of num in standard output on a new line.

Sample Input 1:

Ian George Brown
The Stone Roses
Frontman

Sample Output 1:

Musician(name=Ian George Brown, band=The Stone Roses, role=Frontman)
4
14
Write a program in Kotlin
data class Musician(var name: String = "", var band: String = "", var role: String = "")

fun main() {
val musician = Musician()

musician.apply {
name = readln()
band = readln()
role = readln()
}

// Write your code here
}
___

Create a free account to access the full topic