Assignment 08
Home ] Up ]

 

CSIS 250 2001 Fall

Assignment 08

Date Assigned:

11/30/2001

Date Due:

During Final

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

bool CInventory::isEqualToSummayCounts(const CInventory &inv, const int counts[]) const

As discussed in the class, the member function calcSummaryCounts determines the distinct records from an inventory object and puts them in alphabetically sorted order and their counts in inv and counts[] respectively.  The next step is to check if this function really works.  For a given inventory collection originalInv, and an inventory object distinctInv together with counts[] which hold only distinct records from originalInv and their counts, develop the isEqualToSummaryCounts member function for CInventory class.

If a given inventory collection originalInv, and an inventory object distinctInv together with counts[]hold only distinct records from originalInv and their counts, then the function call originalInv.isEqualToSummaryCounts(distinctInv, counts) should return true if the distinctInv together with counts[] has only the correct summary of originalInv, otherwise it will return false.  In order to achieve this it will perform the following tests to check if the given inventory (distinctInvtogether withcounts[]) has all the sorted distinct records and summary counts of another inventory (originalInv):

test1.                    count of originalInv should be >= the count of distinctInv

test2.                    distinctInv should not have duplicate records

test3.                    for each record in originalInv there must be only one matching record in distinctInv

test4.                    for every record at position i in distinctInv there must be exactly counts[i] matching records in originalInv

test5.                    total of the values in array counts[] should be equal to the number of records in originalInv.

test6.                    records in distinctInv should be in alphabetical ascending order.

Your function should also display if each of the above six tests were failed or passed by your function.  We will also assume that both lists, originalInv  and distinctInv, are non-empty.

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

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

// testIsEqualToSummayCounts(void);

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

void testIsEqualToSummayCounts(void)

  {

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

    {

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

    cout << "Test Case#:" << i << endl;

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

 

    CInventory originalInv('r');

 

    CInventory distinctInv;

    int counts[MAX_ITEMS];

 

    cout << "originalInv =\n";

    cout << originalInv << endl;

 

    originalInv.calcDistinctCounts(distinctInv, counts);

 

    cout << "distinctInv=\n";

    originalInv.displayDistinctCounts(distinctInv, counts);

 

    if (originalInv.isEqualToSummayCounts(distinctInv, counts))

        cout << "isEqualToSummayCounts test passed\n";

      else

        cout << "isEqualToSummayCounts test failed\n";

 

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

    }

  }

 

Sample Run Output

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

Test Case#:2

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

originalInv =

inventory(9)=

[Table, 22]

[Mouse, 88]

[Clock, 99]

[Couch, 66]

[Knife, 44]

[Knife, 44]

[Spoon, 33]

[Spoon, 33]

[Table, 22]

 

distinctInv=

n  Item

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

1  [Clock, 99]

1  [Couch, 66]

2  [Knife, 44]

1  [Mouse, 88]

2  [Spoon, 33]

2  [Table, 22]

test1: passed

test2: passed

test3: passed

test4: passed

test5: passed

test6: passed

isEqualToSummayCounts test passed


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 project8.cpp and executable code as project8.exe).

4.                  Self-evaluation table.

(Late assignment will not count)

 

 

Self-evaluation Table for Project 08

Your Name:

 

 

Max Score

Score

isEqualToSummaryCounts

Description in your own words

3

 

 

Algorithms in pseudo code

7

 

 

Properly formatted output
(10 cases, 4 points each)

20

 

Total Score

30