Assignment 09
Home ] Up ]

 


CSIS 250 2001 Fall

Assignment 09 (Extra Credit)

Date Assigned:

11/30/2001

Date Due:

During Final

Add the following member functions to the program discussed in the class:

void CDInventory::sortBubble(void)

bool CDInventory::isSorted(void) const

As discussed in the class, the member function sortBubble sorts the dynamic inventory and the function isSorted determines if the dynamic inventory is sorted on the basis of item weights.

You should run ten test cases to test your function by using the following test function as is:

//++++++++++++++++++++++++++++++++++++++++++++++++++

// testSortBubbleCDInventory

//++++++++++++++++++++++++++++++++++++++++++++++++++

void testSortBubbleCDInventory(void)

  {

  cout << "testSortBubbleCDInventory\n";

  cout << "=========================\n";

  for (int i=1; i<=10; i++)

    {

    cout << "TEST CASE #" << i << endl;

 

    CDInventory yourInv('r');

 

    cout << yourInv;

 

    if (yourInv.isSorted())

        cout << "SORTED\n";

      else

        cout << "NOT SORTED\n";

 

    cout << "After sortBubble\n";

 

    yourInv.sortBubble();

    cout << yourInv;

 

    if (yourInv.isSorted())

        cout << "SORTED\n";

      else

        cout << "NOT SORTED\n";

   

    cout << "-------------------\n";

    }

  }

 

Sample Run Output

testSortBubbleCDInventory

========================

TEST CASE #1

inventory(15)=

[Clock, 99]

[Chair, 11]

[Plier, 13]

[Stool, 16]

[Stool, 16]

[Paper, 14]

[Stand, 15]

[Couch, 66]

[Mouse, 88]

[Couch, 66]

[Couch, 66]

[Couch, 66]

[Stand, 15]

[Spoon, 33]

[Table, 22]

NOT SORTED

After sortBubble

inventory(15)=

[Chair, 11]

[Plier, 13]

[Paper, 14]

[Stand, 15]

[Stand, 15]

[Stool, 16]

[Stool, 16]

[Table, 22]

[Spoon, 33]

[Couch, 66]

[Couch, 66]

[Couch, 66]

[Couch, 66]

[Mouse, 88]

[Clock, 99]

SORTED

-------------------

TEST CASE #2

inventory(7)=

[Paper, 14]

[Chair, 11]

[Clock, 99]

[Paper, 14]

[Cable, 12]

[Couch, 66]

[Clock, 99]

NOT SORTED

After sortBubble

inventory(7)=

[Chair, 11]

[Cable, 12]

[Paper, 14]

[Paper, 14]

[Couch, 66]

[Clock, 99]

[Clock, 99]

SORTED

-------------------

 

Submit the following:

 

1.                  Printed source code of your contribution only, not the entire source code (to get any credit the program has to work).

2.                  Printed output from ten test cases.

3.                  Source code and the executable code on a diskette (name your source as project9.cpp and executable code as project9.exe).

4.                  Self-evaluation table.

(Late assignment will not count)

 

 

Self-evaluation Table for Project 09

Your Name:

 

 

Max Score

Score

sortBubble

Description in your own words

3

 

Detailed algorithm in pseudo code

7

 

isSorted

Description in your own words

3

 

Detailed algorithm in pseudo code

7

 

 

Properly formatted output
(10 cases, 4 points each)

20

 

Total Score

40