Honor Code Acknowledgment: _____________________________
Due: Thursday, June 10, 1999 6 points
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?
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?
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?