CSE 221 Closed Lab 6 Warm-Up Exercise


Natural_Number_1_C comes equipped with the handy operation Convert_From_Integer that converts the value of an Integer object to the corresponding value for a Natural_Number_1_C object. For the next closed lab, you will be implementing the other conversion operation, Convert_To_Integer, that converts the value of a Natural_Number_1_C object to the corresponding value for an Integer object. Believe it or not, this is most easily done if you use only the operations from Natural_Kernel:

Design and code, on paper, the body of Convert_To_Integer. Review your code carefully and trace it on some examples, but do not enter it into the computer until closed lab. The objective is to have code that works the first time you type it in (except perhaps for typos).

Since two students share a workstation during closed lab, if you want to you may work with a partner on this homework exercise. If you do work with a partner, you need only turn in one solution for this homework. Be sure to put the names of both students on the solution that is turned in.

    global_function Integer Convert_To_Integer (
            preserves Natural_Number_1_C& n
        );
    /*!
        requires
           n <= MAXIMUM_INTEGER
        ensures
           Convert_To_Integer = n
    !*/