Professional Documents
Culture Documents
INGENIERÍA MECATRÓNICA
FUNDAMENTOS DE PROGRAMACIÓN
NRC - 4091
// Definicion de tipos:
typedef struct {
char cedula[11];
char nombre[50];
float nota1, nota2, nota3;
} Elemento;
// Prototipos:
int LeerNomina(TArrEst);
void EscribirNomina(TArrEst, int, char *);
void Ordenar(TArrEst, int, TORDEN, int);
int Comparar(int, Elemento *, Elemento *);
int Ascendente(int, Elemento *, Elemento *);
int Descendente(int, Elemento *, Elemento *);
int Leer(Elemento **, int);
void Mostrar(Elemento *);
void LiberarNomina(TArrEst, int);
// DEFINICION DE FUNCIONES:
int main()
{
TArrEst A;
int tl = LeerNomina(A);
EscribirNomina(A, tl, "NOMINA INGRESADA:");
Ordenar(A, tl, Ascendente, 0);
EscribirNomina(A, tl, "NOMINA ORDENADA ASCENDENTEMENTE POR CEDULA:");
Ordenar(A, tl, Descendente, 0);
EscribirNomina(A, tl, "NOMINA ORDENADA DESCENDENTEMENTE POR CEDULA:");
Ordenar(A, tl, Ascendente, 1);
EscribirNomina(A, tl, "NOMINA ORDENADA ASCENDENTEMENTE POR NOMBRE:");
Ordenar(A, tl, Descendente, 1);
EscribirNomina(A, tl, "NOMINA ORDENADA DESCENDENTEMENTE POR NOMBRE:");
LiberarNomina(A, tl);
return 0;
}
int LeerNomina(TArrEst X) {
int n;
printf("INGRESAR LA NOMINA DE ESTUDIANTES: \n");
for (n = 0; n < TMAX; n ++) {
X[n] = new Elemento;
if (!Leer(&X[n], n)) return n;
}
return n;
}
void EscribirNomina(TArrEst X, int n, char *ms) {
int i;
printf("%s\n", ms);
printf("CEDULA NOMBRE NOTA1 NOTA2 NOTA3 PROMEDIO OBSERVACION\n");
for (i = 0; i < n; i++)
Mostrar(X[i]);
printf("\n");
}
void Ordenar(TArrEst X, int n, TORDEN O, int cn) {
Elemento *aux;
int i, j;
for (i = 0; i < n - 1; i ++)
for (j = i + 1; j < n; j ++)
if (!(*O)(cn, X[i], X[j])) {
// if (Comparar(cn, X[i], X[j]) > 0) {
aux = X[i];
X[i] = X[j];
X[j] = aux;
}
}
int Comparar(int cn, Elemento *x, Elemento *y) {
if (cn == 0)
return strcmpi(x->cedula, y->cedula);
return strcmpi(x->nombre, y->nombre);
}
int Ascendente(int cn, Elemento *x, Elemento *y) {
return Comparar(cn, x, y) <= 0;
}
int Descendente(int cn, Elemento *x, Elemento *y) {
return Comparar(cn, x, y) >= 0;
}
RESULTADOS DE LA CORRIDA: