Help with C++ PROGRAMMING

Sorting the elements of an array is a task that’s often required. It’s also often necessary to sort on more than one field. For example, a two-dimensional table that contains the year and date may have to be sorted on all of those fields. We’d usually first sort on the year and then sort on the date. Note that in multi-field sorting, one has to pay careful attention to which field is sorted first, which is sorted second, etc. For example, in the preceding situation we wouldn’t usually sort first on Employee Number and then on Monthly Pay.

Problem Statement
For this lab, we’ll use the two-dimensional table , call it ‘employees’, shown below. Don’t include the headings in your array, of course, they’re there for explanatory purposes.

Employee Number Monthly Pay
5 1050
17 1200
12 1225
23 1300
6 1140
3 1110
4 1420
1 1360
14 1225
11 1380
10 1410
2 1565
8 1445
7 1387
9 1128
16 1488

For this lab, your job will be to write a program that sorts a table like the above on the two fields ‘Employee Number’ and ‘Monthly Pay’. Sort first on Employee Number, then, within each Employee Number sort on Monthly Pay. Use any sort, quick, bubble. Write a function called ‘sortem()’ that does the actual sorting. It should be displayed in a format similar to that above. The data shown is just for your own testing purposes. To ensure that your program works with other data, you may want to test it on some data you make up. Assume in your program that the maximum size that will be needed for the employees table is 16-by-2, i.e., ‘employees’ should be declared as shown below:
short employees[16][2];

You can also use parallel arrays to the sorting.

Ramat22
Asked Dec 10, 2009

TIP: If it's not your answer to this question, please click "Leave a Comment" button under the question to communicate with the question owner.

Categories