#include #include //for the iomanipulators setw and setprecision #include #include //for class string using namespace std; //Sort the array in order of increasing inches. //Data retrieved from https://worldpopulationreview.com/state-rankings/snowiest-state int main() { struct snowfall { //Top 10 Snowiest States string name; //name of state double inches; //snowfall in inches int station; //National Centers for Environmental Information //(NCEI compiling station to compute snowfall total }; snowfall a[] { {"Alaska", 72.8, 28}, {"New Hampshire", 59.9, 11}, {"Vermont", 58.4, 10}, {"Maine", 57.6, 15}, {"New York", 51.3, 22}, {"Massachusetts", 44.3, 11}, {"Michigan", 43.5, 26}, {"Connecticut", 38.7, 8}, {"Minnesota", 37.8, 32}, {"Colorado", 36.9, 33} }; const size_t n {size(a)}; //the number of elements in the array //Start with pointing to the last element for (snowfall *p {a+n-1}; p > a; --p) { for (snowfall *q {a}; q < p; ++q) { if (q[0].inches > q[1].inches) { //q[0].inches should be <= q[1].inches. //if q[0] and q[1] are in the wrong order, //swap the values of q[0] and q[1]. const snowfall temp {q[0]}; q[0] = q[1]; q[1] = temp; } } } for (const snowfall *p {a}; p < a+n; ++p) { cout << setw(2) << p-a+1 << " " << fixed << setprecision(1) << p->inches << " " << p->name << "\n"; } return EXIT_SUCCESS; }