Advertisement
xlujiax

Lab6_2017

Oct 27th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.94 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  * Renzo Castillo - 20101700
  6.  */
  7.  
  8. #include "Bib_Func_Preg2.h"
  9. #include "Bib_Func_Preg1.h"
  10. #include <iostream>
  11. #include <iomanip>
  12. #include <cstring>
  13. #include <cstdlib>
  14. #define INC 5
  15.  
  16. using namespace std;
  17.  
  18. void** nuevoRegistroNotas(char** palabra, int numPal) {
  19.     void** regNotas = new void*[4];
  20.     int *codigoAlumno = new int;
  21.     *codigoAlumno = atoi(palabra[0]);
  22.  
  23.     int *codCurso = new int;
  24.     *codCurso = atoi(palabra[1]);
  25.  
  26.     int* nota = new int;
  27.     *nota = atoi(palabra[2]);
  28.  
  29.     int* creditos = new int;
  30.     *creditos = atoi(palabra[3]);
  31.  
  32.     regNotas[0] = codigoAlumno;
  33.     regNotas[1] = codCurso;
  34.     regNotas[2] = nota;
  35.     regNotas[3] = creditos;
  36.  
  37.  
  38.     return regNotas;
  39. }
  40.  
  41. void incrementar(void** & lstElem, int numElem) {
  42.     if (lstElem == NULL) {
  43.         lstElem = new void*[INC + 1];
  44.         for (int i = 0; i <= INC; i++) {
  45.             lstElem[i] = NULL;
  46.         }
  47.     } else {
  48.         void** auxElem = new void*[numElem + INC + 1];
  49.         for (int i = 0; i < numElem; i++) {
  50.             auxElem[i] = lstElem[i];
  51.         }
  52.         for (int i = numElem; i <= numElem + INC; i++) {
  53.             auxElem[i] = NULL;
  54.         }
  55.         delete [] lstElem;
  56.         lstElem = auxElem;
  57.     }
  58.  
  59. }
  60.  
  61. void leerNotas(void*& lstAlumnos, int numAl) {
  62.  
  63.     char linea[100];
  64.     while (1) {
  65.         char** palabra;
  66.         int numPal = 0;
  67.         cin.getline(linea, 100, '\n');
  68.  
  69.         if (strcmp(linea, "\0") == 0) break;
  70.         splitTokens(linea, palabra, numPal);
  71.  
  72.         void **recLstAlumnos = (void**) lstAlumnos;
  73.         for (int i = 0; i < numAl; i++) {
  74.             void** regAlumno = (void**) recLstAlumnos[i];
  75.             int* codAlumno = (int*) regAlumno[0];
  76.             if (*codAlumno == atoi(palabra[0])) {
  77.                 //cout << "Hola" << endl;
  78.                 void** buffLstNotas = NULL;
  79.  
  80.                 int numNotas = 0;
  81.                 if (regAlumno[2] != NULL) {
  82.                     buffLstNotas = (void**) regAlumno[2];
  83.                     while (buffLstNotas[numNotas] != NULL)
  84.                         numNotas++;
  85.                     if (numNotas % INC == 0)
  86.                         incrementar(buffLstNotas, numNotas);
  87.                     void **regNotas = nuevoRegistroNotas(palabra, numPal);
  88.                     buffLstNotas[numNotas] = regNotas;
  89.                    
  90.                 } else { //Cuando no hay elementos
  91.                     if (numNotas % INC == 0)
  92.                         incrementar(buffLstNotas, numNotas);
  93.                     void **regNotas = nuevoRegistroNotas(palabra, numPal);
  94.                     buffLstNotas[numNotas] = regNotas;
  95.                 }
  96.  
  97.                 regAlumno[2] = buffLstNotas;
  98.  
  99.                 break;
  100.             }
  101.         }
  102.         //void **regNotas = nuevoRegistroNotas(palabra, numPal);
  103.  
  104.     }
  105. }
  106.  
  107. void imprimirRegNotas(void ** regNotas) {
  108.     int* codigoCurso = (int*) regNotas[1];
  109.     int* nota = (int*) regNotas[2];
  110.     int* credito = (int*) regNotas[3];
  111.  
  112.     cout << " Codigo Curso: " << *codigoCurso << "  Nota: " << *nota << " Credito: " << *credito;
  113. }
  114.  
  115. void imprimirRegAlumnos(void** regCurso) {
  116.     int* codigoAl = (int*) regCurso[0];
  117.     char* nombreAl = (char*) regCurso[1];
  118.  
  119.     cout << "Codigo Alumno: " << *codigoAl << " Nombre Alumno: " << nombreAl;
  120.  
  121.     void** lstNotas = (void**) regCurso[2];
  122.     for (int i = 0; lstNotas[i] != NULL; i++) {
  123.         void** regNotas = (void**) lstNotas[i];
  124.         imprimirRegNotas(regNotas);
  125.         cout << endl;
  126.     }
  127.  
  128.  
  129. }
  130.  
  131. void imprimirAlumnosNotas(void* lstAlumnos, int numAl) {
  132.     void **recLstAlumnos = (void**) lstAlumnos;
  133.     for (int i = 0; i < numAl; i++) {
  134.         void** regAlumno = (void**) recLstAlumnos[i];
  135.         imprimirRegAlumnos(regAlumno);
  136.         cout << endl;
  137.     }
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement