zoukankan      html  css  js  c++  java
  • Day8 return function type and inside function

    func tierMailFee (weight:Int) -> Int

    {

        return 2*weight

    }

     

    func tierMailFee2 (weight:Int) -> Int

    {

        return 6*weight;

    }

     

    func chooseMailFeeCalculateMethod( weight:Int) -> (Int)->Int

    {

        return weight<=10 ? tierMailFee : tierMailFee2

    }

     

    func totalPrice( price:Int, weight:Int ) -> Int

    {

        let mailFeeCalculate:(Int) -> Int = chooseMailFeeCalculateMethod(weight)

        

        return mailFeeCalculate(weight) //+ price*weight

    }

     

    totalPrice(3, weight: 11)

     

     

    func payTax (salary:Float) -> Float

    {

        return 3500*0.2

    }

     

    func secodPayTax (salary:Float) -> Float

    {

        return payTax(3500) + (salary-3500)*0.5

    }

     

    func totalPayTax (salary:Float) -> (Float)->Float

    {

        if salary < 3500 {

            return payTax

        }

        else {

            return secodPayTax

        }

    }

     

    func showPayTax (salary:Float) -> Float

    {

        let totalTax  = totalPayTax(salary)

        return totalTax(salary)

    }

     

    showPayTax(10000)

     

  • 相关阅读:
    2017年6月笔记
    2017年5月笔记
    2017年4月笔记
    转发:i p _ f o r w a r d函数
    IP分组
    IP协议首部结构介绍
    IP:网际协议
    sed工具使用
    正则表达式匹配
    TCP的半连接
  • 原文地址:https://www.cnblogs.com/tony0571/p/5381196.html
Copyright © 2011-2022 走看看