elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Trabajando con las ramas de git (tercera parte)


  Mostrar Temas
Páginas: [1]
1  Programación / Programación C/C++ / [C++][AYUDA]....Proyecto de Base de Datos de Alumnos en: 19 Enero 2015, 19:31 pm
Hola Buenas Dias Tardes o Noches.....Necesito me ayuden con este proyecto....esta casi terminado...pero al ejecutarlo aparenta guardar los datos pero al momento que eligio la opcion mostrar los datos para modificarlos o eliminarlos ....no los muestra ...pareciera que los datos no se guardan....ese es el incoveniente no se si me estare equipovando al momento de utilizar el archivo FILE que es el que sirve como gestor de base de datos en C++.. El resto del codigo funciona a la perfeccion ..me eh quedado estancado ahi no se que mas modificar......de antemano muchas gracias por su gentil ayuda...:)...:)....(Y).
Código
  1. #include<conio.h>
  2. #include<stdio.h>
  3. #include<string.h>
  4.  
  5. struct estudiantes
  6. {
  7. int codigo;
  8. char nombre[50];
  9. char apellido[50];
  10. char materia[50];
  11. int curso;
  12. int dia;
  13. int mes;
  14. int año;
  15. float nota1;
  16. float nota2;
  17. float promedio;
  18. char estado;
  19. };//Fin de la estructura_estudiantes
  20. char *password();
  21. void validar();
  22. void menu();
  23. void ingresar();
  24. void modificar();
  25. void modi_materia();
  26. void modi_curso();
  27. void modi_nota();
  28. void eliminar();
  29. void consultar();
  30. void lista_general();
  31. void lista_nombre();
  32. void lista_materia();
  33. void lista_aprobados();
  34. void lista_reprobados();
  35. int valida(int, int, int);
  36. int op, res, valor=0;
  37. FILE *ptr;
  38. struct estudiantes est;
  39. long tam=sizeof(struct estudiantes);
  40. void main()
  41. {
  42.  clrscr();validar();
  43.  menu();
  44.  getch();
  45.  }
  46. void menu()
  47. {
  48.  op=0;
  49.  clrscr();
  50.   do
  51.   {
  52.    printf("\n\n\t\t    DATA BASE_CISC_N2K");
  53.    printf("\n\t\t    ******************");
  54.    printf("\n\n\t\t1.- NUEVO REGISTRO");
  55.    printf("\n\n\t\t2.- MODIFICAR REGISTRO");
  56.    printf("\n\n\t\t3.- ELIMINAR REGISTRO");
  57.    printf("\n\n\t\t4.- CONSULTAR");
  58.    printf("\n\n\t\t5.- SALIR\n\t");
  59.    printf("\n\n\t\t    Elija una opcion:[ ]");gotoxy(39,17);scanf("%d",& op);
  60.    switch (op)
  61.     {
  62.      case 1:
  63.            ingresar();
  64.    menu();
  65.            break;
  66.      case 2:
  67.            modificar();
  68.            break;
  69.      case 3:
  70.            eliminar();
  71.    menu();
  72.    break;
  73.      case 4:
  74.    consultar();
  75.  
  76.      default : printf("\n\n\n\t\tMsg:OPCIÓN NO VÁLIDA...VUELVA A INTENTARLO.");
  77.      getch();clrscr();
  78.     }
  79.   }while(op<1 || op>5);
  80.   clrscr();
  81. }
  82.  
  83. void ingresar() //DEFINICION DE LA FUNCION ingresar//
  84. {
  85.  int d, m, a, val;
  86.  clrscr();
  87.  ptr=fopen("estudiantes.dat","ab");
  88.  if(ptr==NULL)
  89.   printf("Error de apertura");
  90.  else
  91.  {
  92.   fseek(ptr,0,SEEK_END);
  93.   valor=ftell(ptr)/tam;
  94.   est.codigo=valor+1;
  95.   printf("\n\t\tCodigo de estudiante:\t%d", est.codigo);
  96.   fflush(stdin);
  97.   printf("\n\t\tIngrese nombre del estudiante:\n\t");
  98.   gotoxy(20,4);gets(est.nombre);
  99.   printf("\n\t\tIngrese apellido del estudiante:\n\t");
  100.   gotoxy(20,8);gets(est.apellido);
  101.   printf("\n\t\tIngrese materia del estudiante:\n\t");
  102.   gotoxy(20,12);gets(est.materia);
  103.   do
  104.   {
  105.    printf("\n\t\tIngrese el curso del estudiante:\n\t");
  106.    gotoxy(20,16);scanf("%d",& est.curso);
  107.   }while(est.curso<=0 && est.curso >8);
  108.   do
  109.   {
  110.    printf("\n\t\tIngrese fecha de nacimiento del estudiante\n\n");
  111.    printf("\n\t\tDia:\t");scanf("%d", & d);
  112.    printf("\n\t\tMes:\t");scanf("%d", & m);
  113.    printf("\n\t\tAño:\t");scanf("%d", & a);
  114.    val=valida(d, m, a);
  115.    if(val==0)
  116.    printf("\n\t\tMessage:FECHA INCORRECTA...VUELVA A INTENTARLO \n\t");
  117.    getch();clrscr();
  118.   }while(val==0);est.dia= d;est.mes= m;est.año= a;
  119.   }
  120.   do
  121.    {
  122.     printf("\n\tINGRESE NOTA 1:\t");
  123.     scanf("%f", &est.nota1);
  124.    }while(est.nota1<0 || est.nota1>10);
  125.   do
  126.    {
  127.     printf("\n\tINGRESE NOTA 2:\t");
  128.     scanf("%f", &est.nota2);
  129.    }while(est.nota2<0 || est.nota2>10);
  130.   est.promedio=(est.nota1+est.nota2)/2;
  131.   est.estado='A';
  132.   fwrite(&est,tam,1,ptr);
  133.   res=ferror(ptr);
  134.   if(res==0){
  135.    gotoxy(10,15);printf("Msg: REGISTRO GUARDADO");getch();}
  136.   else
  137.   { gotoxy(10,15);printf("Msg: NO SE GUARDO EL REGISTRO");
  138.    clrscr();
  139.   fclose(ptr);
  140.  }
  141.  getch();
  142. }
  143.  
  144. void modificar()
  145. {
  146. op=0;
  147. clrscr();
  148. do
  149. {
  150.  gotoxy(25,5);printf("MODIFICAR REGISTRO");
  151.  gotoxy(25,6);printf("__________________");
  152.  gotoxy(25,10);printf("1.MODIFICAR MATERIA");
  153.  gotoxy(25,11);printf("2.MODIFICAR CURSO");
  154.  gotoxy(25,12);printf("3.MODIFICAR NOTAS");
  155.  gotoxy(25,13);printf("4.SALIR");
  156.  gotoxy(25,18);printf("Ingrese opcion:[ ]");gotoxy(41,18);scanf("%d",& op);
  157.     switch (op)
  158.      {
  159.       case 1:
  160.                 modi_materia();
  161.                 menu();
  162.                 break;
  163.       case 2:
  164.                 modi_curso();
  165. menu();
  166.                 break;
  167.       case 3:
  168.                 modi_nota();
  169.                 menu();
  170.                 break;
  171.       case 4:
  172.                 menu();
  173.      }
  174. }while(op<1||op>4);
  175. getch();clrscr();
  176. }
  177.  
  178. void modi_materia()
  179. {
  180. int n;
  181. clrscr();
  182.  
  183. lista_general();
  184. ptr=fopen("estudiantes.dat","r+b");
  185. if(ptr==NULL)
  186.   printf("Error de apertura");
  187.  else
  188.  {
  189.   fseek(ptr,0,SEEK_END);
  190.   valor=ftell(ptr)/tam;
  191.   do
  192.    {
  193.     gotoxy(30,5);printf("MODIFICAR MATERIA");
  194.     gotoxy(30,6);printf("_________________");
  195.     gotoxy(15,10);printf("INGRESE EL ID DE REGISTRO A MODIFICAR:[ ]");gotoxy(54,10);scanf("%d",&n);clrscr();
  196.    }while(n<1 || n>valor);
  197.    fseek(ptr,tam*(n-1),SEEK_SET);
  198.    fread(&est,tam,1,ptr);
  199.    gotoxy(20,3);printf("INFORMACION ACTUAL DEL ESTUDIANTE: %d",est.codigo);
  200.    gotoxy(20,4);printf("____________________________________");
  201.    printf("\n\n\n");
  202.    printf("ID NOMBRE APELLIDO MATERIA\tCURSO\tF/NAC\t\tNOTA1\tNOTA2\tPROMEDIO\n\n");
  203.    printf("\n\n%d %s %s %s\t %d\t %d-%d-%d\t %.2f\t %.2f\t %.2f" ,est.codigo
  204.       ,est.nombre,est.apellido,est.materia,est.curso,est.dia,est.mes
  205.       ,est.año,est.nota1,est.nota2,est.promedio);
  206.    printf("\n\n\nPRESIONE UNA TECLA....");
  207.    getch();
  208.    fflush(stdin);
  209.    printf("\n\tINGRESE NUEVA MATERIA\n\t");
  210.    gets(est.materia);
  211.    fseek(ptr,tam*(n-1),SEEK_SET);
  212.    fwrite(&est,tam,1,ptr);
  213.    res==ferror(ptr);
  214.    if(res==0)
  215.    printf("\n\tREGISTRO MODIFICADO");  
  216.    else
  217.     printf("\n\tERROR AL MODIFICAR REGISTRO");
  218.    fclose(ptr);
  219.    getch();
  220.  }
  221.  clrscr();
  222. }
  223.  
  224. void modi_curso()
  225. {
  226. int n;
  227. clrscr();
  228. lista_general();
  229. ptr=fopen("estudiantes.dat","r+b");
  230. if(ptr==NULL)
  231.   printf("Error de apertura");
  232.  else
  233.  {
  234.   fseek(ptr,0,SEEK_END);
  235.   valor=ftell(ptr)/tam;
  236.   do
  237.    {
  238.     gotoxy(30,5);printf("MODIFICAR CURSO");
  239.     gotoxy(30,6);printf("_________________");
  240.     gotoxy(15,10);printf("INGRESE EL ID DE REGISTRO A MODIFICAR:[ ]");
  241.     gotoxy(54,10);scanf("%d",&n);
  242.     clrscr();
  243.    }while(n<1 || n>valor);
  244.    fseek(ptr,tam*(n-1),SEEK_SET);
  245.    fread(&est,tam,1,ptr);
  246.    gotoxy(20,3);printf("INFORMACION ACTUAL DEL ESTUDIANTE # %d",est.codigo);
  247.    printf("\n\n");
  248.    printf("ID NOMBRE APELLIDO MATERIA\tCURSO\tF/NAC\t\tNOTA1\tNOTA2\tPROMEDIO\n\n");
  249.    printf("\n\n%d %s %s %s\t %d\t %d-%d-%d\t %.2f\t %.2f\t %.2f" ,est.codigo
  250.       ,est.nombre,est.apellido,est.materia,est.curso,est.dia,est.mes
  251.       ,est.año,est.nota1,est.nota2,est.promedio);
  252.    printf("\n\n\nPRESIONE UNA TECLA PARA CONTINUAR");
  253.    getch();
  254.    fflush(stdin);
  255.    printf("\n\tINGRESE NUEVO CURSO\n\t");
  256.    do
  257.     {
  258.      scanf("%d",& est.curso);
  259.     }while(est.curso<=0 && est.curso >8);
  260.    fseek(ptr,tam*(n-1),SEEK_SET);
  261.    fwrite(&est,tam,1,ptr);
  262.    res==ferror(ptr);
  263.    if(res==0)
  264.     printf("\n\tREGISTRO MODIFICADO");
  265.    else
  266.     printf("\n\tERROR AL MODIFICAR EL REGISTRO");
  267.    fclose(ptr);
  268.    getch();
  269.  }
  270.  clrscr();
  271. }
  272.  void modi_nota()
  273. {
  274. int n;
  275. clrscr();
  276. printf("\n\n\n MODIFICACION DE CURSO:\n\t");
  277. lista_general();
  278. ptr=fopen("estudiantes.dat","r+b");
  279. if(ptr==NULL)
  280.   printf("Error de apertura");
  281.  else
  282.  {
  283.   fseek(ptr,0,SEEK_END);
  284.   valor=ftell(ptr)/tam;
  285.   do
  286.    {
  287.     gotoxy(30,5);printf("MODIFICAR NOTAS");
  288.     gotoxy(30,6);printf("_______________");
  289.     gotoxy(15,10);printf("INGRESE EL ID DE REGISTRO A MODIFICAR:[ ]");gotoxy(54,10);scanf("%d",&n);clrscr();
  290.    }while(n<1 || n>valor);
  291.    fseek(ptr,tam*(n-1),SEEK_SET);
  292.    fread(&est,tam,1,ptr);
  293.    gotoxy(20,3);printf("INFORMACION ACTUAL DEL ESTUDIANTE # %d",est.codigo);
  294.    printf("\n\n");
  295.     printf("ID NOMBRE APELLIDO MATERIA\tCURSO\tF/NAC\t\tNOTA1\tNOTA2\tPROMEDIO\n\n");
  296.    printf("\n\n%d %s %s %s\t %d\t %d-%d-%d\t %.2f\t %.2f\t %.2f" ,est.codigo
  297.    ,est.nombre,est.apellido,est.materia,est.curso,est.dia,est.mes
  298.    ,est.año,est.nota1,est.nota2,est.promedio);
  299.    printf("\n\n\nPRESIONE UNA TECLA....");
  300.    getch();
  301.    fflush(stdin);
  302.    printf("\n\tINGRESE NUEVAS NOTAS\n\t");
  303.    do
  304.    {
  305.     printf("\n\tINGRESE NOTA 1:\t");
  306.     scanf("%f", &est.nota1);
  307.    }while(est.nota1<0 || est.nota1>10);
  308.    do
  309.    {
  310.     printf("\n\tINGRESE NOTA 2:\t");
  311.     scanf("%f", &est.nota2);
  312.    }while(est.nota2<0 || est.nota2>10);
  313.    est.promedio=(est.nota1+est.nota2)/2;
  314.    fseek(ptr,tam*(n-1),SEEK_SET);
  315.    fwrite(&est,tam,1,ptr);
  316.    res==ferror(ptr);
  317.    if(res==0)
  318.     printf("\n\tREGISTRO MODIFICADO");
  319.    else
  320.     printf("\n\tERROR AL MODIFICAR EL REGISTRO");
  321.    fclose(ptr);
  322.    getch();
  323.  }
  324.  clrscr();
  325. }
  326. void eliminar()
  327. {
  328.  int num;
  329.  clrscr();
  330.  lista_general();
  331.  ptr=fopen("estudiantes.dat","r+b");
  332.  if(ptr==NULL)
  333.   printf("Error de apertura");
  334.  else
  335.  {
  336.   fseek(ptr,0,SEEK_END);
  337.   valor=ftell(ptr)/tam;
  338.   do
  339.    {
  340.    gotoxy(15,10);printf("INGRESE EL ID DE REGISTRO A ELIMINAR:[ ]");
  341.    gotoxy(54,10);scanf("%d",&num);clrscr();
  342.    }while(num<1 || num>valor);
  343.    fseek(ptr,tam*(num-1),SEEK_SET);
  344.    fread(&est,tam,1,ptr);
  345.    printf("INFORMACION ACTUAL DEL ESTUDIANTE # %d",est.codigo);
  346.    printf("\n\n");
  347.    printf("ID NOMBRE APELLIDO MATERIA\tCURSO\tF/NAC\t\tNOTA1\tNOTA2\tPROMEDIO\n\n");
  348.    printf("\n\n%d %s %s %s\t %d\t %d-%d-%d\t %.2f\t %.2f\t %.2f" ,est.codigo
  349.    ,est.nombre,est.apellido,est.materia,est.curso,est.dia,est.mes
  350.    ,est.año,est.nota1,est.nota2,est.promedio);
  351.    printf("\n\n\nPRESIONE UNA TECLA PARA CONTINUAR");
  352.    getch();
  353.    est.estado='I';
  354.    fseek(ptr,tam*(num-1),SEEK_SET);
  355.    fwrite(&est,tam,1,ptr);
  356.    res==ferror(ptr);
  357.    if(res==0)
  358.     printf("\n\n\tREGISTRO ELIMINADO");  
  359.  
  360.    else
  361.     printf("\n\n\tERROR AL INTENTAR ELIMINAR EL REGISTRO");
  362.    fclose(ptr);getch();
  363.   }
  364.   clrscr();
  365.  }
  366.  
  367. void consultar()
  368. {
  369. op=0;
  370. clrscr();
  371. do
  372. {
  373.  gotoxy(30,5);printf("BUSCAR REGISTRO");
  374.  gotoxy(30,6);printf("_______________");
  375.  gotoxy(25,10);printf("1.CONSULTAR TODOS LOS CAMPOS");
  376.  gotoxy(25,11);printf("2.CONSULTAR POR NOMBRE");
  377.  gotoxy(25,12);printf("3.CONSULTAR POR MATERIA");
  378.  gotoxy(25,13);printf("4.CONSULTAR APROBADOS");
  379.  gotoxy(25,14);printf("5.CONSULTAR REPROBADOS");
  380.  gotoxy(25,15);printf("6.SALIR");
  381.  gotoxy(25,18);printf("Ingrese una opcion:[ ]");gotoxy(45,18);scanf("%d",& op);
  382.     switch (op)
  383.      {
  384.       case 1:
  385.                lista_general();
  386.                break;
  387.       case 2:
  388.                lista_nombre();
  389. break;
  390.       case 3:
  391.                lista_materia();
  392.                break;
  393.       case 4:
  394.                lista_aprobados();
  395.                break;
  396.       case 5:
  397.                lista_reprobados();
  398.                break;
  399.      }
  400. }while(op!=6);
  401. getch();clrscr();
  402. }
  403.  
  404. void lista_general()
  405. {
  406. clrscr();
  407. printf("\n\t\t\tCONSULTA GENERAL\n");
  408. printf("\t\t\t****************"); printf("\n");
  409. ptr=fopen("estudiantes.dat","rb");
  410. if(ptr==NULL)
  411.  printf("\nARCHIVO NO EXISTE");
  412. else
  413. {
  414.  printf("\nID\tNOMBRES APELLIDOS MATERIA\tCURSO\tNOTA1\tNOTA2\tPROMEDIO\n\n");
  415.  fread(&est,tam,1,ptr);
  416.  while(feof(ptr)==0)
  417.  {
  418.   if(est.estado=='A')
  419.    {
  420.       printf("\n%d:\t%s %s\t %s\t %d\t %.2f\t%.2f\t%.2f",est.codigo
  421.       ,est.nombre,est.apellido,est.materia,est.curso,est.nota1,est.nota2,est.promedio);
  422.     printf("\n");
  423.    }
  424.   fread(&est,tam,1,ptr);
  425.  }
  426.  fclose(ptr);
  427. }
  428. printf("\n\n\nPRESIONE UNA TECLA PARA CONTINUAR.......");
  429. getch();
  430. clrscr();
  431. }
  432.  
  433. void lista_nombre()
  434. {
  435. char nom[50];
  436. int cont=0;
  437. clrscr();
  438. gotoxy(25,5);printf("CONSULTAR POR NOMBRE");
  439. gotoxy(25,6);printf("********************");
  440. ptr=fopen("estudiantes.dat","rb");
  441. if(ptr==NULL)
  442.   printf("\nARCHIVO NO EXISTE");
  443. else
  444. {
  445.  fseek(ptr,0,SEEK_SET);
  446.  fflush(stdin);
  447.  gotoxy(10,10);printf("INGRESE EL NOMBRE DEL ESTUDIANTE:");
  448.  gotoxy(43,10);gets(nom);clrscr();
  449.  gotoxy(25,3);printf("RESULTADO DE LA CONSULTA");
  450.  gotoxy(25,4);printf("________________________");
  451.  printf("\n\nID\tNOMBRES APELLIDOS MATERIA\tCURSO\tNOTA1\tNOTA2\tPROMEDIO\n\n");
  452.  fread(&est,tam,1,ptr);
  453.  while(feof(ptr)==0)
  454.  {
  455.   if(est.estado=='A')
  456.    {
  457.     if(strcmp(est.nombre,nom)==0)
  458.      {
  459.  
  460. printf("\n%d:\t%s %s\t %s\t %d\t %.2f\t%.2f\t%.2f",est.codigo
  461.        ,est.nombre,est.apellido,est.materia,est.curso,est.nota1,est.nota2,est.promedio);
  462.        printf("\n");
  463.        cont++;
  464.      }
  465.     }
  466.      fread(&est,tam,1,ptr);
  467.  }
  468.  fclose(ptr);
  469.  if(cont==0)
  470.  printf("\n\tALUMNO NO REGISTRADO");
  471.  printf("\n\n\n\n\tPRESIONE UNA TECLA.....");
  472.  getch();
  473. }
  474. clrscr();
  475. }
  476.  
  477. void lista_materia()
  478. {
  479. char mat[50];
  480. int cont=0;
  481. clrscr();
  482. gotoxy(25,5);printf("CONSULTA POR MATERIA");
  483. gotoxy(25,6);printf("********************");
  484. ptr=fopen("estudiantes.dat","rb");
  485. if(ptr==NULL)
  486.   printf("\nARCHIVO NO EXISTE");
  487. else
  488. {
  489.  fseek(ptr,0,SEEK_SET);
  490.  fflush(stdin);
  491.  gotoxy(10,8);printf("INGRESE EL NOMBRE DE LA MATRIA:");
  492.  gotoxy(41,8);gets(mat);clrscr();
  493.  gotoxy(25,3);printf("RESULTADO DE LA CONSULTA");
  494.  gotoxy(25,4);printf("________________________");printf("\n\n\n");
  495.  printf("ID\tNOMBRE APELLIDOS MATERIA\tCURSO\tNOTA1\tNOTA2\tPROMEDIO\n\n");
  496.  fread(&est,tam,1,ptr);
  497.  while(feof(ptr)==0)
  498.  {
  499.   if(est.estado=='A')
  500.    {
  501.     if(strcmp(est.materia,mat)==0)
  502.      {
  503. printf("\n%d:\t%s %s\t %s\t %d\t %.2f\t%.2f\t%.2f",est.codigo
  504.        ,est.nombre,est.apellido,est.materia,est.curso,est.nota1,est.nota2,est.promedio);
  505. printf("\n");
  506.        cont++;
  507.      }
  508.    }
  509.     fread(&est,tam,1,ptr);
  510.  }
  511.  fclose(ptr);
  512.  if(cont==0)
  513.  printf("\n\tMATERIA NO REGISTRADA");
  514.  printf("\n\n\n\n\tPRESIONE UNA TECLA.....");
  515.  getch();
  516. }
  517. clrscr();
  518. }
  519.  
  520. void lista_aprobados()
  521. {
  522. clrscr();
  523. gotoxy(16,3);printf("RESULTADO DE LA CONSULTA DE ALUMNOS APROBADOS");
  524. gotoxy(16,4);printf("_____________________________________________");printf("\n\n\n");
  525. ptr=fopen("estudiantes.dat","rb");
  526. if(ptr==NULL)
  527.  printf("\nARCHIVO NO EXISTE");
  528. else
  529. {
  530. printf("ID\tNOMBRE APELLIDOS MATERIA\tCURSO\tNOTA1\tNOTA2\tPROMEDIO\n\n");
  531.  fread(&est,tam,1,ptr);
  532.  while(feof(ptr)==0)
  533.  {
  534.    if(est.estado=='A')
  535.    {
  536.     if(est.promedio>=7)
  537.      {
  538.      printf("\n%d:\t%s %s\t %s\t %d\t %.2f\t%.2f\t%.2f",est.codigo
  539.      ,est.nombre,est.apellido,est.materia,est.curso,est.nota1,est.nota2,est.promedio);
  540.       printf("\n");
  541.      }
  542.    }
  543.     fread(&est,tam,1,ptr);
  544.  }
  545.  fclose(ptr);
  546. }
  547. printf("\n\n\nPRESIONE UNA TECLA PARA CONTINUAR.......");
  548. getch();clrscr();
  549. }
  550.  
  551. void lista_reprobados()
  552. {
  553. clrscr();
  554. gotoxy(16,3);printf("RESULTADO DE LA CONSULTA DE ALUMNOS REPROBADOS\n\n");
  555. gotoxy(16,4);printf("_____________________________________________");printf("\n\n\n");
  556. ptr=fopen("estudiantes.dat","rb");
  557. if(ptr==NULL)
  558.  printf("\nARCHIVO NO EXISTE");
  559. else
  560. {
  561.  printf("ID\tNOMBRE APELLIDOS MATERIA\tCURSO\tNOTA1\tNOTA2\tPROMEDIO\n\n");
  562.  fread(&est,tam,1,ptr);
  563.  while(feof(ptr)==0)
  564.  {
  565.    if(est.estado=='A')
  566.    {
  567.     if(est.promedio<7)
  568.      {
  569.       printf("\n%d:\t%s %s\t %s\t %d\t %.2f\t%.2f\t%.2f",est.codigo
  570.       ,est.nombre,est.apellido,est.materia,est.curso,est.nota1,est.nota2,est.promedio);
  571.       printf("\n");
  572.      }
  573.     }
  574.      fread(&est,tam,1,ptr);
  575.  }
  576.  fclose(ptr);
  577. }
  578. printf("\n\n\nPRESIONE UNA TECLA PARA CONTINUAR.......");
  579. getch();clrscr();
  580. }
  581.  
  582. int valida(int dd, int mm, int aa)
  583. {
  584. int aux;
  585.  if(aa<=1954 || aa>=2015)
  586.   return 0;
  587.  if(mm<1 || mm > 12)
  588.   return 0;
  589.  switch(mm)
  590.  {
  591.   case 2:
  592.           if((aa%4==0 && aa%100!=0)||(aa%400==0))
  593.            aux=29;
  594.           else
  595.            aux=28;
  596.           break;
  597.   case 4: case 6: case 9: case 11:
  598.           aux=30;
  599.           break;
  600.   default:
  601.    aux=31;
  602.  }
  603.  if(dd<1 || dd>aux)
  604.  return 0; return 1;
  605. }
  606.  
  607.  
  608. void validar()
  609.   {
  610.    char usuario[10],pass[8],x;
  611.    gotoxy(26,5);printf("Universidad de Guayaquil");
  612.    gotoxy(18,6);printf("Facultad de Ciencias Matemáticas y Físicas");
  613.    gotoxy(15,7);printf("Carrera de Ingeniería en Sistemas Computacionales -");
  614.    gotoxy(27,8);printf("Ingenieria en Networking");
  615.  
  616.    gotoxy(15,10);printf("***************************************************");
  617.    gotoxy(18,12);printf("DATABASE_CINTN2K");
  618.    gotoxy(18,13);printf("Login:");
  619.    gotoxy(28,26);printf("                 ");
  620.    gotoxy(35,18);printf("Username:");gotoxy(44,18);scanf("%s",&usuario);
  621.    gotoxy(35,20);printf("Password:");
  622.  
  623.    char *pass1 = password();
  624.    if((strcmp(usuario,"ADMIN")==0)&&(strcmp(pass1,"0927")==0))
  625.    {
  626.     clrscr();
  627.     gotoxy(30,22);printf("Msg: USUARIO AUTENTICADO CORRECTAMENTE");
  628.     gotoxy(30,23);printf("______________________________________");
  629.     getch();
  630.     menu();
  631.     getch();
  632.     clrscr();
  633.    }
  634.    else
  635.    {
  636.     clrscr();
  637.     gotoxy(35,22);printf("Msg: ACCESO DENEGADO AL SISTEMA");
  638.     gotoxy(35,23);printf("_______________________________");
  639.     getch();
  640.     gotoxy(35,22);printf("                                     ");
  641.     gotoxy(35,23);printf("                                     ");
  642.     validar();
  643.     }
  644.   }
  645.  
  646. char * password()
  647. {
  648. char *aux = new char[10];
  649. int car = 0 ;
  650. int i = 0;
  651. while(((car = getch()) != 13) && i < 10)
  652. {
  653.  aux[i] = car;
  654.  printf("*");
  655.  i++;
  656.  }
  657.   if(i == 0)
  658.   {
  659.    delete aux;
  660.    return NULL;
  661.    }
  662.    aux[i] = NULL;
  663.    return aux;
  664. }
  665. [/code ]
2  Programación / Programación C/C++ / Ayuda..Problema Con Funcion Que Retorne Pares Positivos En Dev C++... en: 15 Agosto 2014, 02:05 am
Desearia que me ayuden en esta funcion de antemano gracias....se trata de un programa que me tiene que mostrar en dos funciones tipo retorna y recibe una serie de n elementos pares positivos eh intentado de varias maneras y pues se me ah complicado....ehh....si me ejecuta pero no me sale los valores pares me salen otros valores que no vienen al caso aqui les dejo la codificacion gracias....

Código
  1. #include<stdio.h>
  2. #include<conio.h>
  3. int fibo (int n ,char a[100]);
  4. main()
  5. {
  6. char a[100];
  7.      int n=0,i=0,l=0;
  8.       printf("\n\t\tNUMEROS PARES POSITIVOS\n\t\t");
  9.       printf("\n\t\tIngrese el Numero de terminos de la serie:\n\t\t");
  10.       scanf("%d",&n);
  11.       printf("\n");
  12.  
  13.       for(i=0;i<n;i++)  
  14.       {
  15.  
  16. printf("\n\t[%d]",a[i]);
  17. }
  18. a[i]=fibo(n,a);
  19.  
  20.       getch();
  21.       return 0;
  22.      /*la funcion recibe los parametros*/
  23. }
  24. int fibo(int n,char a[100])
  25. {
  26.  
  27.    int i=0;
  28.    printf("\n\tpresione una tecla para continuar");
  29.    a[0]=2;
  30.    for(i=0;i<n;i++)
  31. {
  32. if((a[i]%2)==0)
  33. a[i];
  34. }
  35. return a[i];
  36.    /* la subfuncion retorna parametros*/
  37. }
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines