Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- * Renzo Castillo - 20101700
- */
- #include "Bib_Func_Preg2.h"
- #include "Bib_Func_Preg1.h"
- #include <iostream>
- #include <iomanip>
- #include <cstring>
- #include <cstdlib>
- #define INC 5
- using namespace std;
- void** nuevoRegistroNotas(char** palabra, int numPal) {
- void** regNotas = new void*[4];
- int *codigoAlumno = new int;
- *codigoAlumno = atoi(palabra[0]);
- int *codCurso = new int;
- *codCurso = atoi(palabra[1]);
- int* nota = new int;
- *nota = atoi(palabra[2]);
- int* creditos = new int;
- *creditos = atoi(palabra[3]);
- regNotas[0] = codigoAlumno;
- regNotas[1] = codCurso;
- regNotas[2] = nota;
- regNotas[3] = creditos;
- return regNotas;
- }
- void incrementar(void** & lstElem, int numElem) {
- if (lstElem == NULL) {
- lstElem = new void*[INC + 1];
- for (int i = 0; i <= INC; i++) {
- lstElem[i] = NULL;
- }
- } else {
- void** auxElem = new void*[numElem + INC + 1];
- for (int i = 0; i < numElem; i++) {
- auxElem[i] = lstElem[i];
- }
- for (int i = numElem; i <= numElem + INC; i++) {
- auxElem[i] = NULL;
- }
- delete [] lstElem;
- lstElem = auxElem;
- }
- }
- void leerNotas(void*& lstAlumnos, int numAl) {
- char linea[100];
- while (1) {
- char** palabra;
- int numPal = 0;
- cin.getline(linea, 100, '\n');
- if (strcmp(linea, "\0") == 0) break;
- splitTokens(linea, palabra, numPal);
- void **recLstAlumnos = (void**) lstAlumnos;
- for (int i = 0; i < numAl; i++) {
- void** regAlumno = (void**) recLstAlumnos[i];
- int* codAlumno = (int*) regAlumno[0];
- if (*codAlumno == atoi(palabra[0])) {
- //cout << "Hola" << endl;
- void** buffLstNotas = NULL;
- int numNotas = 0;
- if (regAlumno[2] != NULL) {
- buffLstNotas = (void**) regAlumno[2];
- while (buffLstNotas[numNotas] != NULL)
- numNotas++;
- if (numNotas % INC == 0)
- incrementar(buffLstNotas, numNotas);
- void **regNotas = nuevoRegistroNotas(palabra, numPal);
- buffLstNotas[numNotas] = regNotas;
- } else { //Cuando no hay elementos
- if (numNotas % INC == 0)
- incrementar(buffLstNotas, numNotas);
- void **regNotas = nuevoRegistroNotas(palabra, numPal);
- buffLstNotas[numNotas] = regNotas;
- }
- regAlumno[2] = buffLstNotas;
- break;
- }
- }
- //void **regNotas = nuevoRegistroNotas(palabra, numPal);
- }
- }
- void imprimirRegNotas(void ** regNotas) {
- int* codigoCurso = (int*) regNotas[1];
- int* nota = (int*) regNotas[2];
- int* credito = (int*) regNotas[3];
- cout << " Codigo Curso: " << *codigoCurso << " Nota: " << *nota << " Credito: " << *credito;
- }
- void imprimirRegAlumnos(void** regCurso) {
- int* codigoAl = (int*) regCurso[0];
- char* nombreAl = (char*) regCurso[1];
- cout << "Codigo Alumno: " << *codigoAl << " Nombre Alumno: " << nombreAl;
- void** lstNotas = (void**) regCurso[2];
- for (int i = 0; lstNotas[i] != NULL; i++) {
- void** regNotas = (void**) lstNotas[i];
- imprimirRegNotas(regNotas);
- cout << endl;
- }
- }
- void imprimirAlumnosNotas(void* lstAlumnos, int numAl) {
- void **recLstAlumnos = (void**) lstAlumnos;
- for (int i = 0; i < numAl; i++) {
- void** regAlumno = (void**) recLstAlumnos[i];
- imprimirRegAlumnos(regAlumno);
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement