Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Lista.h"
- #define MAX 100
- typedef struct paciente{
- int codigo;
- int gravedad;
- }Paciente;
- class Hospital{
- public:
- Hospital();
- void ingreso(Paciente& p const);
- void alta(Paciente& p const);
- void muerte(Paciente& p const);
- int nPacientesUCI() const;
- int nPacientesPlanta() const;
- int nPacientesGrav(int g) const;
- ~Hospital();
- private:
- Lista<Paciente> UCI;
- Lista<Paciente> Planta;
- Lista<Paciente> aux;
- int pacientesPlanta;
- int pacientesUCI;
- };
- Hospital::Hospital(){
- pacientesPlanta = 0;
- pacientesUCI = 0;
- }
- //precondicion: la gravedad del paciente ha de estar comprendida entre 0 y 9
- void Hospital::ingreso(Paciente& p const){
- int gravedadMin = 0, idaux;
- Paciente auxP, menos_grave;
- //acceso a planta
- if(p.gravedad > 5){
- if(nPacientesPlanta() < MAX){
- Planta.push(p);
- pacientesPlanta++;
- }
- else{
- while(!Planta.vacia()){
- auxP = Planta.tope();
- Planta.pop();
- aux.push(auxP);
- if(auxP.gravedad > gravedadMin){
- gravedadMin = auxP.gravedad;
- idaux = auxP.codigo;
- }
- }
- while(!aux.vacia()){
- auxP = aux.tope();
- if(auxP.codigo == idaux)
- menos_grave = auxP;
- Planta.push(auxP);
- aux.pop();
- }
- alta(menos_grave);
- }
- }
- //muerto
- else if(p.gravedad == 0)
- muerte(p);
- //acceso a UCI
- else{
- if(nPacientesUCI() < MAX){
- UCI.push(p);
- pacientesUCI++;
- }
- else{
- while(!UCI.vacia()){
- auxP = UCI.tope();
- UCI.pop();
- aux.push(auxP);
- if(auxP.gravedad > gravedadMin){
- gravedadMin = auxP.gravedad;
- idaux = auxP.codigo;
- }
- }
- while(!aux.vacia()){
- auxP = aux.tope();
- if(auxP.codigo == idaux)
- menos_grave = auxP;
- else if(auxP.codigo != idaux)
- UCI.push(auxP);
- aux.pop();
- }
- menos_grave.gravedad = 6;
- ingreso(menos_grave);
- }
- }
- }
- inline int Hospital::nPacientesUCI() const{return pacientesUCI;}
- inline int Hospital::nPacientesPlanta() const{return pacientesPlanta;}
- int Hospital::nPacientesGrav(int g) const{
- int cont = 0;
- Paciente auxP;
- while(!Planta.vacia()){
- auxP = Planta.tope();
- if(auxP.gravedad == g)
- cont++;
- Planta.pop();
- aux.push(auxP);
- }
- while(!aux.vacia()){
- auxP = aux.tope();
- aux.pop();
- Planta.push(auxP);
- }
- while(!UCI.vacia()){
- auxP = UCI.tope();
- if(auxP.gravedad == g)
- cont++;
- UCI.pop();
- aux.push(auxP);
- }
- while(!aux.vacia()){
- auxP = aux.tope();
- aux.pop();
- UCI.push(auxP);
- }
- return cont;
- }
- Hospital::~Hospital(){
- ~UCI();
- ~Planta();
- ~aux();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement