So I have created a program which can read a .dat file of about 20 lines containing info about different atoms (name, symbol, mass etc) and added them all to a vector of class type I made called Atom.
How would I write a function to find the atom with the highest mass?
Here is my class:
class Atom
{
string element, symbol;
float number;
float mass;
public:
Atom(string e, string s, float n, float m){
element = e; symbol = s; number = n; mass = m;
}
string getElement();
string getSymbol();
float getNumber();
float getMass();
float ratio();
friend ostream& operator<<(ostream& os, Atom c);
};
and the information is added to a vector with the following statements
ifstream fin("atoms.dat");
string E, S;
float M, N;
vector <Atom> periodic;
while(!fin.eof()){
fin >> E >> S >> M >> N;
Atom Atom(E, S, M, N);
periodic.push_back(Atom);
}
I want to be able to write a function which finds which atom has the highest mass, I've tried using a max_element function but I keep getting errors. Is there a quick way of comparing the member variables of class objects stored in a vector?
I'm currently using C++ 98 as it is what my course requires.
Thanks