Fall 2004

Clay Shields


front | classes | research | personal | contact

Project 5 - Guide Dog Kennel Tracking

Program Source code due: December 8, 2004

Guide Dog Kennel Tracking
The Guide Dog Organization (GDO) has been using your litter program to track information about individual litters of puppies. While this has proven useful, they want to be able to track all their litters at once.

GDO has five different internal divisions. The first is the Breeding Center, where they breed puppies to be guides. The second is Raiser Outreach, where they find puppy raisers to keep the puppies until they are old enough to be trained. At that point, puppies move to the Training Center, where they are trained to be guides. After that they are placed with blind people by the Placement Center. Finally, if any puppies do not make it through, the Release program places them with law enforcement agencies or with families to be pets.

They way they keep track of the litters reflects this. Litters are the responsibility of the Breeding Center until all puppies are whelped and placed with raisers or released. At that point, the litter falls under Raiser Outreach until they are all in for training(except for those released). When all puppies are in training (except for those released) they fall under the Training Center. Finally, once all puppies in a litter are done with training (except for the ones in the litter who are released), they fall under the Placement Center as working dogs. At any time, if all puppies in a litter are all released, the whole litter falls under the Release program. Here is a gratuitous picture of some dogs who are in for training.

puppies

The program you will write will extend your puppy and litter classes to allow tracking of litters by the litter status. We will keep track of all the litters by using linked lists, one for each operational division.

Plan of work:

In order to complete this assignment, you will have to take several steps. I HIGHLY recommend that you take each step one at a time and test the code you write at each step before moving on to the next step. I will give suggestions on how to do this. It becomes very hard to debug your program if you try to do it all at once. We like things easy, and I have tried to make it as simple as possible while letting you learn about linked lists.

We will be modifying and using the puppy and litter classes we wrote for Project 4. You may use your own code, or, if you prefer, you may start working from the solution code I posted for that project. I recommend you use my code because I have already overloaded the input and output operators for the litter class. Since it was not required, you may not have done that. You can copy my code to your account on gusun by typing:

cp ~clay/litters.cc ~/

Step 1: Modify your puppy class to include two new status classes: O, which means "out at raiser"; and T which means "puppy in guide training". Make sure that your modifications work by writing a small main that creates a puppy object, sets it to each new code and then prints it out.

Step 2: Modify your litter class to include two new methods.

The first will be called getLitterStatus, and will return a single character that indicates which GDO internal division would be responsible for the litter.
char litter::getLitterStatus()
A litter that has no puppy with a W, O, T, G, or B code would be released. A litter with at least one W code would belong to the breeding center. A litter with no W and at least O would belong to Raiser Outreach. A litter with no W, no O, and at least one T would belong to the Training Center. A litter with no W, no O, and no T, but at least one G or B would belong to the Placement Center. Test this method by writing a small main that allows you to enter a litter and then outputs the code that shows where it belongs. Verify this by hand.

The second method, called changePupStatus, will allow you to change the status code of a puppy by specifying the puppy ID and the new status.
int litter::changePupStatus(string pup_id, char newstatus)
The method will return an int that tells if the call worked or not. If the status code provided is not valid, then it should return a -1. If the puppy is not in the litter, the method should return a 0. If the puppy is found and the status changed, it should return a 1. Write a small main that will allow you to enter a litter, print the litter, then change the codes of some puppies and reprint the litter.

Step 3: Add a new private data member to the litter class. This should be a pointer to another litter, so we can store litters on a linked list. Also add an accessor and observer method that allow you to set and return the next litter on the list.

Step 4: Now we are going to write a new class that will allow us to keep lists of litters, one for each internal division of GDO. We can call this the kennel class. Here is the class definition:

class kennel{

 public:

  kennel();
  ~kennel();
  void newLitter();
  int changePupStatus(string,char);
  void print();
  void showBreeding();
  void showRaising();
  void showTraining();
  void showWorking();
  void showReleased();
  void test();

 private:

  void deleteList(litter * &);
  void printList(litter *);
  void sortLitter(litter *);
  int changePupOnList(string,char, litter *);
  void updateReleasedList();
  void updateBreedingList();
  void updateRaisingList();
  void updateTrainingList();
  void updateWorkingList();

  // new litters start out in the breeding center
  litter * breeding;
  // after all are whelped, they move to the raisers
  litter * raising;
  // after all puppies are raised, they go into training
  litter * training;
  // after puppies are trained, they go into work
  litter * working;
  // sometimes, a whole litter washes out
  litter * released;

};

We are going to implement each of these methods in order, and test each as we go along.

Step 5: After writing the class definition, first create the constructor. All it needs to do is set all the litter pointers in the private section to NULL.

Step 6: Now write a private method called printList that will print each litter on a list, given a pointer to the head of the list.

Step 7: Test the print list method by writing a main that calls the public test method. In the test method, dynamically create a few litter objects and link them together. Then try printing the list to make sure that it all worked correctly. Once that is done, create methods that will show each of the lists in the private section individually (these are the public methods called "showWhatever"), and then all together (the print method).

