#include<conio.h>
#include<stdio.h>
#include<string.h>
struct estudiantes
{
int codigo;
char nombre[50];
char apellido[50];
char materia[50];
int curso;
int dia;
int mes;
int año;
float nota1;
float nota2;
float promedio;
char estado;
};//Fin de la estructura_estudiantes
char *password();
void validar();
void menu();
void ingresar();
void modificar();
void modi_materia();
void modi_curso();
void modi_nota();
void eliminar();
void consultar();
void lista_general();
void lista_nombre();
void lista_materia();
void lista_aprobados();
void lista_reprobados();
int valida(int, int, int);
int op, res, valor=0;
FILE *ptr;
struct estudiantes est;
long tam=sizeof(struct estudiantes);
void main()
{
clrscr();validar();
menu();
getch();
}
void menu()
{
op=0;
clrscr();
do
{
printf("\n\n\t\t DATA BASE_CISC_N2K");
printf("\n\t\t ******************");
printf("\n\n\t\t1.- NUEVO REGISTRO");
printf("\n\n\t\t2.- MODIFICAR REGISTRO");
printf("\n\n\t\t3.- ELIMINAR REGISTRO");
printf("\n\n\t\t4.- CONSULTAR");
printf("\n\n\t\t5.- SALIR\n\t");
printf("\n\n\t\t Elija una opcion:[ ]");gotoxy(39,17);scanf("%d",& op);
switch (op)
{
case 1:
ingresar();
menu();
break;
case 2:
modificar();
break;
case 3:
eliminar();
menu();
break;
case 4:
consultar();
default : printf("\n\n\n\t\tMsg:OPCIÓN NO VÁLIDA...VUELVA A INTENTARLO.");
getch();clrscr();
}
}while(op<1 || op>5);
clrscr();
}
void ingresar() //DEFINICION DE LA FUNCION ingresar//
{
int d, m, a, val;
clrscr();
ptr=fopen("estudiantes.dat","ab");
if(ptr==NULL)
printf("Error de apertura");
else
{
fseek(ptr,0,SEEK_END);
valor=ftell(ptr)/tam;
est.codigo=valor+1;
printf("\n\t\tCodigo de estudiante:\t%d", est.codigo);
fflush(stdin);
printf("\n\t\tIngrese nombre del estudiante:\n\t");
gotoxy(20,4);gets(est.nombre);
printf("\n\t\tIngrese apellido del estudiante:\n\t");
gotoxy(20,8);gets(est.apellido);
printf("\n\t\tIngrese materia del estudiante:\n\t");
gotoxy(20,12);gets(est.materia);
do
{
printf("\n\t\tIngrese el curso del estudiante:\n\t");
gotoxy(20,16);scanf("%d",& est.curso);
}while(est.curso<=0 && est.curso >8);
do
{
printf("\n\t\tIngrese fecha de nacimiento del estudiante\n\n");
printf("\n\t\tDia:\t");scanf("%d", & d);
printf("\n\t\tMes:\t");scanf("%d", & m);
printf("\n\t\tAño:\t");scanf("%d", & a);
val=valida(d, m, a);
if(val==0)
printf("\n\t\tMessage:FECHA INCORRECTA...VUELVA A INTENTARLO \n\t");
getch();clrscr();
}while(val==0);est.dia= d;est.mes= m;est.año= a;
}
do
{
printf("\n\tINGRESE NOTA 1:\t");
scanf("%f", &est.nota1);
}while(est.nota1<0 || est.nota1>10);
do
{
printf("\n\tINGRESE NOTA 2:\t");
scanf("%f", &est.nota2);
}while(est.nota2<0 || est.nota2>10);
est.promedio=(est.nota1+est.nota2)/2;
est.estado='A';
fwrite(&est,tam,1,ptr);
res=ferror(ptr);
if(res==0){
gotoxy(10,15);printf("Msg: REGISTRO GUARDADO");getch();}
else
{ gotoxy(10,15);printf("Msg: NO SE GUARDO EL REGISTRO");
clrscr();
fclose(ptr);
}
getch();
}
void modificar()
{
op=0;
clrscr();
do
{
gotoxy(25,5);printf("MODIFICAR REGISTRO");
gotoxy(25,6);printf("__________________");
gotoxy(25,10);printf("1.MODIFICAR MATERIA");
gotoxy(25,11);printf("2.MODIFICAR CURSO");
gotoxy(25,12);printf("3.MODIFICAR NOTAS");
gotoxy(25,13);printf("4.SALIR");
gotoxy(25,18);printf("Ingrese opcion:[ ]");gotoxy(41,18);scanf("%d",& op);
switch (op)
{
case 1:
modi_materia();
menu();
break;
case 2:
modi_curso();
menu();
break;
case 3:
modi_nota();
menu();
break;
case 4:
menu();
}
}while(op<1||op>4);
getch();clrscr();
}
void modi_materia()
{
int n;
clrscr();
lista_general();
ptr=fopen("estudiantes.dat","r+b");
if(ptr==NULL)
printf("Error de apertura");
else
{
fseek(ptr,0,SEEK_END);
valor=ftell(ptr)/tam;
do
{
gotoxy(30,5);printf("MODIFICAR MATERIA");
gotoxy(30,6);printf("_________________");
gotoxy(15,10);printf("INGRESE EL ID DE REGISTRO A MODIFICAR:[ ]");gotoxy(54,10);scanf("%d",&n);clrscr();
}while(n<1 || n>valor);
fseek(ptr,tam*(n-1),SEEK_SET);
fread(&est,tam,1,ptr);
gotoxy(20,3);printf("INFORMACION ACTUAL DEL ESTUDIANTE: %d",est.codigo);
gotoxy(20,4);printf("____________________________________");
printf("\n\n\n");
printf("ID NOMBRE APELLIDO MATERIA\tCURSO\tF/NAC\t\tNOTA1\tNOTA2\tPROMEDIO\n\n");
printf("\n\n%d %s %s %s\t %d\t %d-%d-%d\t %.2f\t %.2f\t %.2f" ,est.codigo
,est.nombre,est.apellido,est.materia,est.curso,est.dia,est.mes
,est.año,est.nota1,est.nota2,est.promedio);
printf("\n\n\nPRESIONE UNA TECLA....");
getch();
fflush(stdin);
printf("\n\tINGRESE NUEVA MATERIA\n\t");
gets(est.materia);
fseek(ptr,tam*(n-1),SEEK_SET);
fwrite(&est,tam,1,ptr);
res==ferror(ptr);
if(res==0)
printf("\n\tREGISTRO MODIFICADO");
else
printf("\n\tERROR AL MODIFICAR REGISTRO");
fclose(ptr);
getch();
}
clrscr();
}
void modi_curso()
{
int n;
clrscr();
lista_general();
ptr=fopen("estudiantes.dat","r+b");
if(ptr==NULL)
printf("Error de apertura");
else
{
fseek(ptr,0,SEEK_END);
valor=ftell(ptr)/tam;
do
{
gotoxy(30,5);printf("MODIFICAR CURSO");
gotoxy(30,6);printf("_________________");
gotoxy(15,10);printf("INGRESE EL ID DE REGISTRO A MODIFICAR:[ ]");
gotoxy(54,10);scanf("%d",&n);
clrscr();
}while(n<1 || n>valor);
fseek(ptr,tam*(n-1),SEEK_SET);
fread(&est,tam,1,ptr);
gotoxy(20,3);printf("INFORMACION ACTUAL DEL ESTUDIANTE # %d",est.codigo);
printf("\n\n");
printf("ID NOMBRE APELLIDO MATERIA\tCURSO\tF/NAC\t\tNOTA1\tNOTA2\tPROMEDIO\n\n");
printf("\n\n%d %s %s %s\t %d\t %d-%d-%d\t %.2f\t %.2f\t %.2f" ,est.codigo
,est.nombre,est.apellido,est.materia,est.curso,est.dia,est.mes
,est.año,est.nota1,est.nota2,est.promedio);
printf("\n\n\nPRESIONE UNA TECLA PARA CONTINUAR");
getch();
fflush(stdin);
printf("\n\tINGRESE NUEVO CURSO\n\t");
do
{
scanf("%d",& est.curso);
}while(est.curso<=0 && est.curso >8);
fseek(ptr,tam*(n-1),SEEK_SET);
fwrite(&est,tam,1,ptr);
res==ferror(ptr);
if(res==0)
printf("\n\tREGISTRO MODIFICADO");
else
printf("\n\tERROR AL MODIFICAR EL REGISTRO");
fclose(ptr);
getch();
}
clrscr();
}
void modi_nota()
{
int n;
clrscr();
printf("\n\n\n MODIFICACION DE CURSO:\n\t");
lista_general();
ptr=fopen("estudiantes.dat","r+b");
if(ptr==NULL)
printf("Error de apertura");
else
{
fseek(ptr,0,SEEK_END);
valor=ftell(ptr)/tam;
do
{
gotoxy(30,5);printf("MODIFICAR NOTAS");
gotoxy(30,6);printf("_______________");
gotoxy(15,10);printf("INGRESE EL ID DE REGISTRO A MODIFICAR:[ ]");gotoxy(54,10);scanf("%d",&n);clrscr();
}while(n<1 || n>valor);
fseek(ptr,tam*(n-1),SEEK_SET);
fread(&est,tam,1,ptr);
gotoxy(20,3);printf("INFORMACION ACTUAL DEL ESTUDIANTE # %d",est.codigo);
printf("\n\n");
printf("ID NOMBRE APELLIDO MATERIA\tCURSO\tF/NAC\t\tNOTA1\tNOTA2\tPROMEDIO\n\n");
printf("\n\n%d %s %s %s\t %d\t %d-%d-%d\t %.2f\t %.2f\t %.2f" ,est.codigo
,est.nombre,est.apellido,est.materia,est.curso,est.dia,est.mes
,est.año,est.nota1,est.nota2,est.promedio);
printf("\n\n\nPRESIONE UNA TECLA....");
getch();
fflush(stdin);
printf("\n\tINGRESE NUEVAS NOTAS\n\t");
do
{
printf("\n\tINGRESE NOTA 1:\t");
scanf("%f", &est.nota1);
}while(est.nota1<0 || est.nota1>10);
do
{
printf("\n\tINGRESE NOTA 2:\t");
scanf("%f", &est.nota2);
}while(est.nota2<0 || est.nota2>10);
est.promedio=(est.nota1+est.nota2)/2;
fseek(ptr,tam*(n-1),SEEK_SET);
fwrite(&est,tam,1,ptr);
res==ferror(ptr);
if(res==0)
printf("\n\tREGISTRO MODIFICADO");
else
printf("\n\tERROR AL MODIFICAR EL REGISTRO");
fclose(ptr);
getch();
}
clrscr();
}
void eliminar()
{
int num;
clrscr();
lista_general();
ptr=fopen("estudiantes.dat","r+b");
if(ptr==NULL)
printf("Error de apertura");
else
{
fseek(ptr,0,SEEK_END);
valor=ftell(ptr)/tam;
do
{
gotoxy(15,10);printf("INGRESE EL ID DE REGISTRO A ELIMINAR:[ ]");
gotoxy(54,10);scanf("%d",&num);clrscr();
}while(num<1 || num>valor);
fseek(ptr,tam*(num-1),SEEK_SET);
fread(&est,tam,1,ptr);
printf("INFORMACION ACTUAL DEL ESTUDIANTE # %d",est.codigo);
printf("\n\n");
printf("ID NOMBRE APELLIDO MATERIA\tCURSO\tF/NAC\t\tNOTA1\tNOTA2\tPROMEDIO\n\n");
printf("\n\n%d %s %s %s\t %d\t %d-%d-%d\t %.2f\t %.2f\t %.2f" ,est.codigo
,est.nombre,est.apellido,est.materia,est.curso,est.dia,est.mes
,est.año,est.nota1,est.nota2,est.promedio);
printf("\n\n\nPRESIONE UNA TECLA PARA CONTINUAR");
getch();
est.estado='I';
fseek(ptr,tam*(num-1),SEEK_SET);
fwrite(&est,tam,1,ptr);
res==ferror(ptr);
if(res==0)
printf("\n\n\tREGISTRO ELIMINADO");
else
printf("\n\n\tERROR AL INTENTAR ELIMINAR EL REGISTRO");
fclose(ptr);getch();
}
clrscr();
}
void consultar()
{
op=0;
clrscr();
do
{
gotoxy(30,5);printf("BUSCAR REGISTRO");
gotoxy(30,6);printf("_______________");
gotoxy(25,10);printf("1.CONSULTAR TODOS LOS CAMPOS");
gotoxy(25,11);printf("2.CONSULTAR POR NOMBRE");
gotoxy(25,12);printf("3.CONSULTAR POR MATERIA");
gotoxy(25,13);printf("4.CONSULTAR APROBADOS");
gotoxy(25,14);printf("5.CONSULTAR REPROBADOS");
gotoxy(25,15);printf("6.SALIR");
gotoxy(25,18);printf("Ingrese una opcion:[ ]");gotoxy(45,18);scanf("%d",& op);
switch (op)
{
case 1:
lista_general();
break;
case 2:
lista_nombre();
break;
case 3:
lista_materia();
break;
case 4:
lista_aprobados();
break;
case 5:
lista_reprobados();
break;
}
}while(op!=6);
getch();clrscr();
}
void lista_general()
{
clrscr();
printf("\n\t\t\tCONSULTA GENERAL\n");
printf("\t\t\t****************"); printf("\n");
ptr=fopen("estudiantes.dat","rb");
if(ptr==NULL)
printf("\nARCHIVO NO EXISTE");
else
{
printf("\nID\tNOMBRES APELLIDOS MATERIA\tCURSO\tNOTA1\tNOTA2\tPROMEDIO\n\n");
fread(&est,tam,1,ptr);
while(feof(ptr)==0)
{
if(est.estado=='A')
{
printf("\n%d:\t%s %s\t %s\t %d\t %.2f\t%.2f\t%.2f",est.codigo
,est.nombre,est.apellido,est.materia,est.curso,est.nota1,est.nota2,est.promedio);
printf("\n");
}
fread(&est,tam,1,ptr);
}
fclose(ptr);
}
printf("\n\n\nPRESIONE UNA TECLA PARA CONTINUAR.......");
getch();
clrscr();
}
void lista_nombre()
{
char nom[50];
int cont=0;
clrscr();
gotoxy(25,5);printf("CONSULTAR POR NOMBRE");
gotoxy(25,6);printf("********************");
ptr=fopen("estudiantes.dat","rb");
if(ptr==NULL)
printf("\nARCHIVO NO EXISTE");
else
{
fseek(ptr,0,SEEK_SET);
fflush(stdin);
gotoxy(10,10);printf("INGRESE EL NOMBRE DEL ESTUDIANTE:");
gotoxy(43,10);gets(nom);clrscr();
gotoxy(25,3);printf("RESULTADO DE LA CONSULTA");
gotoxy(25,4);printf("________________________");
printf("\n\nID\tNOMBRES APELLIDOS MATERIA\tCURSO\tNOTA1\tNOTA2\tPROMEDIO\n\n");
fread(&est,tam,1,ptr);
while(feof(ptr)==0)
{
if(est.estado=='A')
{
if(strcmp(est.nombre,nom)==0)
{
printf("\n%d:\t%s %s\t %s\t %d\t %.2f\t%.2f\t%.2f",est.codigo
,est.nombre,est.apellido,est.materia,est.curso,est.nota1,est.nota2,est.promedio);
printf("\n");
cont++;
}
}
fread(&est,tam,1,ptr);
}
fclose(ptr);
if(cont==0)
printf("\n\tALUMNO NO REGISTRADO");
printf("\n\n\n\n\tPRESIONE UNA TECLA.....");
getch();
}
clrscr();
}
void lista_materia()
{
char mat[50];
int cont=0;
clrscr();
gotoxy(25,5);printf("CONSULTA POR MATERIA");
gotoxy(25,6);printf("********************");
ptr=fopen("estudiantes.dat","rb");
if(ptr==NULL)
printf("\nARCHIVO NO EXISTE");
else
{
fseek(ptr,0,SEEK_SET);
fflush(stdin);
gotoxy(10,8);printf("INGRESE EL NOMBRE DE LA MATRIA:");
gotoxy(41,8);gets(mat);clrscr();
gotoxy(25,3);printf("RESULTADO DE LA CONSULTA");
gotoxy(25,4);printf("________________________");printf("\n\n\n");
printf("ID\tNOMBRE APELLIDOS MATERIA\tCURSO\tNOTA1\tNOTA2\tPROMEDIO\n\n");
fread(&est,tam,1,ptr);
while(feof(ptr)==0)
{
if(est.estado=='A')
{
if(strcmp(est.materia,mat)==0)
{
printf("\n%d:\t%s %s\t %s\t %d\t %.2f\t%.2f\t%.2f",est.codigo
,est.nombre,est.apellido,est.materia,est.curso,est.nota1,est.nota2,est.promedio);
printf("\n");
cont++;
}
}
fread(&est,tam,1,ptr);
}
fclose(ptr);
if(cont==0)
printf("\n\tMATERIA NO REGISTRADA");
printf("\n\n\n\n\tPRESIONE UNA TECLA.....");
getch();
}
clrscr();
}
void lista_aprobados()
{
clrscr();
gotoxy(16,3);printf("RESULTADO DE LA CONSULTA DE ALUMNOS APROBADOS");
gotoxy(16,4);printf("_____________________________________________");printf("\n\n\n");
ptr=fopen("estudiantes.dat","rb");
if(ptr==NULL)
printf("\nARCHIVO NO EXISTE");
else
{
printf("ID\tNOMBRE APELLIDOS MATERIA\tCURSO\tNOTA1\tNOTA2\tPROMEDIO\n\n");
fread(&est,tam,1,ptr);
while(feof(ptr)==0)
{
if(est.estado=='A')
{
if(est.promedio>=7)
{
printf("\n%d:\t%s %s\t %s\t %d\t %.2f\t%.2f\t%.2f",est.codigo
,est.nombre,est.apellido,est.materia,est.curso,est.nota1,est.nota2,est.promedio);
printf("\n");
}
}
fread(&est,tam,1,ptr);
}
fclose(ptr);
}
printf("\n\n\nPRESIONE UNA TECLA PARA CONTINUAR.......");
getch();clrscr();
}
void lista_reprobados()
{
clrscr();
gotoxy(16,3);printf("RESULTADO DE LA CONSULTA DE ALUMNOS REPROBADOS\n\n");
gotoxy(16,4);printf("_____________________________________________");printf("\n\n\n");
ptr=fopen("estudiantes.dat","rb");
if(ptr==NULL)
printf("\nARCHIVO NO EXISTE");
else
{
printf("ID\tNOMBRE APELLIDOS MATERIA\tCURSO\tNOTA1\tNOTA2\tPROMEDIO\n\n");
fread(&est,tam,1,ptr);
while(feof(ptr)==0)
{
if(est.estado=='A')
{
if(est.promedio<7)
{
printf("\n%d:\t%s %s\t %s\t %d\t %.2f\t%.2f\t%.2f",est.codigo
,est.nombre,est.apellido,est.materia,est.curso,est.nota1,est.nota2,est.promedio);
printf("\n");
}
}
fread(&est,tam,1,ptr);
}
fclose(ptr);
}
printf("\n\n\nPRESIONE UNA TECLA PARA CONTINUAR.......");
getch();clrscr();
}
int valida(int dd, int mm, int aa)
{
int aux;
if(aa<=1954 || aa>=2015)
return 0;
if(mm<1 || mm > 12)
return 0;
switch(mm)
{
case 2:
if((aa%4==0 && aa%100!=0)||(aa%400==0))
aux=29;
else
aux=28;
break;
case 4: case 6: case 9: case 11:
aux=30;
break;
default:
aux=31;
}
if(dd<1 || dd>aux)
return 0; return 1;
}
void validar()
{
char usuario[10],pass[8],x;
gotoxy(26,5);printf("Universidad de Guayaquil");
gotoxy(18,6);printf("Facultad de Ciencias Matemáticas y Físicas");
gotoxy(15,7);printf("Carrera de Ingeniería en Sistemas Computacionales -");
gotoxy(27,8);printf("Ingenieria en Networking");
gotoxy(15,10);printf("***************************************************");
gotoxy(18,12);printf("DATABASE_CINTN2K");
gotoxy(18,13);printf("Login:");
gotoxy(28,26);printf(" ");
gotoxy(35,18);printf("Username:");gotoxy(44,18);scanf("%s",&usuario);
gotoxy(35,20);printf("Password:");
char *pass1 = password();
if((strcmp(usuario,"ADMIN")==0)&&(strcmp(pass1,"0927")==0))
{
clrscr();
gotoxy(30,22);printf("Msg: USUARIO AUTENTICADO CORRECTAMENTE");
gotoxy(30,23);printf("______________________________________");
getch();
menu();
getch();
clrscr();
}
else
{
clrscr();
gotoxy(35,22);printf("Msg: ACCESO DENEGADO AL SISTEMA");
gotoxy(35,23);printf("_______________________________");
getch();
gotoxy(35,22);printf(" ");
gotoxy(35,23);printf(" ");
validar();
}
}
char * password()
{
char *aux = new char[10];
int car = 0 ;
int i = 0;
while(((car = getch()) != 13) && i < 10)
{
aux[i] = car;
printf("*");
i++;
}
if(i == 0)
{
delete aux;
return NULL;
}
aux[i] = NULL;
return aux;
}
[/code ]