#include #include #include //for class string using namespace std; int main() { string a[] { "Maryland", //$90,203 "Massachusetts", //$89,645 "New Jersey", //$89,296 "New Hampshire", //$88,465 "California", //$84,907 "Hawaii", //$84,857 "Washington", //$84,247 "Connecticut", //$83,771 "Colorado", //$82,254 "Virginia", //$80,963 "Utah", //$79,449 "Alaska", //$77,845 "Minnesota", //$77,720 "New York", //$74,314 "Rhode Island", //$74,008 "Vermont", //$72,431 "Illinois", //$72,205 "Oregon", //$71,562 "Delaware", //$71,091 "Arizona", //$69,056 "Pennsylvania", //$68,957 "Wisconsin", //$67,125 "Texas", //$66,962 "Nebraska", //$66,817 "Georgia", //$66,559 "North Dakota", //$66,519 "Idaho", //$66,474 "Nevada", //$66,274 "South Dakota", //$66,143 "Iowa", //$65,600 "Wyoming", //$65,204 "Maine", //$64,767 "Kansas", //$64,124 "Michigan", //$63,498 "Montana", //$63,249 "Florida", //$63,062 "Indiana", //$62,743 "Ohio", //$62,262 "North Carolina", //$61,972 "Missouri", //$61,847 "Tennessee", //$59,695 "South Carolina", //$59,318 "Oklahoma", //$55,826 "Kentucky", //$55,573 "New Mexico", //$53,992 "Alabama", //$53,913 "Arkansas", //$52,528 "Louisiana", //$52,087 "West Virginia", //$51,248 "Mississippi" //$48,716 }; int n {size(a)}; //the number of elements in the array if (n == 0) { cerr << "The array is empty, so it has no smallest element.\n"; return EXIT_FAILURE; } int smallest {0}; //Temporarily assume that first element is smallest. for (int i {0}; i < n; ++i) { //Let smallest be the subscript of the smallest element //currently in the array. int smallest {0}; for (int j {1}; j < n; ++j) { if (a[j] < a[smallest]) { smallest = j; } } //Output the smallest value and erase it. cout << a[smallest] << "\n"; a[smallest] = "zzzzzzzzzzzzzzzz"; //comes last in alphabet order } return EXIT_SUCCESS; }