Using C++
Complete the class below that stores information about chemical elements. Your class should implement 5 functions:
Output example: (No space between each line)
Name: Oxygen
Symbol: O
Atomic weight: 15.999
# valence electrons: 6
Hello, here is the completed code you wanted. Every important statement is explained using comments. Please check and let me know if you have any doubts. Thanks.
Class name is not specified in the question. I have given it as "Element". If student want to change it please specify it in the comment.
CODE
#include<iostream>
using namespace std;
//class Element
//name for class is not specified in the question
//if student want to change the name please comment
class Element
{
//private section
private:
//variable to store name of
element
string name;
//variable to store atomic
weight
double atomicWeight;
//variable to store valence
electrons
int valenceElectrons;
//variable to store symbol
string symbol;
//public section
public:
//setter for set name data
member
void SetName(string n)
{
//sets it equal
to n
name = n;
}
//setter for set atomicWeight data
member
void SetAtomicWeight(double
z)
{
//sets it equal
to z
atomicWeight =
z;
}
//setter for set valenceElectrons
data member
void SetValenceElectrons(int
e)
{
//sets it equal
to e
valenceElectrons
= e;
}
//setter for set symbol data
member
void SetSymbol(string s)
{
//sets it equal
to s
symbol =
s;
}
//prints out the data stored in the
object
void PrintElement()
{
//printing
information about chemical element
cout <<
"Name: " << name << "\n";
cout <<
"Symbol: " << symbol << "\n";
cout <<
"Atomic weight: " << atomicWeight << "\n";
cout << "#
valence electrons: : " << valenceElectrons;
}
};
//main function
int main()
{
//creating object for class Element
Element obj;
//calling SetName
obj.SetName("Oxygen");
//calling SetSymbol
obj.SetSymbol("O");
//calling SetAtomicWeight
obj.SetAtomicWeight(15.999);
//calling SetValenceElectrons
obj.SetValenceElectrons(6);
//calling PrintElement
obj.PrintElement();
}
OUTPUT

CODE SCREEN SHOT



Using C++ Complete the class below that stores information about chemical elements. Your class should implement...