Chemical formulae of hydrocarbon


Discussion:

We have been given a file of chemical formulae, specifically hydrocarbons. Hydrocarbons consist of only hydrogen and carbon atoms. Each line of the file contains the name of the chemical followed by its molecular formula which will be in the form:

C#H#

where # is the number of carbon (C) and hydrogen (H) atoms.

(No name in the file contains blanks.)
Because hydrocarbons with the same molecular formula can appear in many structural forms and each of the forms has a different name, the same molecular formula might appear more than once in the file with different names. (e.g.: Butane and 2-methylpropane both have the molecular formula C4H10.)

Our goal is to keep one entry for each unique molecular formula along with all the names for that formula and then display all these entries inn order by ascending number of carbon atoms. (We can do this without actually sorting the items by making multiple passes over the vector, first printing all forumlas with one carbon, then all with two carbons, etc.)

Each molecular formula will be kept in a struct with three fields:

• the name(s) for formula

• the number of carbon atoms

• the number of hydrogen atoms

We will be storing all these structs in a vector.

Solution Preview :

Prepared by a verified Expert
Chemistry: Chemical formulae of hydrocarbon
Reference No:- TGS01936173

Now Priced at $25 (50% Discount)

Recommended (91%)

Rated (4.3/5)