Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(This in C++) I need to write a program that defines 2 arrays of size 115; The first array's elements should be of thestring data

(This in C++) I need to write a program that defines 2 arrays of size 115; The first array's elements should be of the"string" data type. The second array's elements should be of the "double" data type. The program is chemistry based. Meaning that the elements of the first array are representative of the symbols on the periodic table. For example, "string" Atomic symbol["H","He",]; etc. The elements of the second array correspond to the atomic weights of the elements in the periodic table. For example, double AtomicWeight[1.008,4.002]. etc. The elements of the first array should be assigned to the elements of the second array; that is atomic symbol to atomic weight; H to 1.008 etc.

NOTE!! No need to define the arrays in their entirety, meaning only a few of the elements are need for illustrative purposes. For example; "string" Atomic symbol["H","He",];

The program should ask the user to enter a chemical compound one element at time (the choice of compound is completely arbitratry) followed by the number of times that element appears in the chemical formula, this should be done until the user enters a 0 to indicate that there are no more elemets to be entered for this particular compound. For example,for H20, the user would see a "cout" statement prompting them to "enter the first element in the compund" at that time they would enter H.Then, they would see another "cout" statement prompting them to "enter the number of times H appears in the chemical formula" at that time they would enter 2. Then, they would see another "cout" statement prompting them to "enter the second element in the compound" at that time they would enter O; followed by another "cout" statemet prompting them to" enter the number of times it appears in the chemical formula" which is 1 in this case. This should be done until the user enters a 0 to indicate that there are no more elements to be entered for the compound. While the user is entering the elements in the compound, the program should shift through the elements of the first array which would be of "string" data type to match user input with the one of the chemical symbols in that array. For example, if the user enters O or any other arbitrary element in a compound, then the program should shift through the first array which is of "string" data type until user input matches O.

Finally, the program should calculate the percent composition of a compound. The percent composition is equal to ( the mass of the first element entered multiplied by the number of times it appears in the chemical formula) Divided by (the total mass of the compound) Multiplied by 100. For example, H2O, the Atomic weight of H which would be held by the second array is equal to 1.008, the Atomic weight of O which would also be held by the second array is 16.000. So, as stated above the user would see a cout statement prompting them to enter the first element in the compound they would enter H, the number of times it appears in the formula; 2 and then O; then the number of times it appears which is 1. So the percent comp for H20 is 1.008 multiplied by 2 divided by the total mass of the compound which is 1.008 +1.008+16.000 = 18.016. (the total mass of a compound is the sum of the atomic weights of the elements).

Keep in mind that the elements of the 2 arrays should be assigned to one another, so that when the user enters an element in the compound it corresponds to one of the chem symbols in the first array which would in turn correspond to it matching atomic weight.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Databases With PostgreSQL From Novice To Professional

Authors: Richard Stones, Neil Matthew

2nd Edition

1590594789, 978-1590594780

More Books

Students also viewed these Databases questions

Question

What is the missing amount in this physical flow of units

Answered: 1 week ago

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago