$12.00 Modified C++ Molecular Weight Program. Sorts The List And Uses Binary Search With cmpstr. Compiled Tested Commented
- This tutorial was purchased 1 time and hasn't been rated yet.
- Posted on Mar 04, 2009 at 12:31:54PM
A:
Preview: ... k the remaining lower half<br> if(strcmp(key.c_str(), table[center].getSymbol().c_str()) < 0)<br> return binarySearch(table, low, center, key);<br><br> //else if the key comes after the center element, then check the remaining upper half<br> else if (strcmp(key.c_str(), table[center].getSymbol().c_str()) > 0)<br> return binarySearch(table, center+1, high, key);<br><br> //the key was the center element so return it's weight<br> return table[center].getWeight();<br>}<br><br><br><br>int main()<br>{<br> /* Declare an array of elements named table there are currentley<br> only 117 elements so we make it that size. We use the integer<br> elementCount to keep track of how many of those we are using<br> in this particular program with this particular file.<br> */<br><br> Element table[117];<br> int elementCount = 0;<br><br> //Open the file for reading<br> ifstream elementin("Element.txt", ios::in);<br><br> string symbol; // temporary variables to store the elements data<br> float weight;<br><br> //While there is still a symbol to read there will still be a weight to read<br> while ((elementin >> symbol) != NULL)<br> {<br> elementin >> weight;<br><br> //Set the elements properties<br> table[elementCount].setSymbol(symbol);<br> table[elementCount].setWeight(weight);<br><br> //Incerement the number of elements this program uses so we will know<br> //how many we have in our array.<br> elementCount++;<br> }<br><br> elementin.close();<br><br> //sort the table alphabitcally by symbol<br> sortTable(table, elementCount);<br><br> //open formula.txt for reading<br> ifstream fin("Formula.txt", ios::in);<br><br ...
The full tutorial is about 2431 words long plus attachments.
Attachments:
main.cpp (8K) (Preview)