#include #include #include #include using namespace std; int main() { struct element { string symbol; string name; int number; }; const int periods {7}; const int groups {18}; element table[periods][groups] = {}; table[0][0] = {"H", "Hydrogen", 1}; table[0][17] = {"He", "Helium", 2}; table[1][0] = {"Li", "Lithium", 3}; table[1][1] = {"Be", "Beryllium", 4}; table[1][12] = {"B", "Boron", 5}; table[1][13] = {"C", "Carbon", 6}; table[1][14] = {"N", "Nitrogen", 7}; table[1][15] = {"O", "Oxygen", 8}; table[1][16] = {"F", "Fluorine", 9}; table[1][17] = {"Ne", "Neon", 10}; table[2][0] = {"Na", "Sodium", 11}; table[2][1] = {"Mg", "Magnesium", 12}; table[2][12] = {"Al", "Aluminum", 13}; table[2][13] = {"Si", "Silicon", 14}; table[2][14] = {"P", "Phosphorus", 15}; table[2][15] = {"S", "Sulfur", 16}; table[2][16] = {"Cl", "Chlorine", 17}; table[2][17] = {"Ar", "Argon", 18}; table[3][0] = {"K", "Potassium", 19}; table[3][1] = {"Ca", "Calcium", 20}; table[3][2] = {"Sc", "Scandium", 21}; table[3][3] = {"Ti", "Titanium", 22}; table[3][4] = {"V", "Vanadium", 23}; table[3][5] = {"Cr", "Chromium", 24}; table[3][6] = {"Mn", "Manganese", 25}; table[3][7] = {"Fe", "Iron", 26}; table[3][8] = {"Co", "Cobalt", 27}; table[3][9] = {"Ni", "Nickel", 28}; table[3][10] = {"Cu", "Copper", 29}; table[3][11] = {"Zn", "Zinc", 30}; table[3][12] = {"Ga", "Gallium", 31}; table[3][13] = {"Ge", "Germanium", 32}; table[3][14] = {"As", "Arsenic", 33}; table[3][15] = {"Se", "Selenium", 34}; table[3][16] = {"Br", "Bromine", 35}; table[3][17] = {"Kr", "Krypton", 36}; cout << "Periodic Table of Elements\n\n"; for (int i {0}; i < periods; ++i) { for (int j{0}; j < groups; ++j) { if (table[i][j].symbol != "") { cout << setw(3) << table[i][j].symbol << " "; } else{ cout << setw(3) << " . "; } if (j % 17 == 0 && j > 1) { cout << "\n"; } } } cout << "Input the symbol of an element for more information, or Q to exit.\n"; string lookup {}; cin >> lookup; if (!cin) { cerr << "Sorry, that is not a valid symbol.\n"; return EXIT_FAILURE; } for (int i {0}; i < periods; ++i) { for (int j{0}; j < groups; ++j) { if (table[i][j].symbol == lookup) { cout << table[i][j].symbol << " " << table[i][j].name << " " << table[i][j].number; cout << "\nThank you! Try again soon to see more information!\n\n"; } else if ( "Q" == lookup) { cout << "Thank you, try again soon for more information!\n\n"; return EXIT_SUCCESS; } } } return EXIT_SUCCESS; }