Question: Write in C++ Please Write a program to balance chemical equations. An equation is comprised of a list of compounds and elements, separated by plus-signs,

Write in C++ Please Write a program to balance chemical equations. An equation is comprised of a list of compounds and elements, separated by plus-signs, on both sides of an equal sign. An element will be represented by either one or two letters; the first is always capitalized, and if the element has a second character, it will be lowercase. Compounds are composed of several elements added together that may have parenthesis around them and with a number following each element. This number represents the number of atoms of the element in front of the number in the compound. If there is only one atom of an element in the compound, no number will appear after the element. The result is the lowest number of integer coefficients for each compound needed so the equation is balanced. An equation is balanced when the number of atoms of each element on the left side is equal to that of the right side. Coefficients are applied to the complete compound; so, a coefficient of two for FeCl represents two atoms of Fe and two atoms of Cl. Input is from a text file, where the first line contains an integer N between [1,30]. The following N lines define equations according to the rules described above. For each labeled equation, output to the screen the balanced equation with the lowest integer number coefficients. If an equation cannot be balanced correctly or uniquely, output the words "Cannot Balance". Let the user enter the file name from the keyboard. Refer to the sample output below. Sample File: 5 Fe + Cl2 = FeCl3 KMnO4 + HCl = KCl + MnCl2 + H2O + Cl2 C8H18 + O2 = CO2 + H2O Fe2(SO4)3 KSCN = K3Fe(SCN)6 K2SO4 CO2 = CO Sample Run: Enter the file name: balequation.txt E1: 2Fe + 3Cl2 = 2FeCl3 E2: 2KMnO4 + 16HCl = 2KCl + 2MnCl2 + 8H2O + 5Cl2 E3: 2C8H18 + 25O2 = 16CO2 + 18H2O E4: Fe2(SO4)3 + 12KSCN = 2K3Fe(SCN)6 + 3K2SO4 E5: Cannot Balance

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!