CSE 221 Closed Lab 3 Warm-Up Exercise


For this closed lab, you will be implementing an operation to display the value of an id-name-table object in a "pretty display" format. Here is an example of "pretty display" format. Suppose that id-name table
m = {(4,"Georgia"),(8,"South Carolina"),(1,"Delaware"),(13,"Rhode Island"), (10,"Virginia")}.
Then, pretty display format looks like:

{
    (8, "South Carolina")
    (13, "Rhode Island")
    (1, "Deleware")
    (10, "Virginia")
    (4, "Georgia")
}
Notice that the display begins and ends with opening and closing set braces, respectively, and that each id-name pair appears on a separate line, with each pair indented four spaces from the left. Also notice the space after each comma just before each name. The order in which the pairs appear in the display is not important. For example, the following would also be considered a "pretty display" of m:
{
    (10, "Virginia")
    (1, "Delaware")
    (4, "Georgia")
    (8, "South Carolina")
    (13, "Rhode Island")
}
Write a body for the global operation Display_Id_Name_Table, that has the following specification:
global_procedure Display_Id_Name_table (
        alters    Character_OStream& output,
        preserves Id_Name_Table_Kernel_1_C& m
    );
/*!
    requires
       output.is_open = true 
    ensures
       output.is_open = true  and
       output.ext_name = #output.ext_name  and
       output.content = #output.content * [a "pretty display" of m]
!*/

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 assignment. If you do work with a partner, you need only turn in one solution. Be sure to put the names of both students on the solution that is turned in.