I comped, linked, and ran all four of the second set of sources, and it sent "it's working!" to the screen. I did this on djgpp.
I comped, linked, and ran all four of the second set of sources, and it sent "it's working!" to the screen. I did this on djgpp.
Also, prelude, I find it quite helpful to include files needed for a class's implemenetation in that class's header. That way, if a class needs something that the rest of the program does not, I won't forget to include it. Also, including all fiels in the main sets up dependancies between them, so you can get subtle errors if you include things in the wrong sequence.
>I find it quite helpful to include files needed for a class's
>implemenetation in that class's header.
General rules of thumb aren't written in stone. I do the same thing as well when the situation warrants it.
-Prelude
My best code is written with the delete key.
Ok I don't know what I did but I got it working now! Hopefully I can finish this program for monday. Thanks for all your help.
Prelude, I think you might be right about the double underscore prefix. That's odd because in the assignment they didn't have that.
Ok now I am trying to link the element files as well. The setAWeight function will be called from the aminoacid_analyzer but it is endefined identifier.
aminoacid_main.cpp
aminoacid_analyzer.hCode:#include "aminoacid_analyzer.h" int main( void ) { char elementFile[] = "elements.dat"; char acidFile[] = "aminoacids.dat"; AminoAcidAnalyzer *aaa = new AminoAcidAnalyzer; aaa->populate(elementFile, acidFile); return 0; }
aminoacid_analyzer.cppCode:#ifndef AMINO_ACID_ANALYZER__ #define AMINO_ACID_ANALYZER__ #include <iostream.h> #include "element.h" class AminoAcidAnalyzer { Element elements[5]; int acidCount; public: AminoAcidAnalyzer(); void populate(char * elementFile, char * acidFile); private: void populateElements(char * elementFile); void populateAminoAcids(char * acidFile); }; #endif
element.hCode:#include <iostream.h> #include "aminoacid_analyzer.h" //#include "element.h" AminoAcidAnalyzer::AminoAcidAnalyzer() { acidCount = 0; } void AminoAcidAnalyzer::populate(char *elementFile, char *acidFile) { populateElements(elementFile); populateAminoAcids(acidFile); } void AminoAcidAnalyzer::populateElements(char * elementFile) { setAWeight(); <--- undefined identifier } void AminoAcidAnalyzer::populateAminoAcids(char * acidFile) { cout<<"populateAminoAcids"; }
element.cppCode:#ifndef ELEMENT__ #define ELEMENT__ class Element { char atomic_symbol; double atomic_mass; public: void setAWeight(); void getAWeight(char * elementFile); }; #endif
Code:#include "element.h" void Element::setAWeight() { } void Element::getAWeight(char * elementFile) { }
This is getting to be an interesting project.
The problem now is that Element::setAWeight() is called from outside the class Element without qualification. You will need to call the setAWeight() member of one of your class' Element element[]'s. Remember, class AminoAcid has data members of type Element, but Element is not a nested class declaration, so only the instantiations of Element are in scope, not the member functions of Element.
So if you want to setAWeight for one of your elements, you will need to make a pub function in AminoAcid that takes an int, and have it call a member of one of it's Element objects, like this:
If Element is to be an implementation detail of AminoAcid, then any required functons in Element need to be made available via AminoAcid.Code:AminoAcid::Weight(int e, whatever) { element[e]->setAWeight(whatever); }
Hehe, you have too many more problems and I'm gonna need to retake chem 1101