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

 

 


Tema destacado: Tutorial básico de Quickjs


  Mostrar Temas
Páginas: [1]
1  Programación / Programación C/C++ / Archivos c++ en: 28 Noviembre 2012, 04:33 am
Buenas  :silbar: :silbar:

Mi problema es el siguiente,
Quiero saber como hacer para agregar informacion a una linea espesifica del Archivo es decir el archivo se llena con base a una etructura que tiene:

codigo
materia1
materia2
materia3
materia4
materia5

mi pregunta es:
yo tengo que registrar a todos los alumnos pero cuando ellos quieran inscribir materias ellos digiten el codigo que inscribi anteriormente yo y que lo busque y se pare en esa linea ((eso lo se hacer)) no se como hacer para que les aparezca la opcion de digitar las materias sobre esa linea en especifico

Espero me puedan ayudar.
GRACIAS.
2  Programación / Programación C/C++ / pasar/llamar vector a una funcion en: 22 Noviembre 2012, 05:56 am
Bueno mi problema es que no se como pasar un vetor a una funcion y luego llamarlo en otra :/ , miren mi codigo eta recien iniciado :) creo el arreglo en el main y lo relleno pero quiero crear una funcion VerArreglo y pasar el vector alli pero no se como epero me puedean ayudar Gracias  :o :( :rolleyes:

Código
  1. #include <cstdlib>
  2. #include "windows.h"
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int menu (){
  8.                                            HANDLE hConsoleHandle = GetStdHandle (STD_OUTPUT_HANDLE);    
  9.     int exit=0;
  10.     int opcion;
  11.  
  12.     printf("\n");
  13.        SetConsoleTextAttribute (hConsoleHandle, 2 | FOREGROUND_INTENSITY);
  14.        printf("\n                  *** MENU PRINCIPAL ***\n");
  15.        printf("                      --------------------");
  16.        SetConsoleTextAttribute (hConsoleHandle, 7 | FOREGROUND_INTENSITY);
  17.        printf("\n                   \t1. Insertar Elementos al Arreglo");
  18.        printf("\n                   \t2. Buscar Elementos Del arreglo");
  19.        printf("\n                   \t3. Eliminar Elementos Del Arreglo");
  20.        printf("\n                   \t4. Ordenar El Arreglo ");
  21.        printf("\n                   \t4. Ver El Arreglo ");
  22.        printf("\n                   \t5. Salir\n");
  23.  
  24.         while (exit == 0)
  25.        {
  26.                 SetConsoleTextAttribute (hConsoleHandle, 2 | FOREGROUND_INTENSITY);
  27.                cout<<"\nOpcion: ";
  28.                SetConsoleTextAttribute (hConsoleHandle, 7 | FOREGROUND_INTENSITY);
  29.                scanf("%d", &opcion);
  30.  
  31.                switch(opcion)
  32.                {
  33.                        case 1:
  34.                               system("CLS");
  35.                               cout<<"\n\n  Insertar";
  36.                               menu();
  37.                        break;        
  38.                        case 2:
  39.                               system("CLS");
  40.                               cout<<"\n\n  Buscar";
  41.                               menu();
  42.                        break;        
  43.                        case 3:
  44.                               system("CLS");
  45.                               cout<<"\n\n  Eliminar";
  46.                               menu();
  47.                        break;        
  48.                        case 4:
  49.                               system("CLS");
  50.                               cout<<"\n\n  Ordenar";
  51.                               menu();
  52.                        break;        
  53.                        case 5:
  54. //                               VerArreglo();
  55.                        break;
  56.                        case 6:
  57.                               exit = 1;
  58.                               return EXIT_SUCCESS;
  59.                        break;    
  60.                        default:
  61.                                printf("\n ** Esta opcion no es valida **\n");      
  62.                }
  63.        }
  64. system("CLS");
  65.     }
  66.  
  67.  
  68. main ()
  69. {
  70.     int n;
  71.  
  72.                                            HANDLE hConsoleHandle = GetStdHandle (STD_OUTPUT_HANDLE);
  73.                                       SetConsoleTextAttribute (hConsoleHandle, 7 | FOREGROUND_INTENSITY);
  74.     cout<<"\n Ingrese la longitud del arreglo:  ";                                            
  75.                                       SetConsoleTextAttribute (hConsoleHandle, 2 | FOREGROUND_INTENSITY);
  76.     cin>>n;
  77.     if ((n>=1)&&(n<=100)){}else{main();}
  78.     int vector[n];
  79.  
  80.     for (int i=1; i<=n;i++){
  81.         cin>>vector[i];
  82.         }
  83.  
  84.  
  85.     system("CLS");
  86.     menu();
  87.  
  88. return 0;    
  89. }
3  Programación / Programación C/C++ / Error al compilar en: 25 Octubre 2012, 18:15 pm
Q tal amigos miren ttengo este error al compilar este codigo

Código
  1. struct sEstado_1 {
  2.   char Nombre[40];
  3.   int Codigo;
  4.   char Estado[10];
  5. } E1;
  6.  
  7. struct sDatos_1 {
  8.   float Materia1;
  9.   float Materia2;
  10.   float Materia3;
  11.   float Materia4;
  12.   float Materia5;
  13.   float Materia6;
  14.   float Materia7;  
  15. } D1;
  16.  
  17.  
  18. void Buscar (){    
  19.  
  20.    FILE *Estado1;
  21.    int clave;
  22.    printf("Digite El Codigo Del Estudiante Q quiere Buscar: ");
  23.    scanf("%d", clave);
  24.     Estado1 = fopen("fichero.txt", "r");
  25.  
  26.        if(Estado1 == NULL)
  27.        {
  28.                printf("\nFichero no existe! \nPor favor creelo");
  29.                return;
  30.        }
  31.  
  32.  
  33. while(fread(&E1, sizeof(struct sEstado_1), 1, Estado1)==1)
  34. {
  35. // desplegando estructura buscada
  36. if ( clave == E1.Codigo)
  37. {
  38. printf("CODIGO =%d ",E1.Codigo);
  39. printf(" NOMBRE =%s ",E1.Nombre);
  40. printf(" ESTADO =%d ",E1.Estado);
  41. printf("\n");
  42. }// fin if
  43. }//fin while
  44.  
  45. fclose(Estado1);
  46.  
  47. }
  48.  
al insertar "clave" me sale que el programa dejo de funcionar

Codigo completo

Código
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <conio.h>
  5. #include <cstdlib>
  6. #include <windows.h>
  7.  
  8. using namespace std;
  9.  
  10. void menu();
  11. void CrearFichero(FILE *Estado1);
  12. void InsertarDatos(FILE *Estado1);
  13. void VerDatos(FILE *Estado1);
  14. void CrearArchivo(FILE *Datos1);
  15. void InsertarArchivos(FILE *Datos1);
  16. void VerArchivos(FILE *Datos1);
  17.  
  18.  
  19. struct sEstado_1 {
  20.   char Nombre[40];
  21.   int Codigo;
  22.   char Estado[10];
  23. } E1;
  24.  
  25. struct sDatos_1 {
  26.   float Materia1;
  27.   float Materia2;
  28.   float Materia3;
  29.   float Materia4;
  30.   float Materia5;
  31.   float Materia6;
  32.   float Materia7;  
  33. } D1;
  34.  
  35.  
  36. void Buscar (){    
  37.  
  38.    FILE *Estado1;
  39.    int clave;
  40.    printf("Digite El Codigo Del Estudiante Q quiere Buscar: ");
  41.    scanf("%d", clave);
  42.     Estado1 = fopen("fichero.txt", "r");
  43.  
  44.        if(Estado1 == NULL)
  45.        {
  46.                printf("\nFichero no existe! \nPor favor creelo");
  47.                return;
  48.        }
  49.  
  50.  
  51. while(fread(&E1, sizeof(struct sEstado_1), 1, Estado1)==1)
  52. {
  53. // desplegando estructura buscada
  54. if ( clave == E1.Codigo)
  55. {
  56. printf("CODIGO =%d ",E1.Codigo);
  57. printf(" NOMBRE =%s ",E1.Nombre);
  58. printf(" ESTADO =%d ",E1.Estado);
  59. printf("\n");
  60. }// fin if
  61. }//fin while
  62.  
  63. fclose(Estado1);
  64.  
  65. }
  66.  
  67. void PlanEstudio ()
  68. {
  69.        int opcion4;
  70.        FILE *Estado1;
  71.        FILE *Datos1;
  72.        int exit = 0;
  73.  
  74.        printf("\n   *** PLAN DE ESTUDIOS ***\n");
  75.        printf("\n\t1. Conultar Materias 1ş Semestre");
  76.        printf("\n\t2. Conultar Materias 2ş Semestre");
  77.        printf("\n\t3. Conultar Materias 3ş Semestre");
  78.        printf("\n\t4. Conultar Materias 4ş Semestre");
  79.        printf("\n\t5. Conultar Materias 5ş Semestre");
  80.        printf("\n\t6. Conultar Materias 6ş Semestre");
  81.        printf("\n\t7. Salir");
  82.  
  83.        while (!exit)
  84.        {
  85.                printf("\nOpcion: ");
  86.                scanf("%d", &opcion4);
  87.  
  88.                switch(opcion4)
  89.                {
  90.                        case 1:
  91.  
  92.                        break;        
  93.                        case 2:
  94.  
  95.                        break;        
  96.                        case 3:
  97.  
  98.                        break;        
  99.                        case 4:
  100.  
  101.                        break;        
  102.                        case 5:
  103.  
  104.                        break;
  105.                        case 6:
  106.  
  107.                        break;
  108.                        case 7:
  109.                                exit = 1;
  110.                        break;    
  111.                        default:
  112.                                printf("\n ** Esta opcion no es valida **\n");      
  113.                }
  114.        }
  115.  
  116.        return ;            
  117. }
  118.  
  119. void menuBusqueda()
  120. {
  121.        int opcion3;
  122.        FILE *Estado1;
  123.        FILE *Datos1;
  124.        int exit = 0;
  125.        printf("\n   *** MENU DE BUSQUEDA ***\n");
  126.        printf("\n\t1. Conultar Lista De Estudiantes");// lista
  127.        printf("\n\t2. Estado Del Estudiante");// datos: direccion, tel, etc...
  128.        printf("\n\t3. Plan De Estudio");// plan proyecto curricular
  129.        printf("\n\t4. Consultar Estudiante");// materias
  130.        printf("\n\t5. Volver al inicio");
  131.        printf("\n\t6. Salir");      
  132.  
  133.         while (!exit)
  134.        {
  135.                printf("\nOpcion: ");
  136.                scanf("%d", &opcion3);
  137.  
  138.                switch(opcion3)
  139.                {
  140.                        case 1:
  141.                               VerDatos(Estado1);
  142.                        break;        
  143.                        case 2:
  144.                               cout <<"Estado Del Estudiante";
  145.                        break;        
  146.                        case 3:
  147.                                PlanEstudio();
  148.                        break;        
  149.                        case 4:
  150.                                Buscar();
  151.                        break;        
  152.                        case 5:
  153.                                menu();
  154.                        break;
  155.                        case 6:
  156.                                exit = 1;
  157.                        break;
  158.                        default:
  159.                                printf("\n ** Esta opcion no es valida **\n");      
  160.                }
  161.        }
  162.  
  163.        return;
  164. }
  165.  
  166. void menuLista(){
  167.        int opcion2;
  168.        FILE *Estado1;
  169.        FILE *Datos1;
  170.        int exit = 0;
  171.     printf("\n   *** MENU LISTA ***\n");      
  172.        printf("\n\t1. Crear Archivo Lista");
  173.        printf("\n\t2. Insertar Datos a Lista");
  174.        printf("\n\t3. Ver Datos Lista");
  175.        printf("\n\t4. Volver Al Inicio");
  176.        printf("\n\t5. Salir Del Programa");
  177.        while (!exit)
  178.        {
  179.                printf("\nOpcion: ");
  180.                scanf("%d", &opcion2);
  181.  
  182.                switch(opcion2)
  183.                {
  184.                        case 1:
  185.                                CrearArchivo(Datos1);
  186.                        break;        
  187.                        case 2:
  188.                                InsertarArchivos(Datos1);
  189.                        break;        
  190.                        case 3:
  191.                                VerArchivos(Datos1);
  192.                        break;        
  193.                        case 4:
  194.                                menu();
  195.                        break;        
  196.                        case 5:
  197.                                exit = 1;
  198.                        break;
  199.                        default:
  200.                                printf("\nOpcion no valida");      
  201.                }
  202.        }
  203.  
  204.        return;
  205.     }
  206.  
  207. void menuAdministrativo()
  208. {
  209.        int opcion2;
  210.        FILE *Estado1;
  211.        FILE *Datos1;
  212.        int exit = 0;
  213.  
  214.        printf("\n   *** MENU ADMIISTRATIVO ***\n");      
  215.        printf("\n\t1. Crear Fichero");
  216.        printf("\n\t2. Insertar Datos");
  217.        printf("\n\t3. Ver Datos Parciales");
  218.        printf("\n\t4. Volver Al Inicio");
  219.        printf("\n\t5. Salir Del Programa");
  220.        while (!exit)
  221.        {
  222.                printf("\nOpcion: ");
  223.                scanf("%d", &opcion2);
  224.  
  225.                switch(opcion2)
  226.                {
  227.                        case 1:
  228.                                CrearFichero(Estado1);
  229.                        break;        
  230.                        case 2:
  231.                                InsertarDatos(Estado1);
  232.                        break;        
  233.                        case 3:
  234.                                VerDatos(Estado1);
  235.                        break;        
  236.                        case 4:
  237.                                menu();
  238.                        break;        
  239.                        case 5:
  240.                                exit = 1;
  241.                        break;
  242.                        default:
  243.                                printf("\nOpcion no valida");      
  244.                }
  245.        }
  246.  
  247.        return;
  248.  
  249. }
  250. void menu()
  251. {
  252.     int opcion, exit=0;
  253.  
  254.        printf("\n           *** MENU PRINCIPAL ***\n ");
  255.        printf("\n\t1. Ir al Menu Administrativo ");
  256.        printf("\n\t2. Ir al Menu De Busqueda ");
  257.        printf("\n\t3. Ir al Menu Lista");
  258.        printf("\n\t4. Salir");
  259.  
  260.        while (!exit)
  261.        {
  262.                printf("\n\nOpcion: ");
  263.                scanf("%d", &opcion);
  264.  
  265.                switch(opcion)
  266.                {
  267.  
  268.                        case 1:
  269.                                system("CLS");
  270.                                menuAdministrativo();              
  271.                        case 2:
  272.                                system("CLS");
  273.                                menuBusqueda();
  274.                        case 3:
  275.                                system("CLS");
  276.                                menuLista();
  277.                        case 4:
  278.                                system("CLS");
  279.                                exit = 1;
  280.                        break;
  281.                        default:
  282.                                printf("\nOpcion no valida");
  283.                }
  284.        }
  285.  
  286.        return ;
  287.  
  288. }
  289. int main ()
  290. {
  291.        system("color f");
  292.  
  293.        int opcion, opcion2, opcion3, opcion4;
  294.        int exit = 0;
  295.        FILE *Estado1;
  296.        FILE *Datos1;          
  297.        menu();
  298. }
  299.  
  300. void CrearFichero(FILE *Estado1)
  301. {
  302.        Estado1 = fopen("fichero.txt", "r");
  303.  
  304.        if(!Estado1)
  305.        {
  306.                Estado1 = fopen("fichero.txt", "w");
  307.                printf("\nArchivo creado!");
  308.        }
  309.        else
  310.        {
  311.                printf("\nEl fichero ya existe!");
  312.        }
  313.  
  314.        fclose (Estado1);
  315.  
  316.        return;
  317. }
  318. void InsertarDatos(FILE *Estado1)
  319. {
  320.        Estado1 = fopen("fichero.txt", "a+");
  321.  
  322.        if(Estado1 == NULL)
  323.        {
  324.                printf("\nFichero no existe! \nPor favor creelo");
  325.                return;
  326.        }
  327.  
  328. for (int a=1; a<=4; a++){
  329.        printf("\nDigita el Nombre: ");
  330.        scanf("%s", &E1.Nombre);
  331.  
  332.        printf("\nDigita el Codigo: ");
  333.        scanf("%d", &E1.Codigo);
  334.  
  335.        printf("\nEstado Del Estudiante: ");
  336.        scanf("%s", &E1.Estado);
  337.  
  338.        fwrite(&E1, sizeof(struct sEstado_1), 1, Estado1);
  339.   }
  340.        fclose(Estado1);
  341.  
  342.        return;
  343. }
  344. void VerDatos(FILE *Estado1)
  345. {
  346.        int numero = 1;
  347.  
  348.        Estado1 = fopen("fichero.txt", "r");
  349.  
  350.        if(Estado1 == NULL)
  351.        {
  352.                printf("\nFichero no existe! \nPor favor creelo");
  353.                return;
  354.        }
  355.  
  356.        fread(&E1, sizeof(struct sEstado_1), 1, Estado1);
  357.        printf("\nNumero \tNombre        \tCodigo     \tEstado Del Estudiate");
  358.  
  359.        while(!feof(Estado1))
  360.        {
  361.                printf("\n%d \t%s        \t%d        \t%s", numero, E1.Nombre, E1.Codigo, E1.Estado);
  362.                fread(&E1, sizeof(struct sEstado_1), 1, Estado1);
  363.                numero++;
  364.        }
  365.  
  366.        fclose(Estado1);
  367.  
  368.        return;
  369. }
  370. void CrearArchivo(FILE *Datos1)
  371. {
  372.        Datos1 = fopen("datos.txt", "r");
  373.  
  374.        if(!Datos1)
  375.        {
  376.                Datos1 = fopen("fichero.txt", "w");
  377.                printf("\nArchivo creado!");
  378.        }
  379.        else
  380.        {
  381.                printf("\nEl fichero ya existe!");
  382.        }
  383.  
  384.        fclose (Datos1);
  385.  
  386.        return;
  387. }
  388.  
  389. void InsertarArchivos(FILE *Datos1)
  390. {
  391.        Datos1 = fopen("datos.txt", "a+");
  392.  
  393.        if(Datos1 == NULL)
  394.        {
  395.                printf("\nFichero no existe! \nPor favor creelo");
  396.                return;
  397.        }
  398.  
  399.        printf("\nDigite la nota de Algoritmos: ");
  400.        scanf("%f", &D1.Materia1);
  401.  
  402.        printf("\nDigite la nota de Calculo: ");
  403.        scanf("%f", &D1.Materia2);
  404.  
  405.        printf("\nDigite la nota de Catedra FJDC: ");
  406.        scanf("%f", &D1.Materia3);
  407.  
  408.        printf("\nDigite la nota de Catedra DYC: ");
  409.        scanf("%f", &D1.Materia4);
  410.  
  411.        printf("\nDigite la nota de Logica: ");
  412.        scanf("%f", &D1.Materia5);
  413.  
  414.        printf("\nDigite la nota de Algebra: ");
  415.        scanf("%f", &D1.Materia6);
  416.  
  417.        printf("\nDigite la nota de Textos: ");
  418.        scanf("%f", &D1.Materia7);
  419.  
  420.        fwrite(&D1, sizeof(struct sDatos_1), 1, Datos1);
  421.  
  422.        fclose(Datos1);
  423.  
  424.        return;
  425. }
  426.  
  427. void VerArchivos(FILE *Datos1)
  428. {
  429.        int numero = 1;
  430.  
  431.        Datos1 = fopen("datos.txt", "r");
  432.  
  433.        if(Datos1 == NULL)
  434.        {
  435.                printf("\nFichero no existe! \nPor favor creelo");
  436.                return;
  437.        }
  438.  
  439.        fread(&D1, sizeof(struct sDatos_1), 1, Datos1);
  440.  
  441.        printf("\nNumero \tAlgoritmos \tCalculo \tCatedra FJDC \tCatedra DYC \tLogica \tAlgebra \tTextos");
  442.  
  443.        while(!feof(Datos1))
  444.        {
  445.                printf("\n%d \t%f \t%f \t%f \t%f \t%f \t%f \t%f", numero, D1.Materia1, D1.Materia2, D1.Materia3,
  446.                D1.Materia4, D1.Materia5, D1.Materia6, D1.Materia7);
  447.                fread(&D1, sizeof(struct sDatos_1), 1, Datos1);
  448.                numero++;
  449.        }
  450.  
  451.        fclose(Datos1);
  452.  
  453.  
  454.        return;
  455. }
  456.  
4  Programación / Programación C/C++ / Ayuda fseek ó ftell en: 25 Octubre 2012, 05:14 am
Q tal amigos mi pregunta es la siguiente:

realice un programa con ficheros, ese fichero tiene datos de 10 estudiantes como nombre, codigo .. etc..
Bueno no tengo idea  :-( de como hacer para que cuando de la opcion de buscar estudiante y digite el codigo del estudiante me aparescan los datos es decir la fila del fichero conn sus respectivos datos

hasta lo q e podido apreciar tengo en la funcion:

- abrir el fichero
- mirar si hubo errores al abrirlo
- y supongo aca debe ir  fseek() ó ftell() que comparar los datos pero no se como hacer para q me busque dicha linea del fichero al digitar el codigo

espero me puedan ayudar =D ;D  :D
5  Programación / Programación C/C++ / Ayuda Con menu C++ 4.9.9.4 en: 25 Octubre 2012, 04:14 am
Q tal amigos soy nuevo en este foro y necesito un poco de ayuda.
espero puedan resolver mi duda,

Bueno tengo que entregar un proyecto de programacion basica pues mi problema es que tengo mis menus con switch, ahora cuando ejecuto mi programa corre normalmente sin fallos  :silbar: :silbar:

mi pregunta es e visto muchos programas que al escojer una opcion del switch se borra la pantalla y sale el siguiente menu como si fuera una pantalla totalmente diferente; no se si me entienden =D

pues al ejecutar mi programa corre bien pero los menus me salen como una lista cada vez escojo la opcion y tengo como 10 menus asi q se pueden imaginar la lista que sale jeje

espero me puedan ayudar con un ejemplo gracias   :rolleyes: :rolleyes:
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines