I need help with this. I have a list in which I must store the information of the taxi drivers, in one of the functions I must print a report of taxi drivers who worked overtime, ordered in descending order. I have seen several examples on the internet but none has helped me, this is the code:
void ReporteHorasExtra() {
for (list<Taxista*>::iterator it = taxistas.begin(); it != taxistas.end(); it++) {
if ((*it)->horasExtras() > 0) {
cout << "Nombre:";
cout<<(*it)->getNombre();
cout << ' ';
cout<<(*it)->getApellido();
cout << ' '<<"Sexo: ";
if ((*it)->getSexo() == true) {
cout << "Femenino" << ' ';
}
if ((*it)->getSexo() == false) {
cout << "Masculino" << ' ';
}
cout << "Cantidad de horas extra: ";
cout<<(*it)->horasExtras();
cout << endl;
}
}
}
That's what I have, but I do not know how to order them.
Issue # 1
I have updated the function in the following way, maybe it is very bad and I am sorry for that, but I have not understood completely.
void ReporteHorasExtra() {
for (list<Taxista>::iterator it = taxistas.begin(); it != taxistas.end(); it++) {
vector<Taxista> horas(taxistas.size());
copy(taxistas.begin(), taxistas.end(), horas.begin());
sort(horas.begin(), horas.end(), [](auto &a, auto &b) { return a->horasExtras() > b->horasExtras(); });
if ((it)->horasExtras() > 0) {
cout << "Nombre:";
cout<<(it)->getNombre();
cout << ' ';
cout<<(it)->getApellido();
cout << ' '<<"Sexo: ";
if ((it)->getSexo() == true) {
cout << "Femenino" << ' ';
}
if ((it)->getSexo() == false) {
cout << "Masculino" << ' ';
}
cout << "Cantidad de horas extra: ";
cout<<(it)->horasExtras();
cout << endl;
}
}
}
This is what I have done, but I have obtained these errors.