// PREGUNTA 1 #include void f1(int *i,int j); void f2(int a,int *b); void f3(int *v,int *w); main() { int x,y,z; x=11; y=-1; z=20; f2(z,&y); f3(&x,&y); printf("%d %d %d \n", x, y, z); } void f1 (int *i,int j) { (*i)++; printf("%d %d \n", *i, j); } void f2 (int a,int *b) { int c; c = *b + 1; f1 (&c, a); printf("%d %d %d \n",a,*b,c); } void f3 (int *v,int *w) { ++(*v); *w = (*v) * 2; } // Salida // 1 20 // 20 -1 1 // 12 24 20 // PREGUNTA 2 #include typedef struct { char nombre[16], apellido[16], pais[11]; int edad, goles; } JUGADOR; int main() { FILE *fpJugador, *fpNovato; // (1 pto) JUGADOR J; fpJugador = fopen("jugador.txt", "r"); // (1 pto) fpNovato = fopen("novatos.txt", "w"); // (1 pto) if (fpJugador == NULL) { printf("ERROR: No se pudo abrir el archivo jugador.txt\n"); return 0; } if (fpNovato == NULL) { printf("ERROR: No se pudo crear el archivo Novato.txt\n"); fclose(fpJugador); // (1 pto) return 0; } else { while (!feof(fpJugador)) { // (1 pto) fscanf(fpJugador, "%s %s %d %s %d", J.nombre, J.apellido, J.edad, J.pais, J.goles); // (1 pto) printf("%s %s %d %s %d\n", J.nombre, J.apellido, J.edad, J.pais, J.goles); // (1 pto) if (J.edad < 25) { // (1 pto) fprintf(fpNovato, "%s %s %d %s %d\n", J.nombre, J.apellido, J.edad, J.pais, J.goles); // (1 pto) } } fclose(fpJugador); // (0.5 ptos) fclose(fpNovato); // (0.5 ptos) } } // PREGUNTA 3 int MaxMatriz( int mat[M][N], int mdim, int ndim, int * fmax, int * cmax) // (2 ptos) // PRE: (1 pto) 0 <= mdim < M y 0 <= ndim < N // POST: (1 pto) La función devuelve el valor máximo almacenado // en ella. (fmax, cmax) es la posición del máximo en la matriz { int max; int i,j; max = mat[0][0]; // (1 pto), tambien vale max = -MAXINT *fmax = 0; *cmax = 0; for (i = 0; i < mdim; i++) { // (1 pto) for (j = 0; j < ndim; j++) { // (1 pto) if ( max < mat[i][j]) { // (1 pto) max = mat[i][j]; // (1 pto) *fmax = i; // (1 pto) *cmax = j; // (1 pto) } } } return( max ); // (1 pto) } // Suponga que se desea construir el programa principal que invoca dicha función para ello se realizan las siguientes declaraciones: #define M 20 // Indican las dimensiones máximas de la matriz #define N 15 int matriz[M][N]; // La matriz int m,n; // Las dimensiones actuales int maximo; // Almacenará el valor máximo de la matriz int f,c; // Indicarán la posición f,c del máximo maximo = MaxMatriz(matriz, m ,n, &f, &c); /* PREGUNTA OPCIONAL (3 ptos): Suponga que se quiere ampliar la información de los escudos del planeta Arkynlot (proyecto de laboratorio). Además de la posición del escudo se requiere el tamaño del mismo (metros que protege), la resistencia (desvanecimiento inmediato, desvanecimiento desvanecimiento retardado), y el tipo de escudo (magnético, titanium, platinum, laser). Defina un tipo de datos (typedef ) que permita representar los diferentes tipos de escudos. Defina un tipo de datos que permita representar la estructura de un escudo. Escriba la declaración de un arreglo que permita almacenar los escudos de una batalla. */ typedef enum {INMEDIATO, RETARDADO} Resistencia; typedef enum {MAGNETICO, TITANIUM, PLATINUM, LASER} TipoMaterial; typedef struct { int Posicion; int Tamanyo; Resistencia Desvanecimiento; TipoMaterial ClaseEscudo; } Escudo; Escudo MisEscudos[MAX];