this is what i have so far
Code:
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
#include <cmath>
#include <cctype>
using namespace std;
const int SIZE = 25;
class CElement
{
public:
string atomicSymbol;
int atomicNumber;
float atomicMass;
};
void readPeriodicTable(CElement [], int &);
void bubbleSort(CElement [], int );
void printTable(CElement [], int &);
void promptUser();
float numberOfGramrsPerMole(CElement [], string);
int findMassNumber(string);
double calculateNumberOfParticles(float, float);
int main()
{
int num;
float weight;
string molecularFormula;
CElement chemicalelement[SIZE];
readPeriodicTable(chemicalelement, num);
bubbleSort(chemicalelement, num);
printTable(chemicalelement, num);
promptUser();
cin >> molecularFormula >> weight;
return 0;
}// end main
/* Function readPeriodicTable: reads in the data from a file and puts it into an
* array chemicalelement[]
* Called by: main
* Calls: none
*/
void readPeriodicTable(CElement chemicalelement[], int &num)
{
int count;
ifstream infile;
infile.open("periodicTable.txt");
if ( !infile.is_open() )
{
cout << endl << "ERROR: Unable to open file!" << endl;
system("PAUSE");
exit(1);
}
count = 0;
while (!infile.eof() )
{
infile >> chemicalelement[count].atomicSymbol;
infile >> chemicalelement[count].atomicNumber;
infile >> chemicalelement[count].atomicMass;
count++;
}
num = count;
infile.close();
return;
}//end readPeriodicTable
/* Function bubbleSort: recieves an array chemicalelement[], and sorts it in an
* alphabetical order
* Called by: main
* Calles: none
*/
void bubbleSort(CElement chemicalelement[], int num)
{
int j, pass;
bool switched = true;
CElement hold;
for (pass = 0; pass < num - 1 && switched == true; pass++)
{
switched = false;
for (j = 0; j < num - pass - 1; j++)
if (chemicalelement[j].atomicSymbol > chemicalelement[j+1].atomicSymbol)
{
switched = true;
hold = chemicalelement[j];
chemicalelement[j]= chemicalelement[j+1];
chemicalelement[j+1] = hold;
}
}
}// end bubbleSort
/* Function prinTable: recieves a sorted array chemicalelement[], and prints
* neatly arranged table into a file output.txt
* Called by: main
* Calls: none
*/
void printTable(CElement chemicalelement[], int &num)
{
ofstream outfile;
outfile.open("output.txt");
if(!outfile.is_open())
{
cout << endl << "ERROR; Unable to open file!" << endl;
system("PAUSE");
exit(1);
}
outfile << "Atomic Symbol " << "Atomic Number " << "Atomic Mass"
<< endl << endl;
int count;
for(count = 0; count < num; count++)
{
outfile.width(17);
outfile << left << chemicalelement[count].atomicSymbol;
outfile.width(17);
outfile << left << chemicalelement[count].atomicNumber;
outfile.width(17);
outfile << left << chemicalelement[count].atomicMass << "\n";
}
return;
}// end printTable
void promptUser()
{
cout << "Enter the molecular formula: "<< endl;
cout << "Enter the weight in grams: " << endl;
}
float numberOfGramrsPerMole(CElement chemicalelement[], string molecularFormula)
{
string s = molecularFormula, element1, element2;
int subscript1, subscript2;
for(int i = 0; i < s.length() ; i++) // not even close to solve the problem
{
if(s[i] == isupper())
element1 = s[i];
i++;
else if(s[i] == isupper())
element2 = s[i];
subscript1 = 1;
}
}