int main() { printf("Starting program stest.\n"); #ifdef DEBUG printf("DEBUG defined\n"); #else printf("Not defined\n"); #endif //--------------------Creating and Printing Employee-------------------------- Employee* tri; Employee* jetro; tri = createEmployee(20000, "Tri", "Robotics"); jetro = createEmployee(20000,"Jetro", "Electrical"); // Anybody recognize these names? Employee harry; // Declare a local variable (a struct). harry.salary = 5000; harry.name = strdup("Harry Palmer"); // Make a dynamic copy. harry.dept = strdup("Mechanical"); Employee bluejay; // Declare a local variable (a struct). bluejay.salary = 10000; bluejay.name = strdup("Erik Grantby"); // Make a dynamic copy. bluejay.dept = strdup("Computer Science"); // Output the employees to stdout. printEmployee(&harry); printEmployee(&bluejay); printEmployee(tri); printEmployee(jetro); //---------------------Ending Employee--------------------- //---------------------Getting Employee's Info From Prompts------------------------- getEmployeeInfo(100, 100, 100); //---------------------End Prompts------------------------- //Output the employees to a file. printf("About to write to file.\n"); FILE *outfile; outfile = fopen("stest.txt", "w"); // Open or create file for writing if(outfile != '\0'){// check if outfile can be opened printf("outfile opened sucessfull\n");// prompt succes // write the data to outfile outputEmployee(outfile, &harry); outputEmployee(outfile, &bluejay); outputEmployee(outfile, tri); outputEmployee(outfile, jetro); fclose(outfile);// close outfile } else{ fprintf(stderr, "Uh-oh!\n");//print error if file can't be opened } printf("Ending program stest.\n"); return 0; }
/** * main function * @return 0 indicating success, 1 indicating file not opened successfully */ int main() { printf("\nStarting program stest.\n\n"); // Anybody recognize these names? Employee harry; // Declare a local variable (a struct). harry.salary = 5000; harry.name = strdup("Harry Palmer"); // Make a dynamic copy. harry.dept = strdup("MI6"); // Make a dynamic copy. Employee bluejay; // Declare a local variable (a struct). bluejay.salary = 10000; bluejay.name = strdup("Erik Grantby"); // Make a dynamic copy. bluejay.dept = strdup("KGB"); // Make a dynamic copy. //Creating employees dynamically using function makeEmployee Employee* jason = makeEmployee(10000, "Jason Bourne", "CIA"); int temp_salary = 1000; char *temp_name = "Carlos the Jackal"; char *temp_dept = "Novgorod"; Employee* carlos = makeEmployee(temp_salary, temp_name, temp_dept); Employee* user_emp1 = inputEmployee(); // Output the employees to stdout. printEmployee(&harry); printEmployee(&bluejay); printEmployee(jason); printEmployee(carlos); printEmployee(user_emp1); // Output the employees to a file. printf("\nAbout to write to file.\n"); FILE *outfile = fopen("stest.txt", "w"); // Open or create file for writing if(outfile == NULL){ fprintf(stderr, "Whoops! stest had error number %d - %s\n", errno, strerror(errno)); return 1; } outputEmployee(outfile, &harry); outputEmployee(outfile, &bluejay); outputEmployee(outfile, jason); outputEmployee(outfile, carlos); outputEmployee(outfile, user_emp1); fclose(outfile); // Close the file printf("\nEnding program stest.\n"); debug_def_checker(); return 0; }
int main() { struct Employee* emps[MAXEMPS]; struct Employee* p; int i, nemps = 0; emps[nemps++] = createEmployee("Mantle", "Mickey", "Outfielder", 58); emps[nemps++] = createEmployee("Maris", "Roger", "Shortstop", 60); if (emps[nemps-1]->salary != 61) emps[nemps-1]->salary = 61; p = createEmployee("", "", "", 0); setLast(p, "Kaline"); setFirst(p, "Al"); setTitle(p, "Outfielder"); setSalary(p, 52); emps[nemps++] = p; for (i = 0; i < nemps; ++i) { printEmployee(emps[i]); putchar('\n'); free(emps[i]); } return 0; }
int main() {//really just calls the functions int printed = 0; openFile(); printed = printEmployee(first); return 0; }
int modifyEmployee(ArrayList* pList) { int i; int retorno=-1; int option; char auxname[20]; char auxAuxName[20]; char* auxLastName; float auxSalary; eEmployee* AuxEmployee; int auxId; if(pList!=NULL) { if(!getInt(&auxId,"Ingrese el legajo del empleado:","Error",1,pList->size)) { for(i=0;i<pList->size;i++) { AuxEmployee=*((pList->pElements)+i); if(AuxEmployee->id==auxId) { do { getInt(&option,"\n1-Cambiar nombre\n2-Cambiar apellido\n3-Cambiar salario\n4-Salir","Opcion no valida",1,4); switch(option) { case 1: fflush(stdin); if(-1!=getString(auxname,"Ingrese el nombre: ",1,20)) { printEmployee(AuxEmployee); printf("%s",&auxname); strcpy(AuxEmployee->name,auxname); } break; case 2: fflush(stdin); if(-1!=getString(auxLastName,"Ingrese el apellido: ",1,20)) { strcpy(AuxEmployee->lastName,auxLastName); } break; case 3: printf("Ingrese el salario:"); if(!scanf("%f",&auxSalary)) { AuxEmployee->salary=auxSalary; } } }while (option!=4); retorno=0; } } } } }
void printArrayListEmployee(ArrayList* lista) { int i=0; for(i=0;i<lista->len(lista);i++) { Employee* pAux = lista->get(lista,i); printf("%d) ",i); printEmployee(pAux); } }
/** \brief imprime una array de empleados dentro de una arraylist * * \param list ArrayList* arraylist a recorrer * \return int -1 si la lista es null y 0 si no lo es * */ int PrintEmployees(ArrayList* list) { int returnAux=-1; int i; eEmployee* Aux; if(list!=NULL) { for(i=0; i<list->size; i++) { // Aux=*((list->pElements)+i); /**NO PUEDO VER EL ULTIMO EMPLEADO HAY ALGO MAL EN EL PUSH**/ printEmployee(*((list->pElements)+i)); // printf("%x Puntero ",*((list->pElements)+i)); } returnAux=0; } return returnAux; }
void printArrayListEmployee(ArrayList* lista) { int i; Employee* aux; if (lista!=NULL && lista->size >0) { for (i=0;i< lista->len(lista);i++) { aux=(Employee*) al_get(lista, i); printEmployee(aux); } } else { printf("NO ESTA\n"); } }
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() { 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 main() { #ifdef DEBUG printf("\nNow in Debug Mode.\n\n"); #endif printf("Starting program emptest.\n"); int i = 0; /* loop counter */ char* ent; /* store the # of entries, type char */ int entries; /* store the number of employee entries needed */ /* read the user input and store into local var */ ent = readline("Number of employee entries needed: "); entries = atoi(ent); /* convert the string into an integer */ /* allocate an array of pointers to Employees with appropriate size */ Employee** emp = calloc(entries, sizeof(Employee*)); Employee** emp2 = emp; Employee** emp3 = emp; Employee** emp4 = emp; /* fill the array with ptrs to Employee structs until # entries is reached */ while( i < entries ) { *(emp2++) = userEmployee(); i++; } /* end while */ int j = 0; /* loop counter */ /* print each struct in the array */ while( j < entries ) { printEmployee(*(emp3++)); j++; } /* end while */ /* output the employees to a file */ printf("About to write to file.\n"); int k = 0; /* loop counter */ FILE* ofile; /* check if opening the file was sucessful */ if( fopen("emptest.txt", "w") != NULL ) { ofile = fopen("emptest.txt", "w"); /* open file if suecessful */ /* out each employee to the file */ while( k < entries ) { outEmployee(ofile, *(emp4++)); k++; } /* end while */ } /* end if */ /* if unable to open file, or error occurs, print errors to stderr */ else { fprintf(stderr, "\nError: unable to open file in program stest.\n"); fprintf(stderr, "Error Number: %d, Information: %s, ", errno, strerror( errno )); } /* end else */ fclose(ofile); /* close the file */ free_array(emp, entries); printf("Ending program emptest.\n"); return 0; /* sucessful termination */ } /* end function main */
void Programmer::printProgrammer(){ printEmployee(); printFields(); }
/** Prints all the Employee structures defined in an array of pointers to structures * @param employeePtrArray The array of pointers to structs to dereference and print * @param count Number of elements in the array *@author Steven Kordell */ void printEmployeeArray(Employee** employeePtrArray, int count) { int i; //An iterator for looping through the array for(i = 0; i < count; i++) { //iterate over the array printEmployee(employeePtrArray[i]); //print the struct } }