#include #include //for the function exit and the macro EXIT_FAILURE #include "element.h" using namespace std; //Definitions for static data members: const string element::name[] { "", //dummy, so that Hydrogen will have subscript 1 "Hydrogen", // 1 "Helium", // 2 "Lithium", // 3 "Beryllium", // 4 "Boron", // 5 "Carbon", // 6 "Nitrogen", // 7 "Oxygen", // 8 "Flourine", // 9 "Neon", // 10 "Sodium", // 11 "Magnesium", // 12 "Aluminum", // 13 "Silicon", // 14 "Phosphorus",// 15 "Sulfur", // 16 "Chlorine", // 17 "Argon", // 18 "Potassium", // 19 "Calcium" // 20 }; const size_t element::n {size(element::name) - 1}; const int element::biggestInEachPeriod[] { 0, //dummy, so thet first period will have subscript 1 2, //Period 1 10, //Period 2 18, //Period 3 36, //Period 4 54, //Period 5 86, //Period 6 118 //Period 7 }; element::element(int z) : atomicNumber {z} { if (z < 1 || z > n) { cerr << "Bad atomic number " << z << ".\n"; exit(EXIT_FAILURE); } } int element::period() const //element's row in periodic table { for (int p {1}; p < size(biggestInEachPeriod); ++p) { if (biggestInEachPeriod[p] >= atomicNumber) { return p; } } return 0; //not found } void element::print() const { cout << name[atomicNumber]; }