void twelfthTestCase02(void) { int i, r; ArrayList* list; Employee* pAux[LENGTH]; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->add(list,pAux[i]); } for(i=0; i < LENGTH; i++) { r = list->indexOf(list,pAux[i]); utest_assertEqualsIntMsg(r,i,"Error in return value <indexOf> the correct value to return is the index"); } free(list); for(i=0; i < LENGTH; i++) free(pAux[i]); }
void seventhTestCase04(void) { int i, r; ArrayList* list; Employee* pAux[LENGTH]; Employee* pAuxToSet; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->add(list,pAux[i]); } pAuxToSet = newEmployee(id[5],unsortedList[5],unsortedList[5],salary[5],sector[5]); r = list->set(NULL,0,pAuxToSet); utest_assertEqualsIntMsg(r,-1,"Error in return value <set> if the pointer to the new Element is NULL the correct value to return is -1"); free(list); }
void eighthTestCase02(void) { int i, r; ArrayList* list; Employee* pAux[LENGTH]; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->add(list,pAux[i]); } for(i=LENGTH-1; i >=0 ; i--) { r = list->remove(list,0); utest_assertEqualsIntMsg(r,0,"Error in return value <remove(list,0)> if ok the correct value to return is 0"); } utest_assertEqualsIntMsg(list->size,0,"Error in the size of the array, after remove all the elements the correct value is 0"); free(list); for(i=0; i < LENGTH; i++) free(pAux[i]); }
void fifthTestCase01(void) { int i; ArrayList* list; Employee* pAux[LENGTH]; Employee* pAuxGet; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->add(list,pAux[i]); } for(i=0; i < LENGTH; i++) { pAuxGet = list->get(list,i); utest_assertNotNullMsg(pAuxGet,"Error in return value <get> if ok the correct value to return is not NULL"); } free(list); for(i=0; i < LENGTH; i++) free(pAux[i]); }
/** \brief Returns an array containing all of the elements in this list in proper sequence * \param pList ArrayList* Pointer to arrayList * \return ArrayList* Return (NULL) if Error [pList is NULL pointer] * - (New array) if Ok */ ArrayList* al_clone(ArrayList* pList) { ArrayList* returnAux; returnAux = al_newArrayList(); int i; if(pList != NULL && returnAux!= NULL) { for(i=0;i<pList->size;i++) { al_add(returnAux,al_get(pList,i)); } } else{ if(pList == NULL) { returnAux = NULL; } } //printf("% p / %p \n", pList, returnAux ); return returnAux; }
void eleventhTestCase01(void) { int i, r; ArrayList* list; Employee* pAux[LENGTH]; Employee* pAuxToPush; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->add(list,pAux[i]); } pAuxToPush = newEmployee(id[5],unsortedList[5],unsortedList[5],salary[5],sector[5]); r = list->push(list,i-1,pAuxToPush); utest_assertEqualsIntMsg(r,0,"Error in return value <push> if ok the correct value to return is 0"); free(list); free(pAuxToPush); for(i=0; i < LENGTH; i++) free(pAux[i]); }
void seventeenthTestCase02(void) { int i; ArrayList* list; Employee* pAux[LENGTH]; Employee* pAuxGet[LENGTH]; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->add(list,pAux[i]); } list->sort(list, compareEmployee,0); for(i=0; i < LENGTH; i++) { pAuxGet[i] = list->get(list,i); utest_assertNotNullMsg(pAuxGet[i],"Error in return value <get> if ok the correct value to return is not NULL"); } for (i=0;i < LENGTH;i++) { utest_assertEqualsFloatMsg(((Employee*)pAuxGet[i])->salary,salarySortedUp[i],"Error value in <.salary> after sort"); } free(list); for(i=0; i < LENGTH; i++) free(pAux[i]); }
/** \brief Imprime una serie de informes * 1- Imprime nomina ocmpleta * 2- solicita desde y hasta e imprime una sublista de empleados por legajo * 3 imprime listado por sueldo < o > * * \param pList ArrayList* array de donde se obtendran los datos * \return int * */ int informes(ArrayList* pList) { int option; int from; int to; int returnAux=-1; int order; ArrayList* ArrayAux=al_newArrayList(); if(pList!=NULL && ArrayAux!=NULL ) { getInt(&option,"\n1-Imprimir Nomina\n2-Imprimir Sub-Nomina\n3-Imprimir listado por sueldo\n4-Salir\nOption:","Error Opcion no valida",1,4); switch(option) { case 1: PrintEmployees(pList); break; case 2: if(!getInt(&from,"Ingrese desde que legajo:","Error Legajo mayor a los empleados en nomina...\n",0,pList->size)&& getInt(&to,"Ingrese hasta que legajo:","Error Legajo mayor a los empleados en nomina...\n",0,pList->size)) { ArrayAux=al_subList(pList,from-1,to); PrintEmployees(ArrayAux); al_deleteArrayList(ArrayAux); } break; case 3: if(!getInt(&order,"\n1-Mostrar Nomina por sueldo de mayor a menor\n2-Mostrar Nomina por sueldo de menor a mayor\nOption:","Error",1,2)) { switch(order) { case 1: ArrayAux=pList->clone(pList); pList->sort(ArrayAux,compareEmployee,0); PrintEmployees(ArrayAux); pList->deleteArrayList(ArrayAux); break; case 2: ArrayAux=pList->clone(pList); pList->sort(ArrayAux,compareEmployee,1); PrintEmployees(ArrayAux); pList->deleteArrayList(ArrayAux); break; } } break; case 4: break; } returnAux=0; } return returnAux; }
/** \brief Returns an array containing all of the elements in this list in proper sequence * \param pList ArrayList* Pointer to arrayList * \return ArrayList* Return (NULL) if Error [pList is NULL pointer] * - (New array) if Ok */ ArrayList* al_clone(ArrayList* pList) { ArrayList* returnAux = NULL; int i; if(pList!=NULL) { returnAux =al_newArrayList(); for(i=0;i<pList->size;i++) al_add(returnAux,al_get(pList,i)); } return returnAux; }
/** \brief Returns a new arrayList with a portion of pList between the specified * fromIndex, inclusive, and toIndex, exclusive. * \param pList ArrayList* Pointer to arrayList * \param from int Initial index of the element (inclusive) * \param to int Final index of the element (exclusive) * \return int Return (NULL) if Error [pList is NULL pointer or invalid 'from' or invalid 'to'] * - ( pointer to new array) if Ok */ ArrayList* al_subList(ArrayList* pList,int from,int to) { ArrayList* returnAux = NULL; int i; if(pList!=NULL&&from>=0&&from<to&&to<=pList->size&&from<pList->size) { returnAux =al_newArrayList(); if(returnAux!=NULL) for(i=from;i<=to;i++) pList->add(returnAux,pList->get(pList,i)); } return returnAux; }
/** \brief Returns an array containing all of the elements in this list in proper sequence * \param pList ArrayList* Pointer to arrayList * \return ArrayList* Return (NULL) if Error [pList is NULL pointer] * - (New array) if Ok */ ArrayList* al_clone(ArrayList* pList) { ArrayList* returnAux = NULL; if(pList!=NULL) { returnAux=al_newArrayList(); returnAux=pList->subList(pList,0,pList->size); //for(i=0) //pList; } return returnAux; }
int start() { int opcion = 0; ArrayList *calendario = al_newArrayList(); cargarEventosDeArchivo(calendario); do { system("cls"); printMenu(); pedirInt(&opcion,"Ingrese una opcion:\n",7,1,"Ingrese una opcion valida. Entre 1 y 6\n"); switch(opcion) { case NUEVO: if(crearNuevoEvento(calendario)) printf("Hubo un error al intentar crear el evento\n"); pausa("Presione una tecla para volver\n"); break; case CONSULTAR_DIA: if(consultarFecha(calendario)) printf("Hubo un error con la consulta\n"); pausa("Presione una tecla para volver\n"); break; case MODIFICAR: if(modificarEvento(calendario)) printf("No se pudo completar la modificacion\n"); break; case ELIMINAR: if(eliminarEvento(calendario)) printf("No fue posible eliminar el evento\n"); pausa("Presione una tecla para volver\n"); break; case EXPORTAR: if(exportarCalendario(calendario)) printf("Hubo un error al intentar exportar el calendario\n"); pausa("Presione una tecla para volver\n"); break; case LIMPIAR: if(limpiarCalendario(calendario)) printf("No se pudo completar la operacion\n"); pausa("Presione una tecla para volver\n"); break; } }while( opcion != SALIR); guardarEventosEnArchivo(calendario); limpiarMemoria(calendario); calendario->deleteArrayList(calendario); return 0; }
void thirdTestCase02(void) { int r; ArrayList* list; list = al_newArrayList(); r = al_deleteArrayList(list); utest_assertEqualsIntMsg(r,0,"Error in return value <deleteArrayList> if array pointer is valid, the correct value to return is: (0)"); if(r != 0) free(list); }
/** \brief Returns an array containing all of the elements in this list in proper sequence * \param pList ArrayList* Pointer to arrayList * \return ArrayList* Return (NULL) if Error [pList is NULL pointer] * - (New array) if Ok */ ArrayList* al_clone(ArrayList* pList) { ArrayList * aux; if(pList == NULL)return NULL; aux = al_newArrayList(); if(aux == NULL)return NULL; aux->size = pList->size; aux->reservedSize = pList->reservedSize; aux->pElements = realloc(aux->pElements,pList->reservedSize * sizeof(void*)); if(aux->pElements == NULL)return NULL; memcpy( aux->pElements , pList->pElements , pList->reservedSize * sizeof(void*)); return aux; }
/** \brief Returns a new arrayList with a portion of pList between the specified * fromIndex, inclusive, and toIndex, exclusive. * \param pList ArrayList* Pointer to arrayList * \param from int Initial index of the element (inclusive) * \param to int Final index of the element (exclusive) * \return int Return (NULL) if Error [pList is NULL pointer or invalid 'from' or invalid 'to'] * - ( pointer to new array) if Ok */ ArrayList* al_subList(ArrayList* pList,int from,int to) { ArrayList *returnAux = NULL; int i; if(pList != NULL && from >= 0 && from <= to && to <= pList->size) { returnAux = al_newArrayList(); for(i = from; i < to; i++) { returnAux->add(returnAux, *(pList->pElements + i)); } } return returnAux ; }
/** \brief Returns an array containing all of the elements in this list in proper sequence * \param pList ArrayList* Pointer to arrayList * \return ArrayList* Return (NULL) if Error [pList is NULL pointer] * - (New array) if Ok */ ArrayList* al_clone(ArrayList* pList) { ArrayList* returnAux = NULL; ArrayList* pList2=al_newArrayList(); int i; if (pList != NULL) { for (i=0; i<al_len(pList) ; i++) { al_add(pList2,pList->pElements+i); //al_add(pList2,al_get(pList(pList->pElements)+i)); } returnAux=pList2; } return returnAux; }
/** \brief Returns a new arrayList with a portion of pList between the specified * fromIndex, inclusive, and toIndex, exclusive. * \param pList ArrayList* Pointer to arrayList * \param from int Initial index of the element (inclusive) * \param to int Final index of the element (exclusive) * \return int Return (NULL) if Error [pList is NULL pointer or invalid 'from' or invalid 'to'] * - ( pointer to new array) if Ok */ ArrayList* al_subList(ArrayList* pList,int from,int to) { void* returnAux = NULL; ArrayList* subList; int i; if (pList !=NULL && from>=0 && to<=al_len(pList) && to>from ) { subList=al_newArrayList(); for (i=0; i<to - from; i++) { pList->add( subList, pList->get(pList, from+i) ); } returnAux=subList; } return returnAux ; }
void seventhTestCase02(void) { int i, r; ArrayList* list; Employee* pAux[LENGTH]; Employee* pAuxToSet; Employee* pAuxGet; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->add(list,pAux[i]); } pAuxToSet = newEmployee(id[5],unsortedList[5],unsortedList[5],salary[5],sector[5]); for(i=0; i < LENGTH; i++) { r = list->set(list,i,pAuxToSet); utest_assertEqualsIntMsg(r,0,"Error in return value <set> if ok the correct value to return is 0"); } for (i=0;i < LENGTH;i++) { pAuxGet = list->get(list,i); utest_assertEqualsIntMsg(((Employee*)pAuxGet)->id,id[5],"Error value in <.id>"); utest_assertEqualsStringMsg(((Employee*)pAuxGet)->name,unsortedList[5],2,"Error value in <.name>"); utest_assertEqualsStringMsg(((Employee*)pAuxGet)->lastName,unsortedList[5],2,"Error value in <.lastName>"); utest_assertEqualsFloatMsg(((Employee*)pAuxGet)->salary,salary[5],"Error value in <.salary>"); utest_assertEqualsIntMsg(((Employee*)pAuxGet)->sector,sector[5],"Error value in <.sector>"); utest_assertEqualsIntMsg(((Employee*)pAuxGet)->isEmpty,0,"Error value in <.isEmpty> the correct value is: (0)"); } free(list); free(pAuxToSet); for(i=0; i < LENGTH; i++) free(pAux[i]); }
/** \brief Returns a new arrayList with a portion of pList between the specified * fromIndex, inclusive, and toIndex, exclusive. * \param pList ArrayList* Pointer to arrayList * \param from int Initial index of the element (inclusive) * \param to int Final index of the element (exclusive) * \return int Return (NULL) if Error [pList is NULL pointer or invalid 'from' or invalid 'to'] * - ( pointer to new array) if Ok */ ArrayList* al_subList(ArrayList* pList,int from,int to) { void* datos; int i; ArrayList* list; list = al_newArrayList(); if(pList != NULL && from >= 0 && to <= pList->size && to > from && to > 0 && from < pList->size) { for(i=from; i<=to; i++) { datos = pList->get(pList,i); pList->add(list,datos); // *((pList->pElements)+1+i) = *((pList->pElements)+i); } } else { al_deleteArrayList(list); list=NULL; } return list; }
void twelfthTestCase04(void) { int i, r; ArrayList* list; Employee* pAux[LENGTH]; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->add(list,pAux[i]); } r = list->indexOf(list,NULL); utest_assertEqualsIntMsg(r,-1,"Error in return value <indexOf> if the pointer to Element is NULL the correct value to return is -1"); free(list); for(i=0; i < LENGTH; i++) free(pAux[i]); }
void seventeenthTestCase01(void) { int i,r; ArrayList* list; Employee* pAux[LENGTH]; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->add(list,pAux[i]); } r = list->sort(list, compareEmployee,1); utest_assertEqualsIntMsg(r, 0 ,"Error in return value of <sort> if the list is contained the correct value is 1"); free(list); for(i=0; i < LENGTH; i++) free(pAux[i]); }
void seventeenthTestCase04(void) { int i,r; ArrayList* list; Employee* pAux[LENGTH]; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->add(list,pAux[i]); } r = list->sort(list, NULL,1); utest_assertEqualsIntMsg(r, -1 ,"Error in return value of <sort> if the pointer to Function is Null the correct value is -1"); free(list); for(i=0; i < LENGTH; i++) free(pAux[i]); }
/** \brief Returns a new arrayList with a portion of pList between the specified * fromIndex, inclusive, and toIndex, exclusive. * \param pList ArrayList* Pointer to arrayList * \param from int Initial index of the element (inclusive) * \param to int Final index of the element (exclusive) * \return int Return (NULL) if Error [pList is NULL pointer or invalid 'from' or invalid 'to'] * - ( pointer to new array) if Ok */ ArrayList* al_subList(ArrayList* pList,int from,int to) { ArrayList* returnAux = NULL; int i; if(pList!=NULL && (from<to&&from>=0) && (to<=(pList->size)&& to>from)) { returnAux=al_newArrayList(); if(returnAux!=NULL) { for(i=from; i<to;i++) { returnAux->add(returnAux,pList->get(pList,i)); } } } return returnAux; }
void eighthTestCase03(void) { int i, r; ArrayList* list; Employee* pAux[LENGTH]; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->add(list,pAux[i]); } r = list->set(list,9); utest_assertEqualsIntMsg(r,-1,"Error in return value <remove> if the index is invalid the correct value to return is -1"); free(list); }
/** \brief Returns an array containing all of the elements in this list in proper sequence * \param pList ArrayList* Pointer to arrayList * \return ArrayList* Return (NULL) if Error [pList is NULL pointer] * - (New array) if Ok */ ArrayList* al_clone(ArrayList* pList) { ArrayList* returnAux = NULL; int i; if(pList!=NULL) { returnAux=al_newArrayList(); if( returnAux!=NULL) { for(i=0; i<pList->size;i++) { al_add(returnAux,pList->pElements[i]); } } } return returnAux; }
void eleventhTestCase02(void) { int i; ArrayList* list; Employee* pAux[LENGTH]; Employee* pAuxGet[LENGTH]; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->push(list,i,pAux[i]); pAuxGet[i] = list->get(list,i); utest_assertNotNullMsg(pAuxGet[i],"Error in return value <get> if ok the correct value to return is not NULL"); } for (i=0;i < LENGTH;i++) { utest_assertEqualsIntMsg(((Employee*)pAuxGet[i])->id,id[i],"Error value in <.id>"); utest_assertEqualsStringMsg(((Employee*)pAuxGet[i])->name,unsortedList[i],2,"Error value in <.name>"); utest_assertEqualsStringMsg(((Employee*)pAuxGet[i])->lastName,unsortedList[i],2,"Error value in <.lastName>"); utest_assertEqualsFloatMsg(((Employee*)pAuxGet[i])->salary,salary[i],"Error value in <.salary>"); utest_assertEqualsIntMsg(((Employee*)pAuxGet[i])->sector,sector[i],"Error value in <.sector>"); utest_assertEqualsIntMsg(((Employee*)pAuxGet[i])->isEmpty,0,"Error value in <.isEmpty> the correct value is: (0)"); } free(list); for(i=0; i < LENGTH; i++) free(pAux[i]); }
int main() { int r,i; int *auxInt = malloc(sizeof(int)); float *auxFloat = malloc(sizeof(float)); int *auxIndex = malloc(sizeof(int)); int choice; Employee *pEmployee = malloc(sizeof(Employee)); Employee *pEmployee2 = malloc(sizeof(Employee)); ArrayList *nomina; ArrayList *nominaCloned; ArrayList *nominaFilter; nomina = al_newArrayList(); r = importFile(nomina,"Nomina.txt"); do { choice = menu("\n*************** TP 4 - CANEPA ***************\n\n" "1- Agregar empleado\n2- Modificar empleado\n" "3- Borrar empleado\n4- Listar\n" "5- PUSH empleado\n6- Listar por salario\n" "7- Listar por Nombre\n8- Filtrar salarios\n" "9- Borrar todos\n10- Guardar y Salir\n"); switch(choice) { case 1: system("cls"); pEmployee = newEmployee(); pEmployee2 = searchEmployee(nomina,auxIndex,pEmployee->id); if(pEmployee2 == NULL) { nomina->add(nomina,pEmployee); } else { printf("Error. El legajo ya existe."); printEmployee(pEmployee2,*auxIndex); } r = nomina->len(nomina); printf("Cantidad de empleados: %d\n\n",r); system("pause"); break; case 2: system("cls"); if(nomina->isEmpty(nomina) != 0) { printf("Error. Primero ingrese empleados."); break; } getInt(auxInt,"Ingrese el legajo a editar: ","ERROR",1, 99999999); pEmployee = searchEmployee(nomina,auxIndex,*auxInt); if(pEmployee == NULL) { printf("El legajo no existe."); } else { pEmployee2 = editEmployee(pEmployee); printf("Valor Original:\nPosicion: %d\tLegajo: %d\tNombre:%s\tSalario:%.2f\tSector: %d\n\n",*auxIndex,pEmployee->id,pEmployee->name,pEmployee->salary,pEmployee->sector); printf("Nuevo valor: \nPosicion: %d\tLegajo: %d\tNombre:%s\tSalario:%.2f\tSector: %d\n\n",*auxIndex,pEmployee2->id,pEmployee2->name,pEmployee2->salary,pEmployee2->sector); if(validaDecision("Confirma modificacion? S/N ")==0) nomina->set(nomina,*auxIndex,pEmployee2); } system("pause"); break; case 3: system("cls"); if(nomina->isEmpty(nomina) != 0) { printf("Error. Primero ingrese empleados."); break; } getInt(auxInt,"Ingrese el legajo a eliminar: ","ERROR",1, 99999999); pEmployee = searchEmployee(nomina,auxIndex,*auxInt); if(pEmployee == NULL) { printf("El legajo no existe."); } else { printf("Se eliminira:\nPosicion: %d\tLegajo: %d\tNombre:%s\tSalario:%.2f\tSector: %d\n\n",*auxIndex,pEmployee->id,pEmployee->name,pEmployee->salary,pEmployee->sector); if(validaDecision("Confirma eliminacion? S/N ")==0) nomina->pop(nomina,*auxIndex); } r = nomina->len(nomina); printf("Cantidad de empleados: %d\n\n",r); system("pause"); break; case 4: system("cls"); if(nomina->isEmpty(nomina) != 0) { printf("Error. Primero ingrese empleados."); break; } Employee *pEmployeeOr = malloc(sizeof(Employee)); for(i=0;i<nomina->size;i++) { pEmployeeOr = nomina->get(nomina,i); printEmployee(pEmployeeOr,i); } r = nomina->len(nomina); printf("Cantidad de empleados: %d\n\n",r); system("pause"); break; case 5: system("cls"); if(nomina->isEmpty(nomina) != 0) { printf("Error. Primero ingrese empleados."); break; } pEmployee = newEmployee(); getInt(auxInt,"\nIngrese la posicion donde desea ingresar: ","ERROR",0, nomina->size); nomina->push(nomina,*auxInt,pEmployee); r = nomina->len(nomina); printf("\nCantidad de empleados: %d\n\n",r); system("pause"); break; case 6: system("cls"); if(nomina->isEmpty(nomina) != 0) { printf("Error. Primero ingrese empleados."); break; } getInt(auxInt,"\n1: Ascendente\n0: Descendente\n\nElija el orden: ","ERROR",0, 1); nominaCloned = nomina->clone(nomina); r = nomina->containsAll(nomina,nominaCloned); if(r != 0) { for(i=0;i<nominaCloned->size;i++) { pEmployee = nominaCloned->get(nominaCloned,i); printEmployee(pEmployee,i); } } r = nomina->len(nomina); printf("Cantidad de empleados: %d\n\n",r); system("pause"); nominaCloned->deleteArrayList(nominaCloned); break; case 7: system("cls"); if(nomina->isEmpty(nomina) != 0) { printf("Error. Primero ingrese empleados."); break; } getInt(auxInt,"\n1: Ascendente\n0: Descendente\n\nElija el orden: ","ERROR",0, 1); nominaCloned = nomina->clone(nomina); r = nominaCloned->sort(nominaCloned,compareEmployeeName,*auxInt); r = nomina->containsAll(nomina,nominaCloned); if(r != 0) { for(i=0;i<nominaCloned->size;i++) { pEmployee = nominaCloned->get(nominaCloned,i); printEmployee(pEmployee,i); } } r = nomina->len(nomina); printf("Cantidad de empleados: %d\n\n",r); system("pause"); nominaCloned->deleteArrayList(nominaCloned); break; case 8: system("cls"); if(nomina->isEmpty(nomina) != 0) { printf("Error. Primero ingrese empleados."); break; } getFloat(auxFloat,"\nSalarios mayores a:","ERROR",1, 99999999); nominaCloned = nomina->clone(nomina); nominaCloned->sort(nominaCloned,compareEmployee,0); //sort descendente por salario r = nomina->containsAll(nomina,nominaCloned); *auxInt = -1; if(r != 0) { for(i=0;i<nominaCloned->size;i++) { pEmployee = nominaCloned->get(nominaCloned,i); if(pEmployee->salary >= *auxFloat) { *auxInt = i; } } } if(*auxInt >= 0) { nominaFilter = nominaCloned->subList(nominaCloned,0,*auxInt); for(i=0;i<nominaFilter->size;i++) { pEmployee = nominaFilter->get(nominaFilter,i); printEmployee(pEmployee,i); } } r = nominaFilter->len(nominaFilter); printf("Cantidad de empleados con salario mayor a %.2f: %d\n\n",*auxFloat,r); system("pause"); nominaCloned->deleteArrayList(nominaCloned); nominaFilter->deleteArrayList(nominaFilter); break; case 9: system("cls"); if(nomina->isEmpty(nomina) != 0) { printf("Error. Primero ingrese empleados."); break; } nomina->clear(nomina); system("pause"); break; case 10: system("cls"); createTxt(nomina); nomina->deleteArrayList(nomina); break; default: system("cls"); printf("\nOpcion invalida. Reingrese.\n"); system("pause"); break; } system("cls"); } while (choice != 10); return 0; }
int run2(void) { // Genero personas para usar en el ArrayList Employee* p0 = newEmployee(14, "JUAN1" ,"LOPEZ", 133.22,5); Employee* p1 = newEmployee(14, "JUAN2" ,"LOPEZ", 233.22,5); Employee* p2 = newEmployee(14, "JUAN3" ,"LOPEZ", 333.22,5); Employee* p3 = newEmployee(14, "JUAN4" ,"LOPEZ", 433.22,5); printEmployee(p0); printEmployee(p1); printEmployee(p2); printEmployee(p3); //__________________________________________ printf("\r\nCargo ArraList...\r\n"); ArrayList* lista = al_newArrayList(); lista->add(lista,p0); lista->add(lista,p1); lista->add(lista,p2); al_add(lista,p3); // forma no orientada a objetos printArrayListEmployee(lista); printf("\r\nRemuevo index 2\r\n"); lista->remove(lista,2); printArrayListEmployee(lista); printf("\r\nContiene p0 ?\r\n"); if(lista->contains(lista,p0)) printf("SI"); else printf("NO"); printf("\r\nContiene p2 ?\r\n"); if(lista->contains(lista,p2)) printf("SI"); else printf("NO"); printf("\r\nAgrego p2 en la posicion 1\r\n"); lista->set(lista,1,p2); // vuelvo a agregar p2 printArrayListEmployee(lista); printf("\r\nClonamos array\r\n"); ArrayList* lista2 = lista->clone(lista); printf("Lista original:%p\r\n",lista); printArrayListEmployee(lista); printf("Lista Clonada:%p\r\n",lista2); printArrayListEmployee(lista2); lista2->sort(lista2, compareEmployee,1); printf("Lista Clonada Ordenada por Edad (UP):%p\r\n",lista2); printArrayListEmployee(lista2); lista2->sort(lista2, compareEmployee,0); printf("Lista Clonada Ordenada por Edad (DOWN):%p\r\n",lista2); printArrayListEmployee(lista); printf("\r\nlista clonada contiene lista?:"); if(lista->containsAll(lista,lista2)) printf("SI"); else printf("NO"); printf("\r\n\r\nPosicion de p2:"); int index = lista->indexOf(lista,p2); printf("%d\r\n",index); printf("\r\nPosicion de p1:"); index = lista->indexOf(lista,p1); printf("%d\r\n",index); printf("\r\n\r\nHacemos push de p1 en la posicion 1\r\n"); lista->push(lista,1,p1); printArrayListEmployee(lista); printf("\r\nObtenemos sub-lista de 1 a 2\r\n"); ArrayList* subLista = lista->subList(lista,1,2); printArrayListEmployee(subLista); printf("\r\n\r\nHacemos pop de p1 en la posicion 1\r\n"); Employee* p1Aux = lista->pop(lista,1); printf("Elemento pop(): %s\r\n",p1Aux->name); printArrayListEmployee(lista); printf("\r\nClear array\r\n"); lista->clear(lista); printArrayListEmployee(lista); printf("\r\nEsta vacio?\r\n"); if(lista->isEmpty(lista)) printf("SI"); else printf("NO"); // Test expansion/contraccion del size printf("\r\n\r\nTest size\r\n"); int j; for(j=0; j<1100; j++) { Employee* pAux = malloc(sizeof(Employee)); sprintf(pAux->name,"Juan %d",j); pAux->salary=j; lista->add(lista,pAux); } printf("Cantidad de elementos:%d\r\n",lista->len(lista)); //printArrayListPersonas(lista); for(j=0; j<1100; j++) { lista->pop(lista,0); } printf("Cantidad de elementos:%d\r\n",lista->len(lista)); //printArrayListPersonas(lista); //____________________________________ printf("\r\nLibero memoria y termino\r\n"); free(p0); free(p1); free(p2); free(p3); lista->deleteArrayList(lista); lista2->deleteArrayList(lista2); system("PAUSE"); return 0; }
int main() { ArrayList* arrayListC=al_newArrayList(); ArrayList* DeleteHistory=al_newArrayList(); ArrayList* Backup=al_newArrayList(); eEmployee* employeeAux; int id=0; int auxInt; int option; char continueDo='s'; // loadCant(arrayListC); loadFile(arrayListC,"Nomina.dat"); loadFile(DeleteHistory,"Exempl.dat"); // loader(arrayListC); do { getInt(&option,"######CASO DE USO ARRAYLIST###\n\n1-Agregar un empleado\n2-Modificar empleado\n3-Eliminar empleado" "\n4-Tamaño de la nomina\n5-Informes\n6-Salir" "\n10-Salir\noption:","Opcion no valida\n",1,8); switch(option) { case 1: employeeAux=loadEmployee(arrayListC); auxInt=findByName(DeleteHistory,employeeAux->name,employeeAux->lastName); if(auxInt==-1) { id++; if(al_add(arrayListC,(void*)employeeAux)) { id--; } } else { getInt(&option,"\nEl empleado ya pertenecia a la empresa, desea agregarlo nuevamente?? \n1-Si\n2-No","Error opcion no valida",1,2); switch(option) { case 1: employeeAux=(ArrayList*)arrayListC->get(DeleteHistory,auxInt); al_push(arrayListC,(employeeAux->id-1),(void*)employeeAux); al_remove(DeleteHistory,auxInt); break; case 2: id++; if(al_add(arrayListC,(void*)employeeAux)) { id--; } } break; } break; case 2: modifyEmployee(arrayListC); break; case 3: deleteEmployee(arrayListC,DeleteHistory); break; case 4: printf("\n\n@@@@@@@@ HISTORIAL @@@@@@@\n\n"); PrintEmployees(DeleteHistory); break; case 5: informes(arrayListC); break; case 6: continueDo='n'; saveToFileActive(arrayListC,"Nomina.dat"); saveToFileActive(DeleteHistory,"Exempl.dat"); break; case 7: break; case 8: al_push(arrayListC,2,loadEmployee(arrayListC)); break; default: break; } } while(continueDo!='n'); // saveCant(arrayListC); return 0; }
int main() { ArrayList* lista = al_newArrayList(); ArrayList* repetidos = al_newArrayList(); ArrayList* depurados = al_newArrayList(); int opcion; char string[20]; do { printf("MENU:\n"); printf("1.-Parsear\n"); printf("2.-Completar\n"); printf("3.-Listar\n"); printf("4.-Guardar\n"); printf("5.-Salir\n"); scanf("%d", &opcion); system("cls"); switch(opcion) { case 1: lectura(lista); imprimirTodos(lista); break; case 2: completarLetra(lista); imprimirTodos(lista); break; case 3: printf("Ingrese una palabra: "); fflush(stdin); fgets(string, 20, stdin); filtrarRepetidos(lista, repetidos, string); repetidos->sort(repetidos, comparar, 1); imprimirTodos(repetidos); getchar(); filtrarDepurados(lista, depurados, string); depurados->sort(depurados, comparar, 0); imprimirTodos(depurados); break; case 4: escritura(lista, "completo.csv"); escritura(repetidos, "repetidos.csv"); escritura(depurados, "depurados.csv"); break; case 5: printf("Programa finalizado\n"); break; default: printf("Opcion invalida\n"); break; } } while(opcion != 5); return 0; }