#include #include //for the iomanipulator setw ("set width") #include #include //for class string using namespace std; //Sort the states into alphabetical order. //Commenting the 2021 median household income for each state. //https://en.wikipedia.org/wiki/List_of_U.S._states_and_territories_by_income 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 for (int i {n - 1}; i > 0; --i) { for (int j {0}; j < i; ++j) { //a[j] should be less than or equal to a[j+1]. //If a[j] and a[j+1] are in the wrong order, if (a[j] > a[j + 1]) { //Swap the values of a[j] and a[j+1]. string temp {a[j]}; a[j] = a[j + 1]; a[j + 1] = temp; } } //At this point, the value in a[i] is in the correct place. } for (int i {0}; i < n; ++i) { cout << setw(2) << i+1 << " " << a[i] << "\n"; } return EXIT_SUCCESS; }