CSE 221 Closed Lab 7 Warm-Up Exercise


It's hard to read the display of a very large number if all you see are the digits. That's why we normally insert a separator character after every group of three digits, from right to left. In the U.S. this separator is a comma. So the number 12345678 usually appears as 12,345,678.

Write a body for the procedure Put_To_With_Commas to output the value of self in the above format. Note that Put_To_With_Commas will be implemented in a concrete instance class that extends Natural_Number_1_C. Also note that self is preserved by this operation! HINT: This is much easier to do recursively than iteratively.

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.

    procedure Put_To_With_Commas (
            alters Character_OStream& output
        ) is_abstract;
    /*!
        preserves self
        requires
            output.is_open = true
        ensures
            output.is_open = true  and
            output.ext_name = #output.ext_name  and
            output.content = #output.content * [display of self with commas]
    !*/