#include <stdio.h>
#include<string.h>
#define fil_max 30
#define col 100
int cont=0;
void baja(char mat[fil_max][col], int nota[fil_max]);
void lista(char mat[fil_max][col], int nota[fil_max]);
void modi(char mat[fil_max][col], int nota[fil_max]);
void consul(char mat[fil_max][col], int nota[fil_max]);
void leer(char mat[fil_max][col], int nota[fil_max]);
int main()
{
int num, nota[fil_max],x;
char mat[fil_max][col];
for(x=0;x<fil_max;x++)
{
nota[x]=-1;
}
do
{
printf("\n\nTeclee la opcion que desea ejecutar:\n");
printf("1.Introducir alumnos\n");
printf("2.Consultar alumno\n");
printf("3.Modificar nota\n");
printf("4.Listados\n");
printf("5.Dar de baja alumno\n");
printf("6.Salir del programa\n");
scanf("%d", &num);
switch(num)
{
case 1:
leer(mat, nota);
break;
case 2:
consul(mat, nota);
break;
case 3:
modi(mat, nota);
break;
case 4:
lista(mat, nota);
break;
case 5:
baja(mat, nota);
break;
}
} while (num!=6);
return 0;
}
void leer(char mat[fil_max][col], int nota[fil_max])
{
char resp;
do
{
printf("\nIntroduzca nombre y apellidos del alumno:\n");
fflush(stdin);
gets(mat[cont]);
printf("\nIntroduzca la nota del alumno:\n");
scanf("%d", ¬a[cont]);
cont++;
if(cont==30)
{
printf("Ya has introducido 30 alumnos");
break;
}
else
printf("\nDesea introducir otro?\n");
fflush(stdin);
scanf("%c",&resp);
}
while(resp=='s');
}
void consul(char mat[fil_max][col], int nota[fil_max])
{
int num2, notax, f,x,a=0;
char alumaux[col];
printf("Elija opcion:\n");
printf("1.Por alumno\n");
printf("2.Por nota\n");
scanf("%d", &num2);
switch(num2)
{
case 1:
printf("Introduce el nombre completo del alumno:\n");
fflush(stdin);
gets(alumaux);
for(f=0;f<fil_max;f++)
{
if (strcmp(mat[f],alumaux)==0)
{
printf("La nota del alumno %s, es de %d\n\n\n", mat[f],nota[f]);
a=1;
break;
}
}
if (a==0)
printf("El alumno no esta\n\n\n");
break;
case 2 :
printf("Introduce la nota a buscar:\n");
scanf("%d", ¬ax);
a=0;
for(x=0;x<fil_max;x++)
{
if(nota[x]==notax)
{
printf("\n La nota de %d pertenece a %s\n\n\n\n", notax,mat[x]);
a=1;
}
}
if(a==0)
{
printf("\nNingun alumno tiene esa nota\n\n");
}
break;
}
}
void modi(char mat[fil_max][col], int nota[fil_max])
{
char modiaux[col], contes,f,a=0;
printf("¿A que alumno desea modificarle la nota?\n");
fflush(stdin);
gets(modiaux);
for(f=0;f<fil_max;f++)
{
if (strcmp(mat[f],modiaux)==0)
{
printf("La nota del alumno %s, es de %d\n\n\n", mat[f],nota[f]);
a=1;
printf("\n¿Desea modificar la nota de este alumno?\n");
scanf("%c", &contes);
if(contes=='s')
{
printf("\nIntroduzca la nueva nota:\n");
scanf("%d", ¬a[f]);
break;
}
}
}
if (a==0)
printf("El alumno no esta\n\n\n");
}
void lista(char mat[fil_max][col], int nota[fil_max])
{
int num3,f,j,i,t, notaaux;
char nombreAux[col];
printf("Elija opcion\n\n");
printf("1.Aprobados\n");
printf("2.Suspensos\n");
printf("3.Todos\n");
printf("4.Todos ordenados alfabeticamente\n");
scanf("%d", &num3);
switch(num3)
{
case 1:
printf("\n\nLISTA DE ALUMNOS APROBADOS\n\n");
for(f=0;f<cont;f++)
{
if (nota[f]>=5)
{
printf("\n%s\n",mat[f]);
}
}
break;
case 2:
printf("\n\nLISTA DE ALUMNOS SUSPENSOS\n\n");
for(t=0;t<cont;t++)
{
if(nota[t]<5 && nota[t]>=0)
{
printf("\n%s\n", mat[t]);
}
}
break;
case 3:
printf("\n\nLISTA DE TODOS LOS ALUMNOS\n\n");
for(f=0;f<cont;f++)
{
if(nota[f]>=0)
printf("\n%s\n", mat[f]);
}
break;
case 4:
printf("\n\nLISTA DE TODOS LOS ALUMNOS ORDENADOS ALFABETICAMENTE\n\n");
for(j=1;j<cont;j++)
{
for(f=0;f<cont-j;f++)
{
if(strcmp (mat[f], mat[f+1])>0)
{
strcpy(nombreAux, mat[f+1]);
strcpy(mat [f+1], mat[f]);
strcpy(mat[f],nombreAux);
notaaux=nota[f+1];
nota[f+1]=nota[f];
nota[f]=notaaux;
}
}
}
for(i=0;i<cont;i++)
{
if(nota[i]>=0)
printf("%s\n", mat[i]);
}
break;
}
}
void baja(char mat[fil_max][col], int nota[fil_max])
{
int j,f;
char alumaux2[col];
printf("\nIntroduce el nombre del alumno que desea dar de baja:\n");
fflush(stdin);
gets(alumaux2);
for(f=0;f<cont;f++)
{
if (strcmp(mat[f],alumaux2)==0)
{
for(j=f;j<cont-1;j++)
{
strcpy(mat[j],mat[j+1]);
nota[j]=nota[j+1];
}
cont=cont-1;
}
}
}
Comentarios sobre la versión: 20071119 (0)
No hay comentarios