Write a C++ program to predict the molecular geometry of molecules based on form
ID: 3798877 • Letter: W
Question
Write a C++ program to predict the molecular geometry of molecules based on formulas like AB_b,
where the approximate shape is one A atom in the centre surrounded by b B atoms.
The Valence-Shell Electron-Pair Repulsion Model (VSEPR model) is commonly used for this task and consists of these four steps:
1. set v for the centre atom A using a nested-if and the information in Table 1
2. e = v - b
3. n = e / 2
4. use b and n in a nested-if to determine the shape based on Table 2.
Note that Step 1 determines the (simplified) number of valence electrons v for the central atom A.
Step 2 subtracts the number of bonding domains (b) from v to determine the number of nonbonding electrons (e).
Then, by dividing e by 2, Step 3 determines the number of bonding domains (n).
We assume that only single bonds are present. Also, Table 1 shows the element name only for your convenience;
it is not required in the C++ program.
Each line in the input file, called molecules.txt and given on UR Courses,
represents the information for one molecule and contains 3 pieces of data in the following format:
A B b
where A and B are the chemical symbols for two elements (use type string), and b is the number of B atoms (use type int).
In the output file, called geometricalshapes.txt, print the determined shape in this format:
The geometrical shape of one A atom surrounded by b B atoms is s.,
where s is the determined shape from Table 2.
Indicate s as unknown when the values of b and n do not match any case in Table 2.
For example, if the first four input lines from molecules.txt are
O F 2
S F 4
Be F 3
C P 1
then the first four output lines in geometricalshapes.txt would be
The geometrical shape of one O atom surrounded by 2 F atoms is bent.
The geometrical shape of one S atom surrounded by 4 F atoms is seesaw.
The geometrical shape of one Be atom surrounded by 3 F atoms is trigonal planar.
The geometrical shape of one C atom surrounded by 1 P atoms is unknown.
Table 1
Element Symbol v
Beryllium Be 3
Carbon C 4
Silicon Si 4
Nitrogen N 5
Phosphorus P 5
Arsenic As 5
Oxygen O 6
Sulfur S 6
Selenium Se 6
Flourine F 7
Chlorine Cl 7
Bromine Br 7
Iodine I 7
Xenon Xe 8
Table 2
b n s (Molecular Geometry)
2 0 linear
2 1 bent
2 2 bent
2 3 linear
3 0 trigonal planar
3 1 trigonal pyramidal
3 2 T-shaped
4 0 tetrahedral
4 1 seesaw
4 2 square planar
5 0 trigonal bipyramidal
5 1 square pyramidal
6 0 octahedral
Use meaningful variable names, proper indentation, and appropriate comments.
Explanation / Answer
#include<iostream>
#include<fstream>
using namespace std;
//Structure to hold the possible combinations leading to different shapes of molecules
struct moleculeGeo
{
int b_surroundingAtom;
int n_middleAtom;
char s_shape[30];
};
moleculeGeo geometry[13] = {
{2,0,"linear"},
{2,1,"bent"},
{2,2,"bent"},
{2,3,"linear"},
{3,0,"trigonal planar"},
{3,1,"trigonal pyramidal"},
{3,2,"T-shaped"},
{4,0,"tetrahedral"},
{4,1,"seesaw"},
{4,2,"square planar"},
{5,0,"trigonal bipyramidal"},
{5,1,"square pyramidal"},
{6,0,"octahedral"}
};
int main()
{
char outerAtom[5] = {''}, middleAtom[5] = {''};
int count = 0,i=0;
ifstream input("molecules.txt");
ofstream output("geometricalshapes.txt");
while(input >> middleAtom){
input >> outerAtom >> count ;
//Loop over the geometry structure variable to check for the combination
while(i< 13){
if((geometry[i].b_surroundingAtom == count) && (geometry[i].n_middleAtom == 1)){
break;
}
i++;
}
if(i<13)
output << "The geometrical shape of one " << middleAtom << " atom surrounded by " << count << " " << outerAtom << " atoms is " << geometry[i].s_shape << endl;
else
output << "The geometrical shape of one " << middleAtom << " atom surrounded by " << count << " " << outerAtom << " atoms is " << "Unknown" << endl;
i=0;
}
input.close();
output.close();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.