CS 3460 - Lab (1)

The goals of this lab are to:
  1. Create a linked list to hold strings (words)
  2. Create a linked list to hold objects
  3. Learn manipulating the linked list program to di different things.

Getting Ready

Create a directory lab1 under your 3460 directory.  You will work in teams of two to complete this lab and all the activities that follow.

Activity 1: A Linked List of Strings (Due in the lab)

In class, we talked about the linked list and showed an example of a linked list that uses integers.  We want to modify our program such that it works with strings.  So I can enter several words in order and have them store in a linked list. Furthermore, I want to be able to delete a particular word or insert a word at a location using the index of the previous word.

Here is an example:
Hi My name Tom.

I have entered this as "Hi", "My", "name", and "Tom.".  But I forgot "is".  We want to be able to insert "is".  Also, we want to be able to delete something and replace it with something else.   For example, replacing My with Your. 

Here are the files we have to start with.  All these files must be saved in the directory in which you will write your programs:

The Linked List Header file: LinkedList.h
The linked List .cpp file: LinkedList.cpp
The Test Program: Test Program
The exception handling file: Exception
Note: You only need to compile the test program.

In your main program, you may make modifications such that it asks for an option to do different things.  Something like this:

...
          while(option < 6)
          {
            cout << "Choose one of the options" << endl;
            cout << "1 to insert a new element" << endl;
            cout << "2 to display the list" << endl;
            cout << "3 to delete an element" << endl;
            cout << "4 to find an element" << endl;
            cout << "5 to remove ALL elements" << endl;
            cout << "6 to exit" << endl;
            cout << "Enter an Option \n";
            cin >> option;

            switch(option)
            {
                case 1:
                  cout << "Enter an element you wish to insert \n";
                  cin >> value;
                  theList.insert( value, theItr );
                  theItr.advance( );

                break;
                case 2:
                  cout << "Your current list is: \n";
                  printList( theList );
                  cout << "\n\n";
                break;
                case 3:
                  cout << "Enter the element you wish to remove \n";
                  cin >> value;
                  theList.remove( value );
                  cout << endl;
                break;
                // .....
                case 5:
                  cout << "Enter the element you wish to find \n";
                  theList.makeEmpty( );
                break;
                default:
                 return 0;
            }
          }

Activity 2: A Linked List of Objects 

(Due by Tuesday Feb. 15 9:59 pm)

The next thing we want to do is to further modify the program you have written above to do similar things for objects.  We can use the image object.  Below are two files for the image.h and image.cpp that you need to copy in your directory.  I will give you a test program to that you can test the image.cpp and image.h with it. The TestImage.cpp is only to make sure the image.h and image.cpp are working correctly.

To compile: use g++ -Wall TestImage.cpp image.cpp
To run use:  a.out  inputimage  outputfile.

Here are two sample images to start with. I can provide you more if you need: test.pgm and test2.pgm
Here is the interface I get from my program:


Choose on of the options
1 to insert a new image
2 to display the list
3 to delete an image
4 to find an element
5 to remove ALL elements
6 to exit
Enter an Option
1
Enter the name of the file for the image you wish to insert
test.pgm

Choose on of the options
1 to insert a new image
2 to display the list
3 to delete an image
4 to find an element
5 to remove ALL elements
6 to exit
Enter an Option
2
Your current mage is:
P2
# Test
4 4
15
120 30 140 50
90 180 70 60
110 20 130 40
150 80 160 170
When you have more than one image it displays them one after another as they appear in the list.
When you look for an image (try the find option), then you ask for the file that contains the image, read the file, create an Image object for it, then search for it.