Name: ________________________________

Honor Code Acknowledgment: _____________________________


CPS 6, Summer 1999                 Random Quiz 6

Due: Thursday, June 10, 1999                 6 points


Problem 1: Mysterious Vector (2 pts)

Consider the function Mystery shown below.

int Mystery(const Vector <string> & names, int size)
// precondition: the vector "names" contains "size" names, size>0 
// postcondition: ?
{
    int k;
    int j = 0;
    string name = names[0];
    for (k=1; k < size; k++)
    {
      if (names[k] < name)
      {
         name = names[k];
         j = k;
      }
    }
    return j;
}

What is an appropriate postcondition for the function Mystery?






Problem 2: Mysterious Vector2 (2 pts)

Suppose the return value of the Mystery function in problem 1 is changed from int to string, and the return statement is replaced with the statement:

    return name;

What is an appropriate postcondition for the Mystery function with these modifications?




Problem 3: Juggle (2 pts)

Consider the function Mystery2 function shown below.

void Mystery2(Vector <string> & list, int size)
// precondition: the vector "list" contains "size" names, size>0 
// postcondition: ?
{
    int k;
    string name;
    for (k=0; k < (size/2); k++)
    {
        name = list[k];
        list[k] = list[size-1-k];
        list[size-1-k] = name;
    }
}

What is an appropriate postcondition for the function Mystery2?