(Latest Revision: 09/25/99)

Making Versions of a List Program

CS 2500 PROGRAMMING ASSIGNMENT THREE
Part Two: The Ordered List Class


DUE DATE:

Please read chapter 3 of your textbook (Carrano) for help in understanding this assignment.

Also, you are expected to read the class documents entitled:

before beginning to do this or any programming assignment. You will find the documents under "CourseDocuments" in the class web space.

THE ASSIGNMENT
For this assignment, you will do a re-write of the program you wrote for Programming Assignment Three, Part One.

This re-write will do exactly what the old program did, but will differ from it in how it does what it does.

This re-write will require you to create versions of listCls.h and listCls.cpp that implement an ordered, static, array-based list (ordered by ascending serial number). Also, you will modify your main program as necessary to properly employ the new versions of listCls.h and listCls.cpp.

DETAILS OF THE RE-WRITE:
This is a synopsis of information I will share with the class:

For this part of the assignment, begin by re-writing the listClass defined by the files listCls.h and listCls.cpp in this directory so that the class automatically keeps the list in sorted order. Each time a list element is inserted, the ListInsert function must decide on the particular position the element must have so that the list will stay in order by serial number.

The central problem in this re-write is to convert listClass::ListInsert, so that it inserts by key-value (serial number) instead of by position. For completeness, also re-write listClass::ListDelete so it deletes by key-value.

Perhaps the easiest way to convert the two functions above involves writing a separate function that converts a KEY VALUE to a POSITION. Say, you call the new function PosOfKey.

The new versions of ListInsert and ListDelete can first make a call to PosOfKey to determine the position corresponding to the key value that has been input. Once they have the position, they can proceed basically as the old versions of the functions would have done. Thus the changes to these functions will involve little more than adding a call to PosOfKey at the beginning.

Of course, the position parameter should be taken out of the parameter lists of ListInsert and ListDelete, because it is no longer appropriate for the caller to furnish a position.

Also you will need to change the header comments for ListInsert and for ListDelete, and you will have to write a header comment for PosOfKey.

The definition of "Success" will change in ListInsert and ListDelete, so you will have to rewrite the code that sets the "Success" parameter.

Read chapter four to get some more insight on what PosOfKey does. Also, here is a pseudo-code version:

/* This function sets Success to true if the list contains an element with key matching theKey. Otherwise it sets it to false.

In the case Success=true, the value returned by the function is the position the matching element has in the list.

In the case Success=false, the value returned is the position an element with key value equal to theKey should have.

If all the elements in the list have keys smaller than theKey, then a new element with key equal to theKey should be appended at the end of the list. Otherwise, the position should be the position of the first element in the current list with key greater than theKey.
*/
int PosOfKey (keyType theKey, bool& Success) const
{
  Position <-- 1;
  while (Position <= lastPosition in list)
          AND (the list element at Position has key smaller
               than theKey)
  do add 1 to Position ;
  if Position is now more than lastPosition then Success <-- false
  else if the list element at Position has key equal to theKey
       then Success <-- true
       else Success <-- false ;
  return the value of Position ;
}
THE MAIN PROGRAM FILE:
Once you have made the needed changes to the list class files, make a completely separate main.cpp file for your main function and the rest of your program. Use #include directives to include listCls.h in main.cpp, and to include all the same files in main.cpp that are included in listCls.cpp.

To create your main.cpp program, start with a copy of the *.cpp file you made as the solution to Part One and make the following changes: I will discuss what you need to do for this assignment in greater detail in class. Please be there to get the benefit of that discussion.

To compile this program, you will need to use a command such as

because your program is contained in two separate source files.

DUE DATE: