Description
The purpose of this challenge is to define basic classes with constructors, setters and getters.
Requirements
- Define a class called Element as below
class Element { private: string symbol, name; int number; double atomic_mass; public: }; - Write an overloaded constructor for the Element class to set the values for the symbol, name, number and atomic_mass data members.
- Write setters and getters for each of the private data members
- Use the main() provided below. If you follow the instructions above exactly, you will get an error when you try to compile it as is – identify and fix the error.
- Ask the user to provide the values for a new element, e3
- See the sample interaction to get an idea of what the user is providing as input.
- The e3 element will be compared to both e1 and e2. See the sample interaction to see what the output contains and how it is displayed.
- Make sure your Element class does not contain any cout or cin.
Sample main()
// class definitions here
int main()
{
Element e1("S", "Sulfur", 16, 32.066);
Element e2("Md", "Mendelevium", 101, 258.1);
Element e3;
// Ask the user to provide values for a new element
// that you will store in e3
// Write the code that compares e3 to e1 and e2
// describing appropriately which is heavier
// See sample interaction for details and formatting
return 0;
}
Sample Interaction 1
Enter element name: Zirconium Enter symbol: Zr Enter number: 40 Enter atomic mass: 91.224 Zirconium (Zr) is heavier than Sulfur (S) and appears after it Zirconium (Zr) is lighter than Mendelevium (Md) and appears before it
Sample Interaction 2
Enter element name: Helium Enter symbol: He Enter number: 2 Enter atomic mass: 4.003 Helium (He) is lighter than Sulfur (S) and appears before it Helium (He) is lighter than Mendelevium (Md) and appears before it
LEGEND
PROGRAM OUTPUT
USER INPUT
FROM INPUT
CATALOG ID: CPP-CHAL0082
Print Requirements