Step 8: Create a private deleteList method which, given a pointer to the head of a list, will delete all the elements on a list. Test it by adding the call to the public test method to make sure you can delete the list you created by hand. Make sure you set the pointer passed as a parameter to NULL when you are done deleting the list! You can use reference paramters for ths. Try printing the list after deleting it to make sure your method worked. Now create a destructor that will delete all the lists in the private section by calling the delete list method on each of them.

Step 9: Now create a method called sortLitter. This method will take a pointer to a single litter, figure out which list it belongs on by calling the litter::getLitterStatus method, then add the litter to the appropriate list. Test it by dynamically creating some litter objects, entering the puppy info, and then calling sortLitter with each litter. Print all lists in between to make sure that the litters are being sorted onto the proper lists.

Step 10: Create a method called ChangePupOnList that will go over each litter on a list and try to update the status of a particular puppy as specified by a puppy ID. Return -1 if the status code was bad, 0 if the puppy was not found, and 1 if the puppy was successfully updated. Test that it works by creating a dynamic list of some litters, printing it, then changing a puppy status and printing the list again.

Step 11: Now create a public method called changePupStatus that will search each lists in the private section until it finds the puppy to change the status of. It should return the same values as the method in step 10. Test this by using your public test method to create some litter objects on different lists in the private section, then print them. Next try and change a puppy code and verify that it was changed by printing all lists again.

Step 12: Since we have updated puppy codes in a litter on a particular list, we need to see if that causes that litter to change status. First, write a method called updateReleasedList that traverses the released list and checks to see that each litter has a "released" status code. If a litter does not have that code, remove it from the list (being careful to maintain the list integrity) and then passed the removed litter into sortLitter so that it will be moved to the correct list. Test this by using your test method to create a list of litters on the failed list, then print it. Now make calls that change the status of one of the puppies so that the litter is no longer failed. Finally, call the updateReleasedList, then print all lists to verify that the litter was moved where it was supposed to go.

Step 13: Once that is working, write similar methods for each of the other lists so that they can all be updated and litters which do not belong in the list are moved.

Step 14: Now add a call to changePupStatus so that each time a pup status is successfully changed, the list is updated to check if the litter the pup is in changed status.

Step 15: Now write a main function that creates a litter object and follows the menu options shown in the example. Test it to make sure everything is working. Be sure to try your program with many litters, so that you know your code works with long lists.

Step 16: Submit your program!

Some additional hints about using pointers


While I didn't cover how to do everything you have to do with pointers in the class, the book has a many examples of how to use pointers that relate directly to the project. Allow me to provide you with some examples.

In Step 6, you have to write a method to print a linked list. You will find some of what you need in Chapter 17, page 1017. You do need to modify the code to accept a pointer as a parameter, and to print using the right method, but it is very similar.

In Step 8, you need to write a method that will delete a list. On page 1028 you will find code that does something similar. Again, you need to modify this code so that it takes a pointer as a reference parameter, destroys the list, then sets the pointer passed as the parameter to null.

In Step 9 you have to write a method that will add a single node to a list. Of course, you have to figure out what list to add it to, but you already wrote a litter method called getLitterStatus to do that earlier. Once you figure out the status, you add it to the appropriate list. Code that shows you how to do this is on page 1017. I will tell you that there is also an easier way to do it; the example code adds the new node to the end of the list. In our project, we don't care about where the litter is on the list, and it is easier to add it to the head of the list, though I don't see an example of that in the test.

In Step 10, you need to write a method that will traverse a single list of litters, calling the changePupStatus method on each one until you run out of litters to try or find the puppy. This is as simple as traversing the list and printing it like you did in step 6. You just need to make it stop if you find what you are looking for early.

In Step 11, you need to search all the different lists we have to see if you can find a particular puppy to change the status on. What you wrote in step 10 will be really helpful here.

In Step 12, you have to write a method that can check the Released list to see if all litters on it were really supposed to have been released. This just requires traversing the list and checking the status of each litter. What is slightly harder is what you need to do if you find a litter that should be on another this. The first thing you need to do is remove that litter from the list while making sure not to lose anything on the rest of the list. Then you need to add the litter you found to the right list. Fortunately, you wrote a method in Step 9 that you can use to place the litter correctly one you get it off the list. To help you with this method, you can look at the code on how to delete a node from a list on page 1024. Just make sure to call sortLitter instead of delete on the litter you take off the list!

In the rest of the steps, you need to write other methods that do the same for the other lists. They are all almost exactly the same as the one you wrote above.

What to submit


Include the following header in your source code.

//
// Project 5
// Name: <your name>
// E-mail: <your e-mail address>
// COSC 071
//
// In accordance with the class policies and
// Georgetown's Honor Code, I certify
// that I have neither given nor received
// any assistance on this project with the
// exceptions of the lecture notes and those
// items noted below.
//
// Description: <Describe your program>
//

You will submit your source code using the submit program. Do not submit the compiled version! I don't speak binary very well.

To submit your program, make sure there is a copy of the source code on your account on gusun. You may name your program what you like - let's assume that it is called kennel.cc. To submit your program electronically, use the submit program like we did in Homework 2 and project 1, 2, and 3 but with the command:

submit -a p5 -f kennel.cc