Advertisement
xlujiax

Untitled

Dec 5th, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 22.79 KB | None | 0 0
  1. //Main.cpp
  2. #include <cstdlib>
  3. #include <fstream>
  4. #include <iostream>
  5. #include "Miembro.h"
  6. #include "Alumno.h"
  7. #include "Profesor.h"
  8. #include "CListaT.h"
  9. #include "GestorReferencias.h"
  10. #include <cstdlib>
  11. using namespace std;
  12.  
  13. int main(int argc, char** argv) {
  14.    
  15.     ifstream archIn("Miembros.csv", ios::in);
  16.     if (!archIn) {
  17.         cerr << "No se puede abrir el archivo archIn" << endl;
  18.         exit(1);
  19.     }  
  20.    
  21.     ifstream archIn2("libros.csv", ios::in);
  22.     if (!archIn2) {
  23.         cerr << "No se puede abrir el archivo archIn" << endl;
  24.         exit(1);
  25.     }  
  26.    
  27.     GestorReferencias objGestor;
  28.    
  29.     objGestor.leeDatos(archIn);
  30.    
  31.     int codM;
  32.     while(1){
  33.         archIn2 >> codM;
  34.         if (archIn2.eof()) break;
  35.         archIn2.get();
  36.         objGestor.ActualizarCampos(codM, archIn2);
  37.     }
  38.    
  39.     ofstream archOut("reporte.txt", ios::out);
  40.     if (!archOut){
  41.         cerr << "No se pudo crear el archivo " << endl;
  42.         exit(1);
  43.     }
  44.    
  45.     objGestor.imprimirReporte(archOut);
  46.     return 0;
  47. }
  48. //CLISTAT.h
  49. #ifndef CLISTAT_H
  50. #define CLISTAT_H
  51.  
  52. #include "CNodoT.h"
  53. #include <iostream>
  54.  
  55. template <typename TDATO>
  56. class CListaT {
  57. private:
  58.     CNodoT<TDATO>* lista;
  59.     CNodoT<TDATO>* it;
  60.  
  61. public:
  62.  
  63.     CListaT() {
  64.         lista = NULL, it = NULL;
  65.     }
  66.     void insertar(TDATO&);
  67.     void imprimir();
  68.     void imprimir(std::ostream&);
  69.     void eliminar();
  70.     void eliminar(int);
  71.  
  72.     TDATO get_it();
  73.     void reset_it();
  74. };
  75.  
  76. template <typename TDATO>
  77. TDATO CListaT<TDATO>::get_it(){
  78.     //Este método retornará el dato actual y avanzará el puntero al siguiente nodo
  79.     if (it==NULL) return NULL; //Si la lista esta vacia o estamos al final.
  80.     CNodoT<TDATO>* nodoActual = it;
  81.     it = it->sig;
  82.     return nodoActual->dato;
  83. }
  84.  
  85. template <typename TDATO>
  86. void CListaT<TDATO>::reset_it(){
  87.     //Este método reiniciará el iterador interno y lo colocará al inicio de la lista
  88.     it = lista;
  89. }
  90.  
  91. template <typename TDATO>
  92. void CListaT<TDATO>::imprimir() {
  93.     CNodoT<TDATO> *nodoRec = this->lista;
  94.     int i = 0;
  95.     while (nodoRec != NULL) {
  96.         //std::cout << ++i << ") " << std::endl;
  97.         nodoRec->dato->imprimirDatos(std::cout);
  98.         nodoRec = nodoRec->sig;
  99.     }
  100. }
  101.  
  102. template <typename TDATO>
  103. void CListaT<TDATO>::imprimir(std::ostream& out) {
  104.     CNodoT<TDATO> *nodoRec = this->lista;
  105.     int i = 0;
  106.     while (nodoRec != NULL) {
  107.         //out << ++i << ") " << nodoRec->dato << std::endl;
  108.         nodoRec->dato->citar(out);
  109.         nodoRec = nodoRec->sig;
  110.     }
  111. }
  112.  
  113. template <typename TDATO>
  114. void CListaT<TDATO>::eliminar(int codigo) {
  115.     CNodoT<TDATO> *nodoRec = this->lista, *nodoAnt = NULL;
  116.     while (nodoRec != NULL) {
  117.  
  118.         if ((*nodoRec->dato) == codigo)
  119.             break;
  120.         nodoAnt = nodoRec;
  121.         nodoRec = nodoRec->sig;
  122.     }
  123.     if (nodoRec != NULL) {
  124.         if (nodoAnt != NULL) { //Si no es el primer elemento
  125.             nodoAnt->sig = nodoRec->sig;
  126.             nodoRec->sig = NULL;
  127.             delete nodoRec->dato;
  128.             delete nodoRec;
  129.         } else { //Si es el primer elemento
  130.             delete nodoRec->dato;
  131.             this->lista = nodoRec->sig;
  132.             delete nodoRec;
  133.         }
  134.     }
  135. }
  136.  
  137. template <typename TDATO>
  138. void CListaT<TDATO>::eliminar() {
  139.     CNodoT<TDATO> *nodoRec = this->lista, *nodoAnt = NULL;
  140.     while (nodoRec != NULL) {
  141.         delete nodoRec->dato;
  142.         nodoAnt = nodoRec;
  143.         nodoRec = nodoRec->sig;
  144.         delete nodoAnt;
  145.     }
  146.     this->lista = nodoRec;
  147. }
  148.  
  149. template <typename TDATO>
  150. void CListaT<TDATO>::insertar(TDATO& _dato) {
  151.     //Inserta ordenadamente
  152.     CNodoT<TDATO> *nodoRec, *nodoAnt = NULL, *nodoNuevo;
  153.     nodoRec = this->lista;
  154.     nodoNuevo = new CNodoT<TDATO>;
  155.     nodoNuevo->dato = _dato;
  156.     //Se recorre hasta encontrar la posición para insertar:
  157.     while (nodoRec != NULL) {
  158.         if (*(nodoRec->dato) > *(nodoNuevo->dato))
  159.             break;
  160.         nodoAnt = nodoRec;
  161.         nodoRec = nodoRec->sig;
  162.     }
  163.     //Inserción del nuevo dato:
  164.     nodoNuevo->sig = nodoRec;
  165.     if (nodoAnt != NULL) //Cuando sí habían datos
  166.         nodoAnt->sig = nodoNuevo;
  167.     else //Cuando la lista estaba vacía
  168.         this->lista = nodoNuevo;
  169. }
  170. #endif /* CLISTAT_H */
  171. //CNODOT.H
  172. #ifndef CNODOT_H
  173. #define CNODOT_H
  174.  
  175. #include <cstdlib>
  176.  
  177. template <typename TDATO> class CListaT;
  178.  
  179. template <typename TDATO>
  180.  
  181. class CNodoT {
  182. private:
  183.     TDATO dato;
  184.     CNodoT<TDATO> * sig;
  185. public:
  186.     CNodoT() {
  187.         sig = NULL;
  188.     }
  189.     friend class CListaT<TDATO>;
  190. };
  191.  
  192. #endif /* CNODOT_H */
  193.  
  194. //CLISTALIB.H
  195. #ifndef CLISTATLIB_H
  196. #define CLISTATLIB_H
  197.  
  198. #include "CNodoTlib.h"
  199. #include <iostream>
  200.  
  201. template <typename TDATO>
  202. class CListaTlib {
  203. private:
  204.     CNodoTlib<TDATO>* lista;
  205.     CNodoTlib<TDATO>* it;
  206. public:
  207.     CListaTlib() {
  208.         lista = NULL, it = NULL;
  209.     }
  210.     void insertar(TDATO&);
  211.     void imprimir();
  212.     void imprimir(std::ostream&);
  213.     void eliminar();
  214.     void eliminar(int);
  215.    
  216.     TDATO get_it();
  217.     void reset_it();
  218. };
  219.  
  220. template <typename TDATO>
  221. TDATO CListaTlib<TDATO>::get_it(){
  222.     //Este método retornará el dato actual y avanzará el puntero al siguiente nodo
  223.     if (it==NULL) return NULL; //Si la lista esta vacia o estamos al final.
  224.     CNodoTlib<TDATO>* nodoActual = it;
  225.     it = it->sig;
  226.     return nodoActual->dato;
  227. }
  228.  
  229. template <typename TDATO>
  230. void CListaTlib<TDATO>::reset_it(){
  231.     //Este método reiniciará el iterador interno y lo colocará al inicio de la lista
  232.     it = lista;
  233. }
  234.  
  235. template <typename TDATO>
  236. void CListaTlib<TDATO>::imprimir() {
  237.     CNodoTlib<TDATO> *nodoRec = this->lista;
  238.     int i = 0;
  239.     while (nodoRec != NULL) {
  240.         //std::cout << ++i << ") " << std::endl;
  241.         nodoRec->dato.L_imprimirDatos(std::cout);
  242.         nodoRec = nodoRec->sig;
  243.     }
  244. }
  245.  
  246. template <typename TDATO>
  247. void CListaTlib<TDATO>::imprimir(std::ostream& out) {
  248.     CNodoTlib<TDATO> *nodoRec = this->lista;
  249.     int i = 0;
  250.     while (nodoRec != NULL) {
  251.         //out << ++i << ") " << nodoRec->dato << std::endl;
  252.         nodoRec->dato.L_imprimirDatos(out);
  253.         nodoRec = nodoRec->sig;
  254.     }
  255. }
  256.  
  257. template <typename TDATO>
  258. void CListaTlib<TDATO>::eliminar(int codigo) {
  259.     CNodoTlib<TDATO> *nodoRec = this->lista, *nodoAnt = NULL;
  260.     while (nodoRec != NULL) {
  261.  
  262.         if ((*nodoRec->dato) == codigo)
  263.             break;
  264.         nodoAnt = nodoRec;
  265.         nodoRec = nodoRec->sig;
  266.     }
  267.     if (nodoRec != NULL) {
  268.         if (nodoAnt != NULL) { //Si no es el primer elemento
  269.             nodoAnt->sig = nodoRec->sig;
  270.             nodoRec->sig = NULL;
  271.             delete nodoRec->dato;
  272.             delete nodoRec;
  273.         } else{ //Si es el primer elemento
  274.             delete nodoRec->dato;
  275.             this->lista = nodoRec->sig;
  276.             delete nodoRec;
  277.         }
  278.     }
  279. }
  280. template <typename TDATO>
  281. void CListaTlib<TDATO>::eliminar() {
  282.     CNodoTlib<TDATO> *nodoRec = this->lista, *nodoAnt = NULL;
  283.     while (nodoRec != NULL) {
  284.         delete nodoRec->dato;
  285.         nodoAnt = nodoRec;
  286.         nodoRec = nodoRec->sig;
  287.         delete nodoAnt;
  288.     }
  289.     this->lista = nodoRec;
  290. }
  291.  
  292. template <typename TDATO>
  293. void CListaTlib<TDATO>::insertar(TDATO& _dato) {
  294.     //Inserta ordenadamente
  295.     CNodoTlib<TDATO> *nodoRec, *nodoAnt = NULL, *nodoNuevo;
  296.     nodoRec = this->lista;
  297.     nodoNuevo = new CNodoTlib<TDATO>;
  298.     nodoNuevo->dato = _dato;
  299.     //Se recorre hasta encontrar la posición para insertar:
  300.     while (nodoRec != NULL) {
  301.         if ((nodoRec->dato) > (nodoNuevo->dato))
  302.             break;
  303.         nodoAnt = nodoRec;
  304.         nodoRec = nodoRec->sig;
  305.     }
  306.     //Inserción del nuevo dato:
  307.     nodoNuevo->sig = nodoRec;
  308.     if (nodoAnt != NULL) //Cuando sí habían datos
  309.         nodoAnt->sig = nodoNuevo;
  310.     else //Cuando la lista estaba vacía
  311.         this->lista = nodoNuevo;
  312. }
  313.  
  314. #endif /* CLISTATLIB_H */
  315. //CNODOTLIB.H
  316. #ifndef CNODOTLIB_H
  317. #define CNODOTLIB_H
  318.  
  319. #include <cstdlib>
  320.  
  321. template <typename TDATO> class CListaTlib;
  322.  
  323. template <typename TDATO>
  324.  
  325. class CNodoTlib {
  326. private:
  327.     TDATO dato;
  328.     CNodoTlib<TDATO> * sig;
  329. public:
  330.     CNodoTlib() {
  331.         sig = NULL;
  332.     }
  333.     friend class CListaTlib<TDATO>;
  334. };
  335.  
  336. #endif /* CNODOTLIB_H */
  337.  
  338. //GestorReferencia.h
  339. #ifndef GESTORREFERENCIAS_H
  340. #define GESTORREFERENCIAS_H
  341.  
  342. #include "CListaT.h"
  343. #include "Miembro.h"
  344.  
  345. class GestorReferencias {
  346. private:
  347.     CListaT<Miembro*> lstMiembros;
  348.  
  349. public:
  350.     GestorReferencias();
  351.    
  352.     void leeDatos(std::istream &);
  353.    
  354.     void imprimirLista();
  355.    
  356.     void eliminarElemento(int);
  357.        
  358.     void eliminarLista();
  359.    
  360.     void ActualizarCampos(int, std::istream &);
  361.    
  362.     void imprimirReporte(std::ostream &);
  363.    
  364.     ~GestorReferencias();
  365.  
  366. };
  367. #endif /* GESTORREFERENCIAS_H */
  368.  
  369. //GestorReferencia.cpp
  370. #include "GestorReferencias.h"
  371. #include "Alumno.h"
  372. #include "Profesor.h"
  373.  
  374.  
  375. GestorReferencias::GestorReferencias() {
  376.     //this->lstPapers = NULL;
  377.     //this->lstPapers = new CListaT<Paper*>;
  378. }
  379.  
  380. GestorReferencias::~GestorReferencias() {
  381.     this->lstMiembros.eliminar();
  382. }
  383.  
  384. void GestorReferencias::leeDatos(std::istream& in) {
  385.  
  386.     char tipo;    
  387.     Miembro * lstMiembro[100];
  388.     //Paper * auxPaper;
  389.     //CListaT<Paper*> lstPapers;
  390.     //this->lstPapers = CListaT<Paper*> *lstPapers;
  391.      
  392.     int num = 0;
  393.    
  394.     while (1) {
  395.         if (in.eof()) break;
  396.         if (in.peek() == EOF) break;
  397.         in >> tipo;
  398.         in.get();
  399.  
  400.         if (tipo == 'A') {
  401.             lstMiembro[num] = new Alumno;
  402.             //auxPaper = new ConferencePaper;
  403.         }else if(tipo == 'P') {
  404.             lstMiembro[num] = new Profesor;
  405.             //auxPaper = new JournalPaper;
  406.         }
  407.        
  408.         lstMiembro[num]->leerDatos(in);
  409.         //auxPaper->leerDatos(in);
  410.        
  411.         this->lstMiembros.insertar(lstMiembro[num]);
  412.         num++;
  413.     }
  414. }
  415.  
  416. void GestorReferencias::imprimirLista() {
  417.     this->lstMiembros.imprimir();
  418. }
  419.  
  420. void GestorReferencias::eliminarLista() {
  421.     this->lstMiembros.eliminar();
  422.  
  423. }
  424.  
  425. void GestorReferencias::eliminarElemento(int id_paper){
  426.     this->lstMiembros.eliminar(id_paper);
  427. }
  428.  
  429. void GestorReferencias::ActualizarCampos(int cod, std::istream& in){
  430.     /*Miembro *nodoRec = this->lstMiembros;
  431.     while(nodoRec!=NULL){
  432.         if(nodoRec->getCodigo() == cod)
  433.             break;
  434.         nodoRec = nodoRec->;
  435.     }
  436.     Libro* newLibro = new Libro;
  437.    
  438.     newLibro->L_leerDatos(in);
  439.    
  440.     (nodoRec->listaDeLibro)->LB_insertar(newLibro);*/
  441.     Miembro* auxP;
  442.    
  443.     this->lstMiembros.reset_it();
  444.    
  445.     while(1){
  446.         auxP = this->lstMiembros.get_it();
  447.         if (auxP == NULL) return;
  448.         if (auxP->getCodigo() == cod)
  449.             break;
  450.     }
  451.     Libro* newLibro = new Libro;
  452.     newLibro->L_leerDatos(in);
  453.     auxP->insertarLibro(*newLibro);
  454.     this->lstMiembros.reset_it();
  455. }
  456.  
  457. void GestorReferencias::imprimirReporte(std::ostream & archOut){
  458.     Miembro* auxP;    
  459.     this->lstMiembros.reset_it();
  460.    
  461.     while(1){
  462.         auxP = this->lstMiembros.get_it();
  463.         if (auxP == NULL) return;
  464.         auxP->imprimirDatos(archOut);
  465.         auxP->imprimirLibro(archOut);        
  466.     }
  467.     this->lstMiembros.reset_it();
  468. }
  469. //Miembro.h
  470. #ifndef MIEMBRO_H
  471. #define MIEMBRO_H
  472.  
  473. #include <fstream>
  474. #include "Libro.h"
  475. #include "CListaT.h"
  476. #include "CListaTlib.h"
  477.  
  478.  
  479. class Miembro{
  480. protected:
  481.     char* nombre;
  482.     int codigo;
  483.     char* distrito;
  484.     CListaTlib<Libro> lstLibros;
  485.    
  486. public:
  487.     Miembro();
  488.     Miembro(const char*, int, const char*);
  489.     virtual ~Miembro();
  490.     virtual void imprimirDatos(std::ostream&) = 0;
  491.     virtual void leerDatos(std::istream&)=0;
  492.    
  493.     void SetDistrito(const char*);
  494.     char* GetDistrito() const;    
  495.     void setCodigo(int);
  496.     int getCodigo() const ;
  497.     void setNombre(const char*);
  498.     char* getNombre() const ;
  499.    
  500.     bool operator< (const Miembro&);
  501.     bool operator> (const Miembro&);
  502.     bool operator==(const Miembro&);
  503.     bool operator==(int);
  504.    
  505.     void insertarLibro(Libro&);
  506.     void imprimirLibro(std::ostream&);
  507.    
  508. };
  509.  
  510. #endif /* MIEMBRO_H */
  511.  
  512. //Miembro.cpp
  513. #include <iostream>
  514. #include <string.h>
  515. #include "Miembro.h"
  516. #include "CListaT.h"
  517. using namespace std;
  518.  
  519. Miembro::Miembro() {
  520.     codigo = 0;
  521.     nombre = NULL;
  522.     distrito = NULL;
  523. }
  524.  
  525. Miembro::Miembro(const char* _nombre, int _codigo, const char* _distrito) {
  526.     nombre = new char[strlen(_nombre)+1];
  527.     strcpy(nombre, _nombre);
  528.     codigo = _codigo;
  529.     distrito = new char[strlen(_distrito)+1];
  530.     strcpy(distrito, _distrito);
  531. }
  532.  
  533. Miembro::~Miembro(){
  534.     cout << "Destructor miembro.." << endl;
  535.     if (nombre) delete [] nombre;
  536.     if (distrito) delete [] distrito;
  537. }
  538.  
  539. void Miembro::leerDatos(std::istream& in){
  540.     char auxStr[100], distAux[100];
  541.     int id;
  542.     in.getline(auxStr, 100, ',');
  543.     in >> id;
  544.     in.get(); //Sacamos la siguiente coma
  545.     in.getline(distAux, 100, ',');
  546.     setCodigo(id);
  547.     setNombre(auxStr);
  548.     SetDistrito(distAux);
  549.    
  550. }
  551.  
  552. void Miembro::setCodigo(int codigo) {
  553.     this->codigo = codigo;
  554. }
  555.  
  556. int Miembro::getCodigo() const {
  557.     return codigo;
  558. }
  559.  
  560. void Miembro::setNombre(const char* nombre) {
  561.     this->nombre = new char[strlen(nombre)+1];
  562.     strcpy(this->nombre, nombre);
  563. }
  564.  
  565. char* Miembro::getNombre() const {
  566.     char* aux = new char[strlen(this->nombre)+1];
  567.     strcpy(aux, this->nombre);
  568.     return aux;
  569. }
  570.  
  571. void Miembro::SetDistrito(const char* distrito){
  572.     this->distrito = new char[strlen(distrito)+1];
  573.     strcpy(this->distrito, distrito);
  574. }
  575.  
  576. char* Miembro::GetDistrito() const {
  577.     char* aux = new char[strlen(this->distrito)+1];
  578.     strcpy(aux, this->distrito);
  579.     return aux;
  580. }
  581.  
  582. bool Miembro::operator<(const Miembro& objMiembro) {
  583.    
  584.     return this->codigo < objMiembro.codigo;
  585. }
  586.  
  587. bool Miembro::operator>(const Miembro& objMiembro) {
  588.     return not (*this < objMiembro);
  589. }
  590.  
  591. bool Miembro::operator==(const Miembro& objMiembro) {
  592.     return (this->codigo == objMiembro.codigo);
  593. }
  594.  
  595. bool Miembro::operator ==(int codigo){
  596.     return (this->codigo == codigo);
  597. }
  598.  
  599. void Miembro::insertarLibro(Libro& objLib){
  600.     this->lstLibros.insertar(objLib);
  601. }
  602.  
  603. void Miembro::imprimirLibro(std::ostream& archOut){
  604.     this->lstLibros.imprimir(archOut);
  605. }
  606. //Alumno.h
  607. #ifndef ALUMNO_H
  608. #define ALUMNO_H
  609.  
  610. #include "Miembro.h"
  611.  
  612. class Alumno : public Miembro {
  613. private:
  614.     int escala;
  615.     char* especialidad;
  616.     char* facultad;
  617. public:
  618.     Alumno();
  619.     Alumno(const char*, int,const char*, int, const char*, const char*);
  620.     ~Alumno();
  621.     void imprimirDatos(std::ostream&);
  622.     void leerDatos(std::istream&);
  623.  
  624.     void setEspecialidad(const char*);
  625.  
  626.     char* getEspecialidad() const;
  627.  
  628.     void setEscala(int);
  629.  
  630.     int getEscala() const;
  631.    
  632.     void SetFacultad(char*);
  633.    
  634.     char* GetFacultad() const;
  635. };
  636.  
  637. #endif /* ALUMNO_H */
  638.  
  639. //Alumno.cpp
  640. #include <string.h>
  641. #include <fstream>
  642. #include <iostream>
  643. #include "Alumno.h"
  644.  
  645. using namespace std;
  646.  
  647. Alumno::Alumno():
  648.     Miembro() {
  649.     escala = 0;
  650.     especialidad = NULL;
  651.     facultad = NULL;
  652. }
  653.  
  654. Alumno::Alumno(const char* _nombre, int _edad, const char* _distrito, int _escala, const char* _especialidad,const char* _facultad ):
  655.     Miembro(_nombre, _edad, _distrito){
  656.     escala = _escala;
  657.     especialidad = new char[strlen(_especialidad)+1];
  658.     strcpy(especialidad, _especialidad);
  659.    
  660.     facultad = new char[strlen(_facultad)+1];
  661.     strcpy(facultad, _facultad);
  662. }
  663.  
  664. void Alumno::leerDatos(std::istream& in) {
  665.     Miembro::leerDatos(in);
  666.     int escala; char auxEsp[100], fac[100];
  667.     in >> escala;
  668.     in.get();
  669.     in.getline(auxEsp, 100, ',');
  670.     in.getline(fac, 100, '\n');
  671.     this->setEscala(escala);
  672.     this->setEspecialidad(auxEsp);
  673.     this->SetFacultad(fac);
  674. }
  675.  
  676. void Alumno::imprimirDatos(std::ostream& out){
  677.     out << "Codigo del Alumno: " << codigo << endl;
  678.     out << "Nombre del Alumno: " << nombre << endl;
  679.     out << "Escala de pago: " << escala << endl;
  680.     out << "Especialidad: " << especialidad << endl;
  681. }
  682.  
  683.  
  684. Alumno::~Alumno(){
  685.     if (especialidad) delete [] especialidad;
  686.     if (facultad) delete [] facultad;
  687. }
  688.  
  689. void Alumno::setEspecialidad(const char* especialidad) {
  690.     this->especialidad = new char[strlen(especialidad)+1];
  691.     strcpy(this->especialidad, especialidad);
  692. }
  693.  
  694. char* Alumno::getEspecialidad() const {
  695.     char* aux = new char[strlen(this->especialidad)+1];
  696.     strcpy(aux, this->especialidad);
  697.     return aux;
  698. }
  699.  
  700. void Alumno::setEscala(int escala) {
  701.     this->escala = escala;
  702. }
  703.  
  704. int Alumno::getEscala() const {
  705.     return escala;
  706. }
  707.  
  708. void Alumno::SetFacultad(char* s){
  709.     this->facultad = new char[strlen(s)+1];
  710.     strcpy(this->facultad, s);
  711. }
  712.  
  713. char* Alumno::GetFacultad() const {
  714.     char* aux = new char[strlen(this->facultad)+1];
  715.     strcpy(aux, this->facultad);
  716.     return aux;
  717. }
  718.  
  719. //Profesor.h
  720. #ifndef PROFESOR_H
  721. #define PROFESOR_H
  722.  
  723. #include "Miembro.h"
  724.  
  725. class Profesor : public Miembro {
  726. private:
  727.     char* categoria;
  728.     char* dedicacion;
  729.     char* seccion;
  730.     char* grado;
  731. public:
  732.     Profesor();
  733.     Profesor(const char*, int, const char*, const char*, const char*, const char*, const char*);
  734.     ~Profesor();
  735.     void imprimirDatos(std::ostream&);
  736.     void leerDatos(std::istream&);
  737.  
  738.     void setDedicacion(const char*);
  739.  
  740.     char* getDedicacion() const;
  741.  
  742.     void setCategoria(const char*);
  743.  
  744.     char* getCategoria() const;
  745.    
  746.     void SetGrado(char*);
  747.     char* GetGrado() const;
  748.     void SetSeccion(char*);
  749.     char* GetSeccion() const;
  750. };
  751.  
  752. #endif /* PROFESOR_H */
  753.  
  754. //Profesor.cpp
  755. #include <iostream>
  756. #include <fstream>
  757. #include <cstring>
  758. #include "Profesor.h"
  759. using namespace std;
  760.  
  761. Profesor::Profesor() :
  762. Miembro() {
  763.     categoria = NULL;
  764.     dedicacion = NULL;
  765.     seccion = NULL;
  766.     grado = NULL;
  767. }
  768.  
  769. Profesor::Profesor(const char* _nombre, int _edad, const char* _distrito, const char* _categoria, const char* _dedicacion, const char* _seccion, const char* _grado) :
  770. Miembro(_nombre, _edad, _distrito) {
  771.     categoria = new char[strlen(_categoria) + 1];
  772.     strcpy(categoria, _categoria);
  773.  
  774.     dedicacion = new char[strlen(_dedicacion) + 1];
  775.     strcpy(dedicacion, _dedicacion);
  776.    
  777.     seccion = new char[strlen(_seccion) + 1];
  778.     strcpy(dedicacion, _seccion);
  779.    
  780.     grado = new char[strlen(_dedicacion) + 1];
  781.     strcpy(dedicacion, _grado);
  782. }
  783.  
  784. Profesor::~Profesor() {
  785.     if (categoria) delete [] categoria;
  786.     if (dedicacion) delete [] dedicacion;
  787.     if (seccion) delete [] seccion;
  788.     if (grado) delete [] grado;
  789. }
  790.  
  791. void Profesor::imprimirDatos(std::ostream& out) {
  792.     out << "Codigo del Profesor : " << codigo << endl;
  793.     out << "Nombre del Profesor: " << nombre << endl;
  794.     out << "Categoria: " << categoria << endl;
  795.     out << "Dedicacion: " << dedicacion << endl;
  796. }
  797.  
  798. void Profesor::leerDatos(std::istream& in) {
  799.     Miembro::leerDatos(in);
  800.     char cat[100], ded[100], sec[100], grado[100];
  801.     in.getline(cat,100,',');
  802.     in.getline(ded,100,',');
  803.     in.getline(sec,100,',');
  804.     in.getline(grado,100,'\n');
  805.     setCategoria(cat);
  806.     setDedicacion(ded);
  807.     SetSeccion(sec);
  808.     SetGrado(grado);
  809. }
  810.  
  811. void Profesor::setDedicacion(const char* dedicacion) {
  812.     this->dedicacion = new char[strlen(dedicacion) + 1];
  813.     strcpy(this->dedicacion, dedicacion);
  814. }
  815.  
  816. char* Profesor::getDedicacion() const {
  817.     char* aux = new char[strlen(this->dedicacion) + 1];
  818.     strcpy(aux, this->dedicacion);
  819.     return aux;
  820. }
  821.  
  822. void Profesor::setCategoria(const char* categoria) {
  823.     this->categoria = new char[strlen(categoria) + 1];
  824.     strcpy(this->categoria, categoria);
  825. }
  826.  
  827. char* Profesor::getCategoria() const {
  828.     char* aux = new char[strlen(this->categoria) + 1];
  829.     strcpy(aux, this->categoria);
  830.     return aux;
  831. }
  832.  
  833. void Profesor::SetSeccion(char* s) {
  834.     this->seccion = new char[strlen(s) + 1];
  835.     strcpy(this->seccion, s);
  836. }
  837.  
  838. char* Profesor::GetSeccion() const {
  839.     char* aux = new char[strlen(this->seccion) + 1];
  840.     strcpy(aux, this->seccion);
  841.     return aux;
  842. }
  843.  
  844. void Profesor::SetGrado(char* s) {
  845.     this->grado = new char[strlen(s) + 1];
  846.     strcpy(this->grado, s);
  847. }
  848.  
  849. char* Profesor::GetGrado() const {
  850.     char* aux = new char[strlen(this->grado) + 1];
  851.     strcpy(aux, this->grado);
  852.     return aux;
  853. }
  854. //Libro.h
  855. #include <iostream>
  856. using namespace std;
  857.  
  858. #ifndef LIBRO_H
  859. #define LIBRO_H
  860.  
  861. class Libro {
  862. private:
  863.     int codigo;
  864.     char* titulo;
  865.     char* autor;
  866.     char* pais;
  867.  
  868. public:
  869.     Libro();
  870.     ~Libro();
  871.  
  872.     void SetCodigo(int);
  873.     int GetCodigo() const;
  874.    
  875.     void SetTitulo(const char*);    
  876.     char* GetTitulo()const;
  877.    
  878.     void SetAutor(const char*);
  879.     char* GetAutor() const;
  880.    
  881.     void SetPais(const char*);
  882.     char* GetPais() const;
  883.    
  884.     bool operator>(Libro&);
  885.     void L_leerDatos(std::istream&);    
  886.     void L_imprimirDatos(std::ostream&);
  887.    
  888. };
  889. #endif /* LIBRO_H */
  890.  
  891. //Libro.cpp
  892. #include "Libro.h"
  893. #include <iostream>
  894. #include <cstring>
  895. #include <cstdlib>
  896. #include <fstream>
  897. #include <iomanip>
  898. using namespace std;
  899.  
  900. Libro::Libro() {
  901.     codigo = 0;
  902.     titulo = NULL;
  903.     autor = NULL;
  904.     pais = NULL;
  905. }
  906.  
  907. Libro::~Libro(){
  908.     if (titulo) delete[] titulo;
  909.     if (autor) delete[] autor;
  910.     if (pais) delete[] pais;
  911. }
  912.  
  913. void Libro::SetAutor(const char* s) {
  914.     this->autor = new char[strlen(s)+1];
  915.     strcpy(this->autor, s);
  916. }
  917.  
  918. char* Libro::GetAutor() const{
  919.     char* aux = new char[strlen(this->autor) + 1];
  920.     strcpy(aux, this->autor);
  921.     return aux;
  922. }
  923.  
  924. int Libro::GetCodigo() const {
  925.     return this->codigo;
  926. }
  927.  
  928. void Libro::SetCodigo(int codigo) {
  929.     this->codigo = codigo;
  930. }
  931.  
  932. void Libro::SetPais(const char* s) {
  933.     this->pais = new char[strlen(s)+1];
  934.     strcpy(this->pais, s);
  935. }
  936.  
  937. char* Libro::GetPais() const {
  938.     char* aux = new char[strlen(this->pais) + 1];
  939.     strcpy(aux, this->pais);
  940.     return aux;
  941. }
  942.  
  943.  
  944. void Libro::SetTitulo(const char* s) {
  945.     this->titulo = new char[strlen(s)+1];
  946.     strcpy(this->titulo, s);
  947. }
  948.  
  949. char* Libro::GetTitulo() const {
  950.     char* aux = new char[strlen(this->titulo) + 1];
  951.     strcpy(aux, this->titulo);
  952.     return aux;
  953. }
  954.  
  955. void Libro::L_leerDatos(std::istream& in) {
  956.     int codigo;
  957.     char titulo[100], autor[100], pais[100];
  958.     in >> codigo;
  959.     in.get();
  960.     in.getline(titulo,100,',');
  961.     in.getline(autor,100,',');
  962.     in.getline(pais,100,'\n');
  963.     SetCodigo(codigo);
  964.     SetTitulo(titulo);
  965.     SetAutor(autor);
  966.     SetPais(pais);
  967. }
  968.  
  969. void Libro::L_imprimirDatos(std::ostream& out) {
  970.     out << left << setw(10) << this->codigo;
  971.     out << left << setw(30) << this->titulo;
  972.     out << left << setw(40) << this->autor;
  973.     out << this->pais << endl;
  974. }
  975.  
  976. bool Libro::operator >(Libro& otherL){
  977.     return this->codigo > otherL.codigo;
  978. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement