Created
November 21, 2016 22:06
-
-
Save dutchand/ae2547b10be2b9eaf84950ab67cd4f0c to your computer and use it in GitHub Desktop.
Reservation System 3rd yr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //--------------------------------------------------------------------------- | |
| #include "TLista_Reserveciones.h" | |
| #include <stdlib.h> | |
| TLista_Reserveciones::TLista_Reserveciones() | |
| { | |
| inicio=NULL; | |
| nueva=NULL; | |
| } | |
| void TLista_Reserveciones::insertar_reservacion(char*nomb,char* anno,char*lab,char*maq,char*dia,char*turno) | |
| { | |
| nueva=new TReservaciones(); | |
| nueva->set_nombre(nomb); | |
| nueva->set_anno(anno); | |
| nueva->set_laboratorio(lab); | |
| nueva->set_maquina(maq); | |
| nueva->set_dia(dia); | |
| nueva->set_turno(turno); | |
| if (inicio==NULL) | |
| inicio=nueva; | |
| else | |
| { | |
| TReservaciones*actual=NULL; | |
| actual=inicio; | |
| while (actual->siguiente!=NULL) | |
| actual=actual->siguiente; | |
| actual->siguiente=nueva; | |
| } | |
| } | |
| //------------------------------------------------------------------------------ | |
| TReservaciones*TLista_Reserveciones::Buscar_reservacion(char* nombre,char* dia) | |
| { | |
| TReservaciones*temp=inicio;int cont=0; | |
| while (temp!=NULL) | |
| { | |
| if(strcmp(temp->get_nombre(),nombre)==0 && strcmp(temp->get_dia(),dia)==0) | |
| {return temp;cont=1;} | |
| temp=temp->get_siguiente(); | |
| } | |
| if(cont==0) | |
| return NULL; | |
| } | |
| //------------------------------------------------------------------------------ | |
| bool TLista_Reserveciones::Eliminar_Reservacion(TReservaciones* reservacion) | |
| { | |
| TReservaciones*temp,*anterior; | |
| if(reservacion!=NULL) | |
| { | |
| if(inicio!=NULL) | |
| { | |
| if(inicio==reservacion) | |
| { | |
| temp=inicio; | |
| inicio=inicio->siguiente; | |
| delete temp; | |
| } | |
| else | |
| { | |
| temp=anterior=inicio; | |
| while (temp!=NULL && temp!=reservacion) | |
| { | |
| anterior=temp; | |
| temp=temp->siguiente; | |
| } | |
| if(temp!=NULL) | |
| { | |
| anterior->siguiente=temp->siguiente; | |
| delete temp; | |
| } | |
| } | |
| return true; | |
| } | |
| } | |
| else | |
| return false; | |
| } | |
| //------------------------------------------------------------------------------ | |
| bool TLista_Reserveciones::Verificar_Reservacion(char*nomb,char* anno,char*lab,char*maq,char*dia,char*turno) | |
| { | |
| bool bandera=true; | |
| TReservaciones*temp=inicio; | |
| int casos=0; | |
| if (temp) | |
| { | |
| while (temp!=NULL) | |
| { | |
| if((strcmp(temp->get_nombre(),nomb)==0) && | |
| (strcmp(temp->get_dia(),dia)==0)) | |
| casos=1; | |
| else | |
| { | |
| if((strcmp(temp->get_maquina(),maq)==0) && | |
| (strcmp(temp->get_dia(),dia)==0) && | |
| (strcmp(temp->get_turno(),turno)==0) && | |
| (strcmp(temp->get_laboratorio(),lab)==0)) | |
| casos=2; | |
| } | |
| temp=temp->siguiente; | |
| } | |
| switch (casos) | |
| { | |
| case 1: | |
| ShowMessage("!!Ya existe una reservacion con ese nombre en el dia!!"); | |
| bandera=false; | |
| break; | |
| case 2: | |
| ShowMessage("!!Ya esta ocupada la maquina!!"); | |
| bandera=false; | |
| break; | |
| } | |
| } | |
| return bandera; | |
| } | |
| //------------------------------------------------------------------------------ | |
| void TLista_Reserveciones::Salvar(char* Nombre) | |
| { | |
| remove(Nombre); | |
| fstream Fichero(Nombre,ios_base::in | ios_base::out); | |
| if (inicio) | |
| { | |
| TReservaciones*temp=inicio; | |
| while (temp) | |
| { | |
| Fichero<<temp->get_nombre()<<endl; | |
| Fichero<<temp->get_anno()<<endl; | |
| Fichero<<temp->get_laboratorio()<<endl; | |
| Fichero<<temp->get_maquina()<<endl; | |
| Fichero<<temp->get_dia()<<endl; | |
| Fichero<<temp->get_turno(); | |
| if(temp->siguiente!=NULL) | |
| Fichero<<endl<<endl; | |
| temp=temp->siguiente; | |
| } | |
| Fichero.close(); | |
| } | |
| else | |
| { | |
| Fichero.close(); | |
| remove(Nombre); | |
| } | |
| } | |
| //------------------------------------------------------------------------------ | |
| void TLista_Reserveciones::Cargar(char* Nombre) | |
| { | |
| fstream Fichero(Nombre,ios_base::in | ios_base::app ); | |
| if(Fichero.is_open()&& Fichero.peek()>0){ | |
| char*nombre=new char[50]; | |
| char*anno=new char[10]; | |
| char*lab=new char[15]; | |
| char*maq=new char[30]; | |
| char*dia=new char[15]; | |
| char*turno=new char[30]; | |
| while (!Fichero.eof()) | |
| { | |
| Fichero>>nombre; | |
| Fichero>>anno; | |
| Fichero>>lab; | |
| Fichero>>maq; | |
| Fichero>>dia; | |
| Fichero>>turno; | |
| insertar_reservacion(nombre,anno,lab,maq,dia,turno); | |
| } | |
| } | |
| Fichero.close(); | |
| } | |
| //------------------------------------------------------------------------------ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment