Question
Asked by:
bobbyboucher
bobbyboucher
Rating : No Rating
Questions Asked: 37
Tutorials Posted: 0
 

$12.00 Array of Class Modified

Q:
Please see attached. Note that the Restrictions are different. New restrictions are that we must first sort data by element name using cmpstr function then use Binary search to look up elements instead.
 
Attachments:
Chemistry.pdf (22K)
Element.txt (0K)
Formula.txt (0K)


   
   
   
   
 
Available Tutorials to this Question
Posted by:
rainman
rainman
Rating (40): A+
Questions Asked: 2
Tutorials Posted: 174, earned $906.64
 

$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)
   
Join Now or Log In
Get Tutoring
Get Paid
Academic Honesty