//*************************************** //sort3StringClass.cpp //R. A. Hillyard // // Program to sort 3 String Objects // Shows use of cstring functions // included in the cstring and cstdlib library //*************************************** #include<iostream> #include<string> using namespace std; void sort3(string& a, string& b, string& c); void swap(string& a, string& b); int main() { string str1, str2, str3; cout << "Enter three strings (on the same line)\n> "; cin >> str1 >> str2 >> str3; sort3(str1,str2,str3); cout << "\nsorted: " << str1 << " " << str2 << " " << str3 << endl; return 0; }//end main /*************************************************************/ void sort3(string& a, string& b, string& c) { if(a > b) { swap(a,b); } if(a > c) { swap(a,c); } if(b > c) { swap(b,c); } }//end sort3 /*************************************************************/ void swap(string& a, string& b) { string temp; temp = a; a = b; b = temp; }//end swap /*************************************************************/ /*****************Program output***************************** Enter three strings (on the same line) > last middle first sorted: first last middle Enter three strings (on the same line) > why only 3 sorted: 3 only why Enter three strings (on the same line) > have a cow sorted: a cow have */