#include #include //for the i/o manipulator setw #include #include //for class string #include //for class vector using namespace std; int main() { struct state { int year; //of admissio to he United States string name; }; const state a[] { {1787, "Delaware"}, //the Thirteen Colonies {1787, "Pennsylvania"}, {1787, "New Jersey"}, {1788, "Georgia"}, {1788, "Connecticut"}, {1788, "Massachusetts"}, {1788, "Maryland"}, {1788, "South Carolina"}, {1788, "New Hampshire"}, {1788, "Virginia"}, {1788, "New York"}, {1789, "North Carolina"}, {1790, "Rhode Island"}, {1791, "Vermont"}, {1792, "Kentucky"}, {1796, "Tennessee"}, {1803, "Ohio"}, {1812, "Louisiana"}, {1816, "Indiana"}, {1817, "Mississippi"}, {1818, "Illinois"}, {1819, "Alabama"}, {1820, "Maine"}, {1821, "Missouri"}, {1836, "Arkansaw"}, {1837, "Michigan"}, {1845, "Florida"}, {1845, "Texas"}, {1846, "Iowa"}, {1848, "Wisconsin"}, {1850, "California"}, {1858, "Minnesota"}, {1859, "Oregon"}, {1861, "Kansas"}, {1863, "West Virginia"}, {1864, "Nevada"}, {1867, "Nebraska"}, {1876, "Colorado"}, {1889, "North Dakota"}, {1889, "South Dakota"}, {1889, "Montana"}, {1889, "Washinton"}, {1890, "Idaho"}, {1890, "Wyoming"}, {1896, "Utah"}, {1907, "Oklahoma"}, {1912, "New Mexico"}, {1912, "Arizona"}, {1959, "Alaska"}, {1959, "Hawaii"} }; const size_t n {size(a)}; //the number of states in the United States cout << "Please input a year: "; int year {0}; cin >> year; if (!cin) { cerr << "Sorry, couldn't read that.\n"; return EXIT_FAILURE; } vector v; //born empty, but capable of holding strings for (int i {0}; i < n; ++i) { if (a[i].year <= year) { //If this state existed then, v.push_back(a[i].name); //add the state to the vector. } } const vector::size_type m {v.size()}; //number of states in the specified year cout << "Here are the " << m << " states that existed in the year " << year << ":\n\n"; for (vector::size_type i {0}; i < m; ++i) { cout << setw(2) << i+1 << " " << v[i] << "\n"; } return EXIT_SUCCESS; }