The plan is to make a little interactive word sorter that would work just like this: $ a.out > enter 10 qat what eat rat that yacht unhat irate oat pat > list 10 words: qat what eat rat that yacht unhat irate oat pat > sort > list 10 words: eat irate oat pat qat rat that unhat what yacht > enter 4 cat ant dog bat > list 4 words: cat ant dog bat > sort > list 4 words: ant bat cat dog > exit because we never know in advance how many words will be entered, we can't create an array of the right size in the ordinary way. We have to use dynamic allocation (with new), and remember to plug any memory leaks. This is as close as I can remember to the program we produced in class. I have filled in the gaps and put the functions in a different order. main tells the story, so it makes sense to see it first. _______________________________________________________________________ #include #include void list(string * arr, int n); void sort(string * arr, int n); string * readwords(int n); void main() { string * AS = new string[0]; int num = 0; while (true) { cout << "> "; string command; cin >> command; if (command == "exit") break; else if (command == "list") list(AS, num); else if (command == "sort") sort(AS, num); else if (command == "enter") { cin >> num; delete[] AS; AS = readwords(num); } else cout << "don't understand " << command << "\n"; } } void list(string * arr, int n) { cout << n << " words:"; for (int i=0; i> words[i]; return words; } int where_is_the_biggest(string * arr, int begin, int end); void swap(string & a, string & b); void sort(string * arr, int size) { for (int last=size-1; last>0; last-=1) { int pos = where_is_the_biggest(arr, 0, last); swap(arr[pos], arr[last]); } } int where_is_the_biggest(string * arr, int begin, int end) { int biggest_so_far = begin; for (int i=begin+1; i<=end; i+=1) if (arr[i] > arr[biggest_so_far]) biggest_so_far = i; return biggest_so_far; } void swap(string & a, string & b) { string temp = a; a = b; b = temp; } __________________________________________________________________