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.

  • 相关阅读:
    《分析的艺术》读书笔记
    MySql数据库文件frm的移植
    R语言学习笔记(一)
    GATE使用笔记(使用自带的GUI界面)
    如何解决 Endnote自动搜索word中中括号[ ]或者大括号{}内的文字
    java import中jar包的位置
    hello
    filebeatkafkaelk搭建
    android note3
    iOS 6 SDK: 在应用内展示App Store
  • 原文地址:https://www.cnblogs.com/qingsunny/p/3296766.html
Copyright © 2011-2022 走看看