Name: ________________________________

Honor Code Acknowledgment: _____________________________


CPS 6, Summer 1999                 Random Quiz 13

Due: Monday, June 28, 1999                 6 points


Consider the following code segment.

void DoStuff(Vector <string *> wp, int n )
// precondition:  ????
// postcondition: ????
{
   int k;

   for (k = n; k >= 0; k--)
   {
      cout << *wp[k] << endl;
      delete wp[k];
   }
}

int main()
{
   Vector <string *> wordp(1000);
   string s;

   cout << "Enter strings (^ D to quit)"  << endl;
   int k = 0;
   wordp[k] = new string;
   while (cin >> *wordp[k])
   {
      k++;
      wordp[k] = new string;
   }
   delete wordp[k];
   DoStuff(wordp, k-1);

   return 0;
}

Problem 1: (2 pts)

What would be good pre and post conditions for the DoStuff function?










Problem 2: (2 pts)

Given the following data, what would be the output of this program?

goose solder lightbulb carpet wookie pigeon Peppercorn phonebook




Problem 3: (2 pts)

Why is the line "delete wordp[k];" in the main function of the above program?