Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <clocale>
- #include <cstring>
- using namespace std;
- void cargarCadena(char *palabra, int tam){
- int i=0;
- fflush(stdin);
- for (i=0; i<tam; i++){
- palabra[i]=cin.get();
- if (palabra[i]=='\n'){
- break;
- }
- }
- palabra[i]='\0';
- fflush(stdin);
- }
- class Fecha{
- private:
- int dia,mes, anio;
- public:
- void Cargar(){
- cin>>dia;
- cin>>mes;
- cin>>anio;
- }
- void Mostrar(){
- cout<<dia<<"/";
- cout<<mes<<"/";
- cout<<anio<<endl;
- }
- int getDia(){return dia;}
- int getMes(){return mes;}
- int getAnio(){return anio;}
- void setDia(int d){dia=d;}
- void setMes(int m){mes=m;}
- void setAnio(int a){anio=a;}
- };
- class Partidos{
- private:
- int codPartido;
- int sede;
- int codLocal;
- int codVisitante;
- Fecha fechaRealizacion;
- char nombreArbitro[50];
- bool estado;
- public:
- Partidos(int codPart = 0){
- codPartido = codPart;
- }
- int getCodPartido(){return codPartido;}
- int getSede(){return sede;}
- int getCodLocal(){return codLocal;}
- int getCodVisitante(){return codVisitante;}
- Fecha getFechaRealizacion(){return fechaRealizacion;}
- const char* getNombreArbitro(){return nombreArbitro;}
- bool getEstado(){return estado;}
- void setCodPartido(int cp){codPartido = cp;}
- void setSede(int s){sede = s;}
- void setCodLocal(int cl){codLocal = cl;}
- void setCodVisitante(int cv){codVisitante = cv;}
- void setFechaRealizacion(Fecha f){fechaRealizacion = f;}
- void setNombreArbitro(const char* na){strcpy(nombreArbitro, na);}
- void setEstado(bool e){estado = e;}
- bool Cargar(){
- cout<< "CODIGO PARTIDO: ";
- cin>> codPartido;
- cout<< "SEDE: ";
- cin>> sede;
- cout<< "CODIGO EQUIPO LOCAL: ";
- cin>> codLocal;
- cout<< "CODIGO EQUIPO VISITANTE: ";
- cin>> codVisitante;
- cout<< "FECHA DE REALIZACION: ";
- fechaRealizacion.Cargar();
- cout<< "NOMBRE DEL ARBITRO: ";
- cin>> nombreArbitro;
- estado = true;
- return true;
- }
- void Mostrar(){
- cout<< codPartido << endl;
- cout<< sede << endl;
- cout<< codLocal << endl;
- cout<< codVisitante << endl;
- fechaRealizacion.Mostrar();
- cout<< nombreArbitro << endl;
- cout<< estado << endl;
- }
- };
- class ArchivoPartido{
- private:
- char nombre[30];
- public:
- ArchivoPartido(const char *n){
- strcpy(nombre, n);
- }
- bool grabarRegistro(Partidos reg){
- FILE * archivo = fopen(nombre, "ab");
- if (archivo == NULL){
- return false;
- }
- Partidos registro;
- bool exito = registro.Cargar();
- if (exito){
- fwrite(®istro, sizeof registro, 1, archivo);
- cout << "REGISTRO ESCRITO CON EXITO"<<endl;
- }
- fclose(archivo);
- return true;
- }
- bool mostrarRegistros(){
- FILE * archivo = fopen(nombre, "rb");
- if (archivo == NULL)
- {
- cout << "ERROR ABRIENDO EL ARCHIVO en MOSTRAR\n";
- return false;
- }
- Partidos leer;
- while(fread(&leer, sizeof leer, 1, archivo)==1)
- {
- if (leer.getEstado()) leer.Mostrar();
- }
- fclose(archivo);
- return true;
- }
- int buscarCodigo (int codigo) {
- FILE * archivo = fopen(nombre, "rb");
- if (archivo == NULL) {
- cout << "ERROR ABRIENDO EL ARCHIVO BUSCAR JUGADOR \n";
- return -1;
- }
- Partidos leer;
- int pos = 0;
- while (fread(&leer, sizeof leer, 1, archivo)) {
- if (leer.getCodPartido() == codigo && leer.getEstado()) {
- leer.Mostrar();
- fclose(archivo);
- return pos;
- }
- pos++;
- }
- cout << "NO SE ENCONTRO EL EQUIPO CON EL CODIGO INGRESADO \n";
- fclose(archivo);
- return -2;
- }
- bool bajaLogica() {
- int codigo;
- cout << "INGRESAR CODIGO DEL EQUIPO: ";
- cin >> codigo;
- int pos = buscarCodigo(codigo);
- if (pos > -1) {
- FILE * archivo = fopen(nombre, "r+b");
- if (archivo == NULL) {
- cout << "ERROR ABRIENDO EL ARCHIVO \n";
- return false;
- }
- Partidos leer;
- fseek(archivo, sizeof leer * pos, SEEK_SET);
- fread(&leer, sizeof leer, 1, archivo);
- leer.setEstado(false);
- fseek(archivo, sizeof leer * pos, SEEK_SET);
- if (fwrite(&leer, sizeof leer, 1, archivo)) {
- fclose(archivo);
- cout << "REGISTRO ELIMINADO CON EXITO \n";
- return true;
- }
- fclose(archivo);
- cout << "ERROR DE ARCHIVO, INTENTA DE NUEVO\n";
- return false;
- }
- return false;
- }
- Partidos leerRegistro(int pos){
- Partidos reg;
- reg.setCodLocal(-1);
- FILE *p;
- p=fopen(nombre, "rb");
- if(p==NULL) return reg;
- fseek(p, sizeof(Partidos)*pos,0);
- fread(®, sizeof reg,1, p);
- fclose(p);
- return reg;
- }
- int contarRegistros(){
- FILE *p;
- p=fopen(nombre, "rb");
- if(p==NULL) return -1;
- fseek(p, 0,2);
- int tam=ftell(p);
- fclose(p);
- return tam/sizeof(Partidos);
- }
- };
- void punto3(){
- ArchivoPartido archPart("Partidos.dat");
- int cantPart = archPart.contarRegistros();
- Partidos regPart;
- Fecha fechaNueva;
- cout<< "INGRESAR FECHA: ";
- fechaNueva.Cargar();
- if (cantPart <= 0){
- cout<< "No hay registros" << endl;
- return;
- }
- int cont=0;
- for (int x=0; x<cantPart; x++){
- regPart = archPart.leerRegistro(x);
- if (fechaNueva.getAnio() < regPart.getFechaRealizacion().getAnio() && regPart.getEstado()){
- cont++;
- }
- }
- Partidos *v;
- v=new Partidos[cont];
- if(v==NULL) return;
- int pos=0;
- for (int x=0; x<cantPart; x++){
- regPart = archPart.leerRegistro(x);
- if (regPart.getEstado()){
- v[pos] = regPart;
- pos++;
- }
- }
- for (int x=0; x<cont; x++){
- v[x].Mostrar();
- }
- delete[] v;
- }
- int main (void){
- int opc;
- ArchivoPartido archPartidos("Partidos.dat");
- while(true){
- system("cls");
- cout<<"MENU ALUMNOS "<<endl;
- cout<<"********************** "<<endl;
- cout<<"1. AGREGAR REGISTRO "<<endl;
- cout<<"2. BAJA LOGICA "<< endl;
- cout<<"3. MOSTRAR REGISTROS "<<endl;
- cout<<"0. SALIR DEL PROGRAMA "<<endl;
- cout<<"********************** "<<endl;
- cout<<"OPCION "<<endl;
- cin>>opc;
- system("cls");
- switch(opc){
- case 1:
- archPartidos.grabarRegistro(opc);
- break;
- case 2:
- archPartidos.bajaLogica();
- break;
- case 3:
- punto3();
- break;
- case 0:
- return 0;
- break;
- }
- system("pause");
- system("cls");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement