Homework One
Pointer Refresher
Due Jan 20

I wrote the following C++ program to read in five strings, sort them, then print them out. Then I removed several key pieces of code and marked those spots with comments starting with *****. Your job is to replace those particular comments with appropriate code.

Email your source code to acc.dannellys2@winthrop.edu by the beginning of class on Thursday January 20. The easiest way to do this is to type:
"mail dannellys2@winthrop.edu < hw01.cpp"


#include < iostream.h>
#include < string.h>
#include < stdlib.h>

// your name here
// data structures lab one
// january 13, 2004
// program that uses a procedure to sort a list of strings

/********************************************************/

void bubble_sort(list)   //***** fix decl of list *****
{
   char temp[11];  // temp string for swapping
   int  i,j;       // loop counters

   // very simple bubble sort
   for (i=0; i<5; i++)
      for (j=0; j<4; j++)
	 if (strcmp(list[j],list[j+1]) > 0)
            {
              //***** use temp to swap list[j] and list[j+1]
	    }
}

/********************************************************/

int main()
{
   char *strings[5];   // list of five strings
   int i;              // loop counter

   //***** allocate space so that each string can hold 10 chars

   // read in five words
   cout << "\nEnter five short words:\n";
   for (i=0; i<5; i++)
       cin >> strings[i];
  
   // sort the five words 
   //***** call the sort procedure with strings as a parameter

   // print the sorted list
   cout << "\n\nThe sorted strings are:\n";
   for (i=0; i<5; i++)
       cout << strings[i] << endl;
}