You are on page 1of 5

PREGRADO SI MRZ19 - JUL19

INGENIERÍA MECATRÓNICA

FUNDAMENTOS DE PROGRAMACIÓN

NRC - 4091

Corrección Del Ejercicio


Nombres:
Camacho Jibaja Carlos Fernando
Guachamín Taboada Pablo Andrés
Guerrero Merino Joe Alexander

Docente: Ing. Fausto Meneses


CALIFICACIONES:

1.- PROGRAMA EN LENGUAJE C ++:


// Calificaciones2
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TMAX 50

// Definicion de tipos:
typedef struct {
char cedula[11];
char nombre[50];
float nota1, nota2, nota3;
} Elemento;

typedef Elemento *TArrEst[TMAX];

typedef int (*TORDEN)(int, Elemento *, 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;
}

int Leer(Elemento **x, int ind) {


char cad[50];
printf("ALUMNO[%d], cedula (salir = NULA): ", ind);
gets(cad);
if (strlen(cad) == 0) return 0;
strcpy((*x)->cedula, cad);
printf("nombre (salir = NULO): ");
gets(cad);
if (strlen(cad) == 0) return 0;
strcpy((*x)->nombre, cad);
printf("notas de los 3 parciales: ");
scanf("%f %f %f", &(*x)->nota1, &(*x)->nota2, &(*x)->nota3);
// Limpiar el buffer:
getchar();
return 1;
}
void Mostrar(Elemento *x) {
float prom = (x->nota1 + x->nota2 + x->nota3) / 3;
printf("%s %s %f %f %f %f %s\n", x->cedula, x->nombre, x->nota1, x->nota2,
x->nota3, prom, (prom < 14 ? "REPRUEBA" : "APRUEBA"));
}

void LiberarNomina(TArrEst X, int n) {


int i;
for (i = 0; i < n; i ++) {
delete X[i];
}
}

RESULTADOS DE LA CORRIDA:

You might also like