I have the next class;
class Estudiante {
private:
string nombre,cedula;
int matricula;
float calificacion;
public:
//se dejo con un destructor por defecto
void anadir(int _matricula,string _nombre,string _cedula,float _calificacion);
void insertar();
void borrar();
void listar();
void listar_inverso();
void promedio();
int getMatricula() const {
return matricula;
}
float getCalificacion() const {
return calificacion;
}
};
/**
* Este metodo es utilizado para asignarle los datos a cada una de las propiedades
* de esta manera el objeto con todas sus propiedades asignadas se almacenan
* en el vector de estudiantes
**/
void Estudiante::anadir(int _matricula,string _nombre,string _cedula,float _calificacion) {
matricula = _matricula;
nombre = _nombre;
cedula = _cedula;
calificacion = _calificacion;
}
/**
* Lista los estudiantes, es utilizado por el vecto junto a un
* iterador
**/
void Estudiante::listar() {
cout << matricula <<" " << nombre <<" " << cedula <<" " << calificacion << endl;
}
I use it to create objects of type estudiante
and save them in a stack of the type of the class;
stack<Estudiante> lista_estudiantes;
Estudiante *est;
//Nuevo objeto de tipo estudiante
est = new Estudiante;
est->anadir(100,"estudent1","000-000000-0",88);
lista_estudiantes.push(*est);
est->anadir(200,"estudent2","000-000000-0",80);
lista_estudiantes.push(*est);
est->anadir(300,"estudent3","000-000000-0",95);
lista_estudiantes.push(*est);
I have tried the following;
for ( int it = 0; it < lista_estudiantes.size(); ++it ){
est->listar();
}
But in this case I only get the last element created, not all, if I have 3 elements created I printed 3 times the last one;
MATRICULA | NOMBRE | CEDULA | CALIFICACION |
300 estudent3 000-000000-0 95
300 estudent3 000-000000-0 95
300 estudent3 000-000000-0 95
All this compiling works, runs and I can register estudiantes
, now I can not print the contents of my stack.