Example of functional decomposition

Report a typo

Take a look at the following examples:

1) 

fun main() {
    val number = readln().toInt()
    if (number > 0) {
        println("Initial number: $number")
        val newNumber = number - number * number
        println("New number after calculations is $newNumber")
    } else if (number < 0) {
        println("Initial number: $number")
        val newNumber = number + number * number
        println("New number after calculations is $newNumber")
    } else {
        println("Initial number: $number")
        println("No calculations here")
    }
}
2)

class Customer

fun enterDetails(credentials: String): Customer {
    // something here
}

fun isNewCustomer(customer: Customer): Boolean {
    // something here
}

fun createLoginAndPassword(login: String, password: String) {
    // something here
}

fun registerMe() {
    val credentials: String = "" // somehow get credentials
    val customer: Customer = enterDetails(credentials)
    if (isNewCustomer(customer)) {
        val login: String = "" // somehow get login
        val password: String = "" // somehow get password
        createLoginAndPassword(login, password)
    } else {
        // something here
    }
}

fun main() {
    registerMe()
}
3)

fun main() {
    val number = readln().toInt()
    while (number > 0)
    if (number % 3 == 0) {
        println("Fizz")
    } else if (number % 5 == 0) {
        println("Buzz")
    } else if (number % 3 != 0 && number % 5 != 0) {
        println("FizzBuzz")
    }
}
4)

fun actionIsCorrect(action: String): Boolean {
    // something here
}

fun remainingValue() {
    // something here
}

fun fillMl() {
    // something here
}

fun buyCoffee() {
    // something here
}

fun takeCoffee() {
    // something here
}

fun main() {
    val action = readln()
    if (!actionIsCorrect(action)) {
        // something here
    } else {
        when (action) {
            "remaining" -> {
                remainingValue()
            }
            "fill" -> {
                fillMl()
            }
            "buy" -> {
                buyCoffee()
            }
            "take" -> {
                takeCoffee()
            }
        }
    }
}

Which ones are examples of functional decomposition?

Select one or more options from the list
___

Create a free account to access the full topic