Tuesday, July 28, 2009

C++ problem? This program has some error, please correct it.?

#include "element.h"


#include %26lt;qfile.h%26gt;


#include %26lt;iostream%26gt;


#include %26lt;qstring.h%26gt;





using namespace std;





element::element(QString p_filename)


{


QFile element_file(p_filename);


element_file.open( IO_ReadOnly );


element_doc.setContent( %26amp;element_file );


element_file.close();





}





QString element::get_element(int p_atomic_number)


{


QString return_value;


QDomElement element_node;


QDomNodeList property_node_list;





// Get all the ATOMS


QDomNodeList atom_node_list = element_doc.documentElement().childNodes...





for (unsigned int i = 0; i %26lt; atom_node_list.count(); i++)


{





// Get all the properties


QDomElement atom_node = atom_node_list.item(i).toElement();


property_node_list = atom_node.childNodes();





for (unsigned int j = 0; j %26lt; property_node_list.count(); j++)


{


QDomElement property_node = property_node_list.item(j).toElement();





// Look for the element number


if (property_node.tagName() == "ATOMIC_NUMBER" %26amp;%26amp; property_node.text() == QString::number(p_atomic_number))


{


// Found it!


element_node = property_node.parentNode().toElement();


}


}


}





// Gather together all the information for the element


property_node_list = element_node.childNodes();


return_value = "";


for (unsigned int i = 0; i %26lt; property_node_list.count(); i++)


{


QDomElement property_node = property_node_list.item(i).toElement();


return_value += property_node.tagName() + "=" + property_node.text().stripWhiteSpace() + " " + property_node.attribute("UNITS") + '\n';


}





return return_value;


}

C++ problem? This program has some error, please correct it.?
You haven't specified the error. How do you expect us to correct the error?
Reply:#include "element.h"


#include %26lt;qfile.h%26gt;


#include %26lt;iostream%26gt;


#include %26lt;qstring.h%26gt;





Check the syntax of "" above.





If this doesn;t compile, what is the error?

flower garden

No comments:

Post a Comment