Just a quick question

Nov 20, 2015 at 5:26pm
I created this code according to what the question asked me to do. But I am confused on the last part of the question. Problem: Modify the selection function presented in this chapter into an array of strings instead of an array of ints. Test the function with a driver program. The last part is where im lost. What is a driver program?

Nov 20, 2015 at 5:40pm
A "driver" program is simply a test program that calls your function with one or more test cases to exercise your function. A driver program will typically check the result returned by your function for each test case to check that the result is correct.

Nov 21, 2015 at 12:41am
so do you think this code will be fine then??

#include <iostream>
#include <string>
using namespace std;
void selectionSort(string *array, int length);

int main() {
const int NUM_NAMES = 20;
string names[NUM_NAMES] = {"Collins, Bill", "Smith, Bart", "Allen, Jim",
"Griffin, Jim", "Stamey, Marty", "Rose, Geri",
"Taylor, Terri", "Johnson, Jill",
"Allison, Jeff", "Looney, Joe", "Wolfe, Bill",
"James, Jean", "Weaver, Jim", "Pore, Bob",
"Rutherford, Greg", "Javens, Renee",
"Harrison, Rose", "Setzer, Cathy",
"Pike, Gordon", "Holland, Beth" };
selectionSort(names,NUM_NAMES);
for(int i=0;i<NUM_NAMES;i++) {
cout<<names[i]<<"\n";
}
cout<<endl;
return 0;
}
void selectionSort(string *array, int length){
string temp;
int i,max;
while (length > 0)
{
max = 0;
for (i = 1; i < length; i++)
if (array[i] > array[max])
max = i;

temp = array[length-1];
array[length-1] = array[max];
array[max] = temp;
length--;
}
}
Topic archived. No new replies allowed.