zoukankan      html  css  js  c++  java
  • pre-condition & post-condition

    As we will see, the two statements work together: The precondition indicates what must be true before the function is called.  The postcondition indicates what will be true when the function finishes its work.

    example:

    void write_sqrt(double x) 

    //   Precondition:  x  >=  0.

    //   Postcondition:  The square root of x has been written to the standard output.

    This is an example of a small function which simply writes the square root of a number.  The number is given as a parameter to the function, called x.   For example, if we call write_sqrt(9), then we would expect the function to print 3 (which is the square root of 9).

    What needs to be true in order for this function to successfully carry out its work?  Since negative numbers don't have a square root, we need to ensure that the argument, x, is not negative.  This requirement is expressed in the precondition:

            Precondition: x  >=  0.

    The postcondition is simply a statement expressing what work has been accomplished by the function.  This work might involve reading or writing data, changing the values of variable parameters, or other actions.

    Notice that the information shown on this slide is enough for you to use the function.  You don't need to know what occurs in the function body.

  • 相关阅读:
    【python cookbook学习笔记】给字典增加一个条目
    UI设计星级评价
    弱引用和循环引用
    lua数据类型
    lua虚拟机笔记
    c++对象模型笔记
    使树控件方向键无效
    实现CListCtrl自定义行高
    创建对话框时常用配置
    C++格式化输出总结
  • 原文地址:https://www.cnblogs.com/qingsunny/p/3296766.html
Copyright © 2011-2022 走看看