Site hosted by Angelfire.com: Build your free website today!

C++ BONUS # 4C++ Programming

Dzwonkiewicz

 

 

 

Computing the number of molecules in a hydrocarbon

 

A trivial problem in elementary school chemistry is to compute the number of atoms or molecules contained in a particular amount of substance. The substance that we all are interested in is of course hydrocarbon. These are substances that contain only two elements: carbon and hydrogen. (EX: the fuels methane, propane and butane)

 

The computation of the number of molecules in a hydrocarbon is best illustrated with an example. Recall that a mole of any substance contains 6.02 x 10^23 molecules. This number is called Avogadro’s constant. It is the case that one mole of a substance is always equal to the formula weight in grams. The formula weight is the sum of the atomic weights of the consuituent elements. The computation of formula weight of methanc, CH4, is

 

1 carbon atom              =          1 x 12.0 amu = 12.0

4 hydrogen atoms         =          4 x  1.0 amu = 4.0

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1 mole of CH4                                                       = 16.0 g

 

Therefore 16 grams of methane contain 6.02 x 10^23 molecules. The following equation expresses the relationship between the mass of a substance and the number of molecules.

 

Molecules = Mass x (1 mole)/(Formula weight) x (6.02 x 10^23 molecules) / (1mole)

 

 

Write a program to compute the number of molecules in an amount of hydrocarbon. The amount of hydrocarbon will be given in grams. Carbon’s atomic weight is 12 amu and hydrogen’s is 1 amu.

 

Sample run…

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Enter mass of hydrocarbon (in grams) followed by the number of carbon atoms followed by the number of hydrogen atoms. (Ex. 10.5  2  6)

 

16  1  4 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

16.4 grams of hydrocarbon with 1 carbon of atom(s) and 4 hydrogen atom(s) contains 6.02 e+23 molecules

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

*Ask for mass of hydro., # of atoms of C and # of atoms of H

*Compute formula weight of one mole (# C atoms x12 + # H atoms x 1)

*Compute number of molecules

*Put Avogadro’s constant in a const… const double avogadro = 6.02e23