Begin this lab by defining a structure type which is capable of holding the information about a chemical element or compound. For the sake of simplicity we can call it element_t. (For element type.) This type will have a string with a length of 10 characters for the element or compound's chemical symbol (i.e. Na for Sodium), an integer for the atomic number, and a double for the atomic weight. You will define this type above the main.

Now in the main declare three variables of your new type. Have the program fill two variables by asking the user for the information:

Enter the Chemical Symbol : Na
Enter the atomic number: 11
Enter the atomic weight: 22.9897

Then output your two elements so they look something like this.

Sym: Na
No. 11
Wt. 22.9897

After you have written and tested this little main add to it a function which takes as parameters two element_t variables and which returns the sum of those two. The value returned will also be of type element_t. Remember that you can assign the return value of the function to your third element_t variable in main. The function will have a local variable of element_t type, which you will "construct" in the function by adding the various components of the two elements you have received. (Note you can use strcat, if you #include < string.h > at the top, to put the names of the elements together.)This local variable will then be returned to the main - just the like the functions we learned about early in the semester.

So the user interaction might look like:

Enter first element:
Enter the Chemical Symbol : Na
Enter the atomic number: 11
Enter the atomic weight: 22.9897
Enter second element:
Enter the Chemical Symbol : Cl
Enter the atomic number: 17
Enter the atomic weight: 35.453
The resulting compound is :
Sym: NaCl
No. 28
Wt. 58.4427
(*User input is shown in bold.)

Once you have this working create a sample run that shows two runs of your program, the first for Sodium Chloride as shown above, and the second for Cadmium Telluride (CdTe).

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.