Sunteți pe pagina 1din 20

Proyecto gestion de investigadores

1. OBJETIVOS
Construir y manejar clases y objetos.
Gestión de memoria dinámica.
Sobrecarga de operadores.

2. DESCRIPCIÓN DEL PROBLEMA


Se desea obtener una aplicación que ayude a la gestión de un proyecto de un centro tecnológico, debiendo permitir
modificar los datos básicos de dicho proyecto. La aplicación debe llevar a cabo, además, operaciones básicas (altas,
bajas y modificaciones) de gestión de los investigadores involucrados en dicho proyecto.

3. ESTRUCTURAS DE DATOS
A continuación, se describen los detalles de las funcionalidades de esta aplicación. Se precisará una clase Fecha
para almacenar datos de este tipo.
Estructura de una Fecha
Año Entero
Mes Entero
Dı́a Entero
Para cada investigador, la aplicación gestionará la siguiente información:
Nombre Cadena
Apellidos Cadena
Fecha de ingreso en el proyecto Fecha
Categorı́a Enumerado (becario, contratado, fijo)
Salario Real
Para el proyecto de investigación, la aplicación gestionará la siguiente información:
Nombre Cadena
Presupuesto total Real
Descripción Cadena
Fecha de inicio Fecha
Fecha de finalización Fecha
Investigador principal Puntero a un objeto Investigador
Investigadores Lista dinámica de investigadores

4. IMPLEMENTACIÓN
Será necesario crear una clase Investigador, y otra Proyecto. La clase Fecha permitirá gestionar la fecha de
incorporación al proyecto del investigador, ası́ como las fechas de inicio y fin de proyecto.
La clase ListaInvestigadores se encargará de la gestión (búsquedas, altas, bajas, y modificaciones) de investi-
gadores. Nótese que esta lista es dinámica, es decir, no se sabe a priori el número de investigadores que participan
en él. La lista estará formada por punteros a objetos de la clase Investigador, simplificando de esta forma la gestión
de la misma. Cada posición contendrá un puntero a un objeto de la clase Investigador (los investigadores podrán
referenciarse según su posición en la lista). En caso de que se necesite almacenar un nuevo investigador, será necesario
reservar espacio para el nuevo puntero, crear el objeto y sólo entonces, enlazarlo.

Página 1 de 20
Proyecto gestion de investigadores

En caso de eliminar una posición, se podrá realizar el comportamiento que se desee: eliminar el objeto, reservar
(menos) espacio, y copiar los punteros al nuevo espacio, o eliminar el puntero de la lista y llevar un control de las
posiciones empleadas.
En cualquier caso, deberá ser posible saber el número de investigadores en todo momento, y no deberá haber
huecos en dicha lista.

4.1. Sobrecarga de operadores


Las clases Investigador y Proyecto sobrecargarán el operador <<, de manera que se pueda obtener por la salida
estándar toda la información de un proyecto o de un investigador (lı́neas 10 y 11).
Además, la clase ListaInvestigadores sobrecargará el operador +=, de manera que sea posible añadir un investigador
empleando la sintaxis proyecto.lista += investigador (lı́nea 9).
La misma clase deberá sobrecargar el operador [] para permitir acceder a los investigadores (lı́nea 10), ası́ como
el operador - postfijo (lı́nea 12) para eliminar al investigador de incorporación más reciente.
Por otra parte, la clase Fecha debe sobrecargar los operadores <, > y ==, que actuarán sobre la fecha de incor-
poración al proyecto, de manera que, por ejemplo, se pueda determinar sobre dos investigadores cuál tiene la fecha
de ingreso más reciente en el proyecto, cuál la más tardı́a, y si son iguales, respectivamente.
Finalmente, la clase ListaPersonas sobrecargará el operador = y el constructor de copia.
A continuación se muestra un ejemplo:
Fecha hoy ( 8 , 1 , 2 0 1 0 ) ;
Fecha f i n ( 8 , 1 , 2 0 1 2 ) ;
P r o y e c t o pry ( ” Emigrantes de Ourense ” , hoy , f i n , 1 0 0 0 0 ) ;
I n v e s t i g a d o r i n v e s t i g a d o r 1 ( 6 ” B a l t a s a r ” , ” G ar cı́ a ” , hoy , I n v e s t i g a d o r : : F i j o , 1 0 0 0 ) ;
pry . i n v e s t i g a d o r e s += i n v e s t i g a d o r 1 ;
c o u t << pry . i n v e s t i g a d o r e s [ 0 ] << e n d l ;
c o u t << pry << e n d l ;
pry . i n v e s t i g a d o r e s −−;
c o u t << pry << e n d l ;

4.2. Funcionalidad
La aplicación mostrará inicialmente la información del proyecto (exceptuando los investigadores participantes),
con un menú a continuación que detalle las opciones que se explican más abajo. En el caso de que sea necesario
escoger entre más opciones en un momento dado, estas se mostrarán a modo de menú igualmente.
En todo momento se deberá validar que el usuario selecciona alguna de las opciones disponibles, mostrando, en
caso contrario, un mensaje de error y volviendo a mostrar el menú.
La gestión del proyecto debe permitir realizar las siguientes operaciones:

Modificar datos del proyecto Soportará la edición de los datos básicos del proyecto.

Alta de investigador Permitirá dar de alta un nuevo investigador en el proyecto. Debe pedir los datos del nuevo
investigador, y mostrarlos una vez introducidos. Si el investigador es el investigador principal, se sustituirá al
que ya hubiera en ese momento por este. Si sólo hay un investigador, se hará a este investigador principal
obligatoriamente.

Baja de investigador Solicitará al usuario el número de investigador (su posición en la lista). Si el número no es
válido, mostrará un mensaje indicándolo. En caso contrario, mostrará los datos del investigador en cuestión,
pidiendo confirmación al usuario para su eliminación.

Eliminar al investigador más reciente Buscará al investigador que se ha incorporado más recientemente al
proyecto, y lo eliminará, como si se tratara de una baja. El programa debe listar el grupo de investigadores
resultante para el proyecto.

Listar investigadores Visualizar en pantalla una lista de todos los investigadores (número, apellidos, y nombre).

Modificar datos de investigador Pedirá al usuario el número de un investigador y permitirá modificar cualquiera
de sus datos, a excepción de dicho número. Después de modificar los datos, se mostrará por pantalla toda la
información referente al investigador.

Página 2 de 20
Proyecto gestion de investigadores

5. Cambios bloque II
Modificar el proyecto del bloque I para trabajar los siguientes aspectos:
1. Herencia
2. Polimorfismo dinámico
3. Contenedores de objetos: STL
4. Excepciones

5.1. Herencia
Los tres tipos de investigadores de un proyecto (Becario, Contratado y Fijo) se van a implementar en clases
independientes. Los becarios son investigadores que van a disponer de una beca que durará un número determinado
de meses y su salario será una cantidad fija al mes. Los contratados son investigadores vinculados al proyecto durante
un número determinado de dı́as, y su salario será en función de los dı́as trabajados. Los investigadores fijos tendrán
como salario un porcentaje del presupuesto global del proyecto.

5.2. Polimorfismo dinámico


La clase ListaInvestigadores tendrá que gestionar un número variable de investigadores que podrán ser o bien
becarios, contratados o fijos. La función toString y calcularSalario serán especı́ficas para cada clase. La funcionalidad
de listar investigadores y una nueva para listar el salario de todos los investigadores tendrán que utilizar ligadura
dinámica.

5.3. STL
Para implementar la clase ListaInvestigadores sustituir se debe el array dinámico de punteros a objetos de tipo
investigador por un vector de la STL. Para conseguir la requerida ligadura dinámica del apartado anterior el tipo base
del contenedor tiene que ser un puntero a la clase Investigador (que va a poder apuntar a objetos de las clases Becario,
Investigador o Fijo). Realizar todos los cambios oportunos para mantener las mismas funcionalidades requeridas en
el proyecto del Bloque I, añadiendo una nueva para listar el salario de todos los investigadores.

5.4. Excepciones
Todos los errores que anteriormente se mostraban por consola y hacı́an que el programa se detuviera, deben ser
gestionados mediante excepciones.

Solución:
Base.h

#i f n d e f BASE H INCLUDED
#define BASE H INCLUDED
using namespace s t d ;
#include <i o s t r e a m >
#include <sstream >
#include <s t d e x c e p t >
#include <l i m i t s >
#include <v e c t o r >
class Investigador ;
class Becario ;
c l a s s Contratado ;
class Fijo ;
c l a s s Fecha ;
// c l a s s L i s t a I n v e s t i g a d o r e s ;
class ListaInvestigadoresVector ;
class Proyecto ;
class FechaIncorrecta ;

Página 3 de 20
Proyecto gestion de investigadores

#include ” E x c e p c i o n e s . h”
void a l e r t a ( s t r i n g t e x t o ) ;
void r e s e t ( ) ;
int getNum ( s t r i n g prompt=”Numero” ) ;
s t r i n g g e t S t r i n g ( s t r i n g prompt=”Cadena” ) ;
Fecha getFecha ( s t r i n g prompt=” Fecha ” ) ;

#endif // BASE H INCLUDED

Base.cpp

#include ” Base . h”
#include ” Fecha . h”
void a l e r t a ( s t r i n g t e x t o ) {
c o u t << e n d l
<< ”−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−” << e n d l
<< t e x t o << e n d l << e n d l
<< ”−−−I n t r o para c o n t i n u a r −−−−−−−” << e n d l ;
cin . clear () ;
cin . get () ;
}
void r e s e t ( ) {
cin . clear () ;
c i n . i g n o r e ( n u m e r i c l i m i t s <int > : : max ( ) , ’ \n ’ ) ;
}
int getNum ( s t r i n g prompt ) {
c o u t << e n d l << prompt << ” : ” ;
int num = 0 ;
cin . exceptions ( i o s : : f a i l b i t | i o s : : badbit ) ;
c i n >> num ;
cin . ignore () ;
return num ;
}
s t r i n g g e t S t r i n g ( s t r i n g prompt ) {
c o u t << e n d l << prompt << ” : ” ;
s t r i n g cad ;
g e t l i n e ( c i n , cad ) ;
return cad ;
}
Fecha getFecha ( s t r i n g prompt ) {
c o u t << e n d l << prompt << ” : ” ;
int dia , mes , y e a r ;
d i a = getNum ( ” Dia ” ) ;
mes = getNum ( ”Mes” ) ;
y e a r = getNum ( ”Anno” ) ;
Fecha f ( dia , mes , y e a r ) ;
f . comprobar ( ) ;
return f ;
}

Becario.h

#i f n d e f BECARIO H INCLUDED
#define BECARIO H INCLUDED
#include ” Base . h”
#include ” I n v e s t i g a d o r . h”

Página 4 de 20
Proyecto gestion de investigadores

c l a s s B e c a r i o : public I n v e s t i g a d o r {
public :
B e c a r i o ( s t r i n g nombre , s t r i n g a p e l l i d o s , Fecha f e c h a , int c a n t i d a d ) ;
float getSalario () ;
s t r i n g getToString () ;
Investigador ∗ copiarInvestigador () ;
i s t r e a m & r e a d ( i s t r e a m &) ;

private :
float cantidad ;
};

#endif // BECARIO H INCLUDED

Becario.cpp

#include ” B e c a r i o . h”
#include<i o s t r e a m >
#include<sstream >
B e c a r i o : : B e c a r i o ( s t r i n g nombre , s t r i n g a p e l l i d o s , Fecha f e c h a , int c a n t i d a d )
: I n v e s t i g a d o r ( nombre , a p e l l i d o s , f e c h a ) , c a n t i d a d ( c a n t i d a d ) {

}
float Becario : : ge t S al ar i o () {
Fecha f = getFecha ( ) ;
int meses=getEntr ada ( ) . difEnMeses ( f ) ;
return meses ∗ c a n t i d a d ;
}
Investigador ∗ Becario : : copiarInvestigador () {
I n v e s t i g a d o r ∗ i n v=new B e c a r i o ( ∗ t h i s ) ;
return i n v ;
}
s t r i n g Becario : : getToString () {
stringstream st ;
s t << I n v e s t i g a d o r : : g e t T o S t r i n g ( ) ;
s t << ” Cantidad : ” << c a n t i d a d << e n d l ;
return s t . s t r ( ) ;
}
istream & Becario : : read ( istream & i ) {
I n v e s t i g a d o r : : read ( i ) ;
i >> c a n t i d a d ;
i . ignore () ;
return i ;
}

Contratado.h

#i f n d e f CONTRATADO H INCLUDED
#define CONTRATADO H INCLUDED

#include ” Base . h”
#include ” I n v e s t i g a d o r . h”
c l a s s Contratado : public I n v e s t i g a d o r {
public :
Contratado ( s t r i n g nombre , s t r i n g a p e l l i d o s , Fecha f e c h a , int c a n t i d a d ) ;
float getSalario () ;

Página 5 de 20
Proyecto gestion de investigadores

s t r i n g getToString () ;
Investigador ∗ copiarInvestigador () ;
i s t r e a m & r e a d ( i s t r e a m &) ;

private :
float cantidad ;
};

#endif // CONTRATADO H INCLUDED

Contratado.cpp

#include ” Contratado . h”
#include<i o s t r e a m >
#include<sstream >
using namespace s t d ;
Contratado : : Contratado ( s t r i n g nombre , s t r i n g a p e l l i d o s , Fecha f e c h a , int c a n t i d a d
)
: I n v e s t i g a d o r ( nombre , a p e l l i d o s , f e c h a ) , c a n t i d a d ( c a n t i d a d ) {

}
f l o a t Contratado : : g e t S a l a r i o ( ) {
Fecha f= getFecha ( ) ;
float cantidad ;
int meses=getEntr ada ( ) . difEnMeses ( f ) ;
cout<<” I n t r o d u z a l a c a n t i d a d ”<<e n d l ;
c i n >>c a n t i d a d ;
return meses ∗ c a n t i d a d ;
}
I n v e s t i g a d o r ∗ Contratado : : c o p i a r I n v e s t i g a d o r ( ) {
I n v e s t i g a d o r ∗ i n v=new Contratado ( ∗ t h i s ) ;
return i n v ;
}
s t r i n g Contratado : : g e t T o S t r i n g ( ) {
stringstream st ;
s t << I n v e s t i g a d o r : : g e t T o S t r i n g ( ) ;
s t << ” Cantidad : ” << c a n t i d a d ;
return s t . s t r ( ) ;
}
i s t r e a m & Contratado : : r e a d ( i s t r e a m & i ) { I n v e s t i g a d o r : : r e a d ( i ) ;
i >> c a n t i d a d ;
i . ignore () ;
return i ;
}

Fecha.h

#i f n d e f FECHA H INCLUDED
#define FECHA H INCLUDED
#include ” Base . h”

c l a s s Fecha {
public :
Fecha ( int d i a =1, int mes=1, int y e a r =1900) ;
int getYear ( ) ;

Página 6 de 20
Proyecto gestion de investigadores

int getMes ( ) ;
int g e t D i a ( ) ;
string toString () ;
bool operator >(Fecha&) ;
int d i f E n D i a s ( Fecha f ) ;
int difEnMeses ( Fecha f ) ;
void comprobar ( ) ;
bool e s Y e a r B i s i e s t o ( ) ;

private :
int y e a r ;
int mes ;
int d i a ;
friend i s t r e a m & operator >>(i s t r e a m &, Fecha &) ;
friend ostream & operator <<(ostream &out , Fecha f ) ;

};
#endif // FECHA H INCLUDED

Fecha.cpp

#include ” Fecha . h”
using namespace s t d ;

Fecha : : Fecha ( int dia , int mes , int y e a r ) {


this−>d i a = d i a ;
this−>mes = mes ;
this−>y e a r = y e a r ;
comprobar ( ) ;
}
int Fecha : : getYear ( ) {
return y e a r ;
}
int Fecha : : getMes ( ) {
return mes ;
}
int Fecha : : g e t D i a ( ) {
return d i a ;
}
bool Fecha : : operator >(Fecha &f ) {
return ( ( y e a r ∗ 365+ mes ∗ 31 + d i a ) > ( f . y e a r ∗365+ f . mes∗31+ f . d i a ) ) ;
}
s t r i n g Fecha : : t o S t r i n g ( ) {
stringstream st ;
st
<<” ” << g e t D i a ( )
<<”/” << getMes ( )
<<”/” << getYear ( ) << ” ” << e n d l ;
return s t . s t r ( ) ;

}
ostream & operator <<(ostream &out , Fecha f ) {
out << f . d i a << ” ” ;
out << f . mes << ” ” ;
out << f . year<< ” ” ;
return out ;
}

Página 7 de 20
Proyecto gestion de investigadores

int Fecha : : d i f E n D i a s ( Fecha f ) {


int d i a s=y e a r ∗ 365+ mes ∗ 31 + d i a ;
int d i a s F=f . y e a r ∗ 365+ f . mes ∗ 31 + f . d i a ;
return d i a s −d i a s F ;
}
int Fecha : : difEnMeses ( Fecha f ) {
int meses=y e a r ∗ 12+ mes ;
int mesesF=f . y e a r ∗ 12+ f . mes ;
return meses−mesesF ;
}
void Fecha : : comprobar ( ) {
i f ( year < 0) {
throw F e c h a I n c o r r e c t a ( ”Anno i n c o r r e c t o ” ) ;
} e l s e i f ( ( mes < 0 ) | | ( mes > 1 2 ) ) {
throw F e c h a I n c o r r e c t a ( ”Mes i n c o r r e c t o ” ) ;
} else i f ( dia < 0) {
throw F e c h a I n c o r r e c t a ( ” Dia i n c o r r e c t o ” ) ;
} else {
switch ( mes ) {
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 1 0 :
case 1 2 :
i f ( dia > 31) {
throw F e c h a I n c o r r e c t a ( ” Dia i n c o r r e c t o ” ) ;
}
break ;
case 2 :
i f ( dia > 29) {
throw F e c h a I n c o r r e c t a ( ” Dia i n c o r r e c t o ” ) ;
} e l s e i f ( ( d i a == 2 9 ) &&(! e s Y e a r B i s i e s t o ( ) ) ) {
throw F e c h a I n c o r r e c t a ( ” Dia i n c o r r e c t o ” ) ;
}
break ;
default :
i f ( d i a >30){
throw F e c h a I n c o r r e c t a ( ” Dia i n c o r r e c t o ” ) ;
}
}
}
}

bool Fecha : : e s Y e a r B i s i e s t o ( ) {
bool b i s i e s t o = f a l s e ;
i f ( ( y e a r % 4 ) == 0 ) {
i f ( ( y e a r % 1 0 0 ) == 0 ) {
i f ( ( y e a r % 4 0 0 ) == 0 ) {
b i s i e s t o = true ;
}
} else {
b i s i e s t o = true ;
}
}
return b i s i e s t o ;

Página 8 de 20
Proyecto gestion de investigadores

Fijo.h

#i f n d e f FIJO H INCLUDED
#define FIJO H INCLUDED
#include ” Base . h”
#include ” I n v e s t i g a d o r . h”
#include ” P r o y e c t o . h”
#include ” Fecha . h”

c l a s s F i j o : public I n v e s t i g a d o r
{
public :
F i j o ( s t r i n g nombre , s t r i n g a p e l l i d o s , Fecha f e c h a , f l o a t p o r c e n t a j e ) ;
float getSalario () ;
s t r i n g getToString () ;
Investigador ∗ copiarInvestigador () ;
i s t r e a m & r e a d ( i s t r e a m &) ;

private :
float presupuesto ;
float porcentaje ;
};

#endif // FIJO H INCLUDED

Fijo.cpp

#include ” F i j o . h”
#include <sstream >

F i j o : : F i j o ( s t r i n g nombre , s t r i n g a p e l l i d o s , Fecha f e c h a , f l o a t p o r c e n t a j e )
: I n v e s t i g a d o r ( nombre , a p e l l i d o s , f e c h a ) , p o r c e n t a j e ( p o r c e n t a j e ) {

}
float Fijo : : getSalario () {
return p r o y e c t o −>g e t P r e s u p u e s t o ( ) ∗ p o r c e n t a j e ;
}
Investigador ∗ Fijo : : copiarInvestigador () {
I n v e s t i g a d o r ∗ i n v=new F i j o ( ∗ t h i s ) ;
return i n v ;
}
s t r i n g Fijo : : getToString () {
stringstream st ;
s t << I n v e s t i g a d o r : : g e t T o S t r i n g ( ) ;
s t << ” P o r c e n t a j e : ” << p o r c e n t a j e << e n d l ;
s t << ” P r e s u p u e s t o : ” << p r o y e c t o −>g e t P r e s u p u e s t o ( ) ;
return s t . s t r ( ) ;

}
istream & F i j o : : read ( istream & i ) {
I n v e s t i g a d o r : : read ( i ) ;
i >> p o r c e n t a j e ;
i . ignore () ;
return i ;
}

Página 9 de 20
Proyecto gestion de investigadores

Investigador.h

#i f n d e f INVESTIGADOR H INCLUDED
#define INVESTIGADOR H INCLUDED
#include ” Base . h”
#include ” Fecha . h”

class Investigador {
public :
I n v e s t i g a d o r ( const I n v e s t i g a d o r & i ) ;
I n v e s t i g a d o r ( s t r i n g nombre , s t r i n g a p e l l i d o s , Fecha f e c h a ) ;
s t r i n g &getNombre ( ) ;
s t r i n g& g e t A p e l l i d o s ( ) ;
v i r t u a l f l o a t g e t S a l a r i o ( ) =0;
virtual ˜ I n v e s t i g a d o r ( ) ;
Fecha& getEntr ada ( ) ;
void s e t P r o y e c t o ( P r o y e c t o ∗ ) ;
virtual s t r i n g getToString ( ) ;
v i r t u a l i s t r e a m & r e a d ( i s t r e a m &) ;
v i r t u a l I n v e s t i g a d o r ∗ c o p i a r I n v e s t i g a d o r ( ) =0; // ¿ ??

protected :
s t r i n g nombre ;
string apellidos ;
Fecha e n t r a d a ;
Proyecto ∗ proyecto ;
friend i s t r e a m & operator>>(i s t r e a m &, I n v e s t i g a d o r ∗ ) ;
friend ostream & operator<<(ostream &, I n v e s t i g a d o r ∗ ) ;

};

#endif // INVESTIGADOR H INCLUDED


Investigador.cpp

#include ” I n v e s t i g a d o r . h”
#include<i o s t r e a m >
#include<sstream >
using namespace s t d ;
I n v e s t i g a d o r : : I n v e s t i g a d o r ( const I n v e s t i g a d o r& i ) {
nombre = i . nombre ;
apellidos = i . apellidos ;
entrada = i . entrada ;
proyecto = i . proyecto ;
}
I n v e s t i g a d o r : : I n v e s t i g a d o r ( s t r i n g nombre , s t r i n g a p e l l i d o s , Fecha f e c h a ) {
this−>nombre = nombre ;
this−>a p e l l i d o s = a p e l l i d o s ;
this−>e n t r a d a = f e c h a ;
this−>p r o y e c t o = 0 ;

}
Investigador : : ˜ Investigador () {
}
s t r i n g &I n v e s t i g a d o r : : getNombre ( ) {
return nombre ;
}

Página 10 de 20
Proyecto gestion de investigadores

s t r i n g &I n v e s t i g a d o r : : g e t A p e l l i d o s ( ) {
return a p e l l i d o s ;
}

Fecha &I n v e s t i g a d o r : : getEntr ada ( ) {


return e n t r a d a ;
}
void I n v e s t i g a d o r : : s e t P r o y e c t o ( P r o y e c t o ∗ p r o y e c t o ) {
this−>p r o y e c t o = p r o y e c t o ;
}

s t r i n g Investigador : : getToString () {
stringstream st ;
s t << e n d l
<<”Nombre : ” << getNombre ( ) << e n d l
<<” A p e l l i d o s : ”<< g e t A p e l l i d o s ( ) << e n d l
<<” Fecha : ” << getEntr ada ( ) . t o S t r i n g ( ) << e n d l ;

return s t . s t r ( ) ;
}

ostream & operator<<(ostream & out , I n v e s t i g a d o r ∗ i ) {


out<< i −>g e t T o S t r i n g ( ) ;
return out ;
}
istream & I n v e s t i g a d o r : : read ( istream & i ) {
g e t l i n e ( i , nombre ) ;
getline ( i , apellidos ) ;
e n t r a d a = getFecha ( ) ;
return i ;
}
i s t r e a m & operator>>(i s t r e a m &i , I n v e s t i g a d o r ∗ i n v ) {
return inv−>r e a d ( i ) ;
}

ListaInvestigadores.h

#i f n d e f LISTAINVESTIGADORES H INCLUDED
#define LISTAINVESTIGADORES H INCLUDED
#include ” Base . h”
#include ” I n v e s t i g a d o r . h”
class ListaInvestigadores {
private :
I n v e s t i g a d o r ∗∗ v e c t o r ;
unsigned int tamano ;
unsigned int c a p a c i d a d ;

public :
ListaInvestigadores () ;
L i s t a I n v e s t i g a d o r e s ( const L i s t a I n v e s t i g a d o r e s & l ) ;
˜ ListaInvestigadores () ;
I n v e s t i g a d o r ∗ g e t ( int pos ) ;
void i n s e r t a r ( I n v e s t i g a d o r ∗ i ) ;
void e l i m i n a r ( int pos ) ;
void e l i m i n a r U l t i m o ( ) ;
void s e t ( I n v e s t i g a d o r ∗ i , unsigned int pos ) ;
unsigned int s i z e ( ) ;

Página 11 de 20
Proyecto gestion de investigadores

s t r i n g getToString () ;

};
#endif // LISTAINVESTIGADORES H INCLUDED

ListaInvestigadores.cpp

#include ” Base . h”
#include ” L i s t a I n v e s t i g a d o r e s . h”
using namespace s t d ;
ListaInvestigadores : : ListaInvestigadores () {
tamano = 0 ;
capacidad = 10;
v e c t o r = new I n v e s t i g a d o r ∗ [ c a p a c i d a d ] ;
}
ListaInvestigadores : : ˜ ListaInvestigadores () {
f or ( unsigned int n = 0 ; n< tamano ; n++) {
delete v e c t o r [ n ] ;
}
delete [ ] v e c t o r ;
}
L i s t a I n v e s t i g a d o r e s : : L i s t a I n v e s t i g a d o r e s ( const L i s t a I n v e s t i g a d o r e s & l ) {
tamano = l . tamano ;
capacidad = l . capacidad ;
v e c t o r = new I n v e s t i g a d o r ∗ [ c a p a c i d a d ] ;
f or ( unsigned int n = 0 ; n < tamano ; n++) {
v e c t o r [ n ] =l . v e c t o r [ n]−> c o p i a r I n v e s t i g a d o r ( ) ;
}
}
I n v e s t i g a d o r ∗ L i s t a I n v e s t i g a d o r e s : : g e t ( int pos ) {
return v e c t o r [ pos ] ;
}
void L i s t a I n v e s t i g a d o r e s : : i n s e r t a r ( I n v e s t i g a d o r ∗ i ) {
i f ( tamano > c a p a c i d a d ) {
I n v e s t i g a d o r ∗∗ p = new I n v e s t i g a d o r ∗ [ c a p a c i d a d ∗ 2 ] ;
f or ( unsigned int n = 0 ; n< tamano ; n++) {
p [ n ] = vector [ n ] ;
}
delete [ ] v e c t o r ;
vector = p ;
c a p a c i d a d ∗=2;
}
v e c t o r [ tamano ] = i ;
tamano ++;
}

void L i s t a I n v e s t i g a d o r e s : : e l i m i n a r ( int pos ) {


delete v e c t o r [ pos ] ;

f or ( unsigned int n = pos ; n< s i z e ( ) −1; n++) {


s e t ( g e t ( n+1) , n ) ;
}
tamano−−;
}
void L i s t a I n v e s t i g a d o r e s : : e l i m i n a r U l t i m o ( ) {
Fecha maxFecha = g e t ( 0 )−>getEntr ada ( ) ;
int numUltimo = 0 ; //Numero d e l i n v de maxima f e c h a

Página 12 de 20
Proyecto gestion de investigadores

f or ( unsigned int n = 0 ; n < s i z e ( ) ; n++) {


i f ( g e t ( n )−>getEntr ada ( ) > maxFecha ) {
numUltimo = n ;
maxFecha = g e t ( n )−>getEntr ada ( ) ;
}
}
delete v e c t o r [ numUltimo ] ;
f or ( unsigned int n = numUltimo ; n< s i z e ( ) −1; n++) {
s e t ( g e t ( n+1) , n ) ;
}
tamano−−;
}
void L i s t a I n v e s t i g a d o r e s : : s e t ( I n v e s t i g a d o r ∗ i , unsigned int pos ) {
i f ( pos < tamano ) {
v e c t o r [ pos ] = i ;
} else {
c o u t << ” P o s i c i o n i n c o r r e c t a ” << e n d l ;
}
}
unsigned int L i s t a I n v e s t i g a d o r e s : : s i z e ( ) {
return tamano ;
}
s t r i n g L i s t a I n v e s t i g a d o r e s : : getToString () {
stringstream ss ;
f or ( unsigned int n = 0 ; n< tamano ; n++) {
s s << v e c t o r [ n]−> g e t T o S t r i n g ( ) ;
}
return s s . s t r ( ) ;
}

ListaInvestigadoresVector.h

#i f n d e f LISTAINVESTIGADORESVECTOR H INCLUDED
#define LISTAINVESTIGADORESVECTOR H INCLUDED
#include ” Base . h”
#include ” I n v e s t i g a d o r . h”

class ListaInvestigadoresVector {
public :
ListaInvestigadoresVector () ;
v e c t o r <I n v e s t i g a d o r ∗> d a t o s ;
˜ ListaInvestigadoresVector () ;
I n v e s t i g a d o r ∗ g e t ( int pos ) ;
void s e t ( I n v e s t i g a d o r ∗ i , unsigned int pos ) ;
unsigned int s i z e ( ) ;
s t r i n g getToString () ;
void i n s e r t a r ( I n v e s t i g a d o r ∗ i ) ;
void e l i m i n a r ( int pos ) ;
void e l i m i n a r U l t i m o ( ) ;

private :
L i s t a I n v e s t i g a d o r e s V e c t o r ( const L i s t a I n v e s t i g a d o r e s V e c t o r &) ;
};

#endif // LISTAINVESTIGADORESVECTOR H INCLUDED

ListaInvestigadoresVector.cpp

Página 13 de 20
Proyecto gestion de investigadores

#include ” Base . h”
#include ” L i s t a I n v e s t i g a d o r e s V e c t o r . h”
using namespace s t d ;
ListaInvestigadoresVector : : ListaInvestigadoresVector () {

}
ListaInvestigadoresVector : : ˜ ListaInvestigadoresVector () {
v e c t o r <I n v e s t i g a d o r ∗ >:: i t e r a t o r i ;
f or ( i = d a t o s . b e g i n ( ) ; i != d a t o s . end ( ) ; i ++) {
delete ∗ i ;
}
}
L i s t a I n v e s t i g a d o r e s V e c t o r : : L i s t a I n v e s t i g a d o r e s V e c t o r ( const
ListaInvestigadoresVector & l ) {
// no s e d e b e e j e c u t a r en ningun momento . Lo hacemos p r i v a t e para o b s e r v a r l o .
}
I n v e s t i g a d o r ∗ L i s t a I n v e s t i g a d o r e s V e c t o r : : g e t ( int pos ) {
return d a t o s [ pos ] ;
}
void L i s t a I n v e s t i g a d o r e s V e c t o r : : i n s e r t a r ( I n v e s t i g a d o r ∗ i ) {
d a t o s . push back ( i ) ;
}

void L i s t a I n v e s t i g a d o r e s V e c t o r : : e l i m i n a r ( int pos ) {


delete d a t o s [ pos ] ;
d a t o s . e r a s e ( d a t o s . b e g i n ( )+pos ) ;
}
void L i s t a I n v e s t i g a d o r e s V e c t o r : : e l i m i n a r U l t i m o ( ) {
Fecha maxFecha = g e t ( 0 )−>getEntr ada ( ) ;
int numUltimo = 0 ; //Numero d e l i n v de maxima f e c h a
f or ( unsigned int n = 0 ; n < d a t o s . s i z e ( ) ; n++) {
i f ( g e t ( n )−>getEntr ada ( ) > maxFecha ) {
numUltimo = n ;
maxFecha = g e t ( n )−>getEntr ada ( ) ;
}
}
e l i m i n a r ( numUltimo ) ;
}
void L i s t a I n v e s t i g a d o r e s V e c t o r : : s e t ( I n v e s t i g a d o r ∗ i , unsigned int pos ) {
i f ( pos < d a t o s . s i z e ( ) ) {
d a t o s [ pos ] = i ;
} else {
c o u t << ” P o s i c i o n i n c o r r e c t a ” << e n d l ;
}
}
unsigned int L i s t a I n v e s t i g a d o r e s V e c t o r : : s i z e ( ) {
return d a t o s . s i z e ( ) ;
}
s t r i n g ListaInvestigadoresVector : : getToString () {
stringstream ss ;
f or ( unsigned int n = 0 ; n< d a t o s . s i z e ( ) ; n++) {
s s << d a t o s [ n]−> g e t T o S t r i n g ( ) ;
}
return s s . s t r ( ) ;
}

Main.h

Página 14 de 20
Proyecto gestion de investigadores

#i f n d e f MAIN H INCLUDED
#define MAIN H INCLUDED
#include ” Base . h”
#include ” I n v e s t i g a d o r . h”
#include ” L i s t a I n v e s t i g a d o r e s . h”
#include ” P r o y e c t o . h”
#include ” B e c a r i o . h”
#include ” Contratado . h”
#include ” F i j o . h”
void a l t a I n v e s t i g a d o r ( P r o y e c t o & p r o y e c t o ) ;
void m o d i f i c a r D a t o s P r o y e c t o ( P r o y e c t o & p r o y e c t o ) ;
void b a j a I n v e s t i g a d o r ( P r o y e c t o & p r o y e c t o ) ;
void e l i m i n a r I n v e s t i g a d o r R e c ( P r o y e c t o & p r o y e c t o ) ;
void l i s t a r I n v e s t i g a d o r e s ( P r o y e c t o & p r o y e c t o ) ;
void m o f i c a r D a t o s I n v e s t i g a d o r ( P r o y e c t o & p r o y e c t o ) ;
#endif

Main.cpp

#include ”Main . h”
int main ( ) {
Proyecto proyecto ;
int o p c i o n =−1;
do {
try {
cout<<” −−−−−−− GESTION DE PROYECTO TECNOLOGICO −−−−−−−−−−”<<endl<<
endl ;
c o u t << p r o y e c t o . g e t T o S t r i n g ( ) ;
c o u t << ”−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−”<<e n d l ;
cout<<” 1 : M o d i f i c a r p r o y e c t o ”<<e n d l ;
cout<<” 2 : Agregar i n v e s t i g a d o r ”<<e n d l ;
cout<<” 3 : E l i m i n a r i v e s t i g a d o r ”<<e n d l ;
cout<<” 4 : E l i m i n a r u l t i m o i n v e s t i g a d o r ”<<e n d l ;
cout<<” 5 : M o d i f i c a r un i n v e s t i g a d o r ”<<e n d l ;
cout<<” 6 : L i s t a r i n v e s t i g a d o r e s ”<<e n d l ;
cout<<” 0 : S a l i r ”<<e n d l ;
o p c i o n = getNum ( ” Opcion ” ) ;
switch ( o p c i o n ) {
case 1 :
modificarDatosProyecto ( proyecto ) ;
break ;
case 2 :
altaInvestigador ( proyecto ) ;
break ;
case 3 :
bajaInvestigador ( proyecto ) ;
break ;
case 4 :
eliminarInvestigadorRec ( proyecto ) ;
break ;
case 5 :
moficarDatosInvestigador ( proyecto ) ;
break ;
case 6 :
l i s t a r I n v e s t i g a d o r e s ( proyecto ) ;
break ;
case 0 :

Página 15 de 20
Proyecto gestion de investigadores

return 0 ;
}
} catch ( i o s b a s e : : f a i l u r e e ) {
reset () ;
a l e r t a ( s t r i n g ( ” E r r o r en l a e n t r a d a de d a t o s : ” )+e . what ( ) ) ;
} catch ( F e c h a I n c o r r e c t a e ) {
reset () ;
a l e r t a ( s t r i n g ( ”La f e c h a e s i n c o r r e c t a : ” )+e . what ( ) ) ;
} catch ( e x c e p t i o n e ) {
reset () ;
a l e r t a ( s t r i n g ( ” Excepcion d e s c o n o c i d a : ” )+ e . what ( ) ) ;
}
} while ( o p c i o n !=0) ;
}

void m o d i f i c a r D a t o s P r o y e c t o ( P r o y e c t o & p r o y e c t o ) {
int numero =0;
int numInv = 0 ;

do {
cout<<”Que dato d e s e a m o d i f i c a r ”<<e n d l ;
cout<<” 1 : Nombre”<<e n d l ;
cout<<” 2 : D e s c r i p c i o n ”<<e n d l ;
cout<<” 3 : Fecha i n i c i o ”<<e n d l ;
cout<<” 4 : Fecha f i n ”<<e n d l ;
cout<<” 5 : I n v e s t i g a d o r p r i n c i p a l ”<<e n d l ;
cout<<” 0 : V o l v e r ”<<e n d l ;
numero = getNum ( ” Opcion ” ) ;
switch ( numero ) {
case 1 :
p r o y e c t o . getNombre ( ) = g e t S t r i n g ( ”Nuevo nombre” ) ;
break ;
case 2 :
p r o y e c t o . g e t D e s c r i p c i o n ( ) = g e t S t r i n g ( ”Nueva d e s c r i p c i o n ” ) ;
break ;
case 3 :
p r o y e c t o . g e t I n i c i o ( ) = getFecha ( ” Fecha de i n i c i o ” ) ;
break ;
case 4 :
p r o y e c t o . g e t F i n ( ) = getFecha ( ” Fecha de f i n a l i z a c i o n ” ) ;
break ;
case 5 :
i f ( p r o y e c t o . g e t I n v e s t i g a d o r e s ( ) . s i z e ( ) <1) {
a l e r t a ( ”No hay i n v e s t i g a d o r e s almacenados ” ) ;
} else {
l i s t a r I n v e s t i g a d o r e s ( proyecto ) ;
numInv = getNum ( ”Numero de nuevo i n v e s t i g a d o r p r i n c i p a l ” ) ;
i f ( numInv < p r o y e c t o . g e t I n v e s t i g a d o r e s ( ) . s i z e ( ) ) {
p r o y e c t o . s e t I n v e s t i g a d o r P p a l ( p r o y e c t o . g e t I n v e s t i g a d o r e s ( ) . g e t ( numInv ) ) ;
} else {
a l e r t a ( ”No hay t a n t o s i n v e s t i g a d o r e s ” ) ;
}
break ;
}
case 0 : // v o l v e r a l menú
break ;
}

Página 16 de 20
Proyecto gestion de investigadores

} while ( numero !=0) ;


}
void a l t a I n v e s t i g a d o r ( P r o y e c t o & p r o y e c t o ) {
Investigador ∗ inv = 0;
s t r i n g nombre , a p e l l i d o s ;
int c a n t i d a d ;
Fecha f e c h a ;
nombre = g e t S t r i n g ( ”Nombre” ) ;
apellidos = getString (” Apellidos ”) ;
f e c h a = getFecha ( ” Fecha de a l t a ” ) ;

int num ;
num = getNum ( ” Tipo de empleado ( 0 : b e c a r i o , 1 : c o n t r a t a d o , 2 : f i j o ) ” ) ;
switch (num) {
case 0 :
c a n t i d a d = getNum ( ” Cantidad f i j a por mes” ) ;
i n v = new B e c a r i o ( nombre , a p e l l i d o s , f e c h a , c a n t i d a d ) ;
break ;
case 1 :
c a n t i d a d = getNum ( ” Cantidad f i j a por mes” ) ;
i n v = new Contratado ( nombre , a p e l l i d o s , f e c h a , c a n t i d a d ) ;
break ;
case 2 :
c a n t i d a d = getNum ( ” P o r c e n t a j e ” ) ;
i n v = new F i j o ( nombre , a p e l l i d o s , f e c h a , c a n t i d a d ) ;
break ;
}
i f ( inv ) {
proyecto . g e t I n v e s t i g a d o r e s () . i n s e r t a r ( inv ) ;
inv−>s e t P r o y e c t o (& p r o y e c t o ) ;
i f ( p r o y e c t o . g e t I n v e s t i g a d o r e s ( ) . s i z e ( ) == 1 ) {
proyecto . setInvestigadorPpal ( inv ) ;
}
cout<<i n v ;
}
}
void b a j a I n v e s t i g a d o r ( P r o y e c t o & p r o y e c t o ) {
i f ( p r o y e c t o . g e t I n v e s t i g a d o r e s ( ) . s i z e ( ) <1) {
a l e r t a ( ”No hay i n v e s t i g a d o r e s almacenados ” ) ;
} else {
unsigned int p o s i c i o n =0;
l i s t a r I n v e s t i g a d o r e s ( proyecto ) ;
p o s i c i o n = getNum ( ” P o s i c i o n ” ) ;
i f ( p o s i c i o n <p r o y e c t o . g e t I n v e s t i g a d o r e s ( ) . s i z e ( ) ) {
c o u t << ( p r o y e c t o . g e t I n v e s t i g a d o r e s ( ) . g e t ( p o s i c i o n ) ) ;
i f ( p r o y e c t o . g e t I n v e s t i g a d o r e s ( ) . g e t ( p o s i c i o n )==p r o y e c t o .
getInvestigadorPpal () ) {
a l e r t a ( ”No s e puede b o r r a r e l i n v e s t i g a d o r p r i n c i p a l ” ) ;
} else {
proyecto . getInvestigadores () . eliminar ( posicion ) ;
}
} else {
a l e r t a ( ”La p o s i c i o n no e s c o r r e c t a ” ) ;
}
}
}
void e l i m i n a r I n v e s t i g a d o r R e c ( P r o y e c t o & p r o y e c t o ) {

Página 17 de 20
Proyecto gestion de investigadores

i f ( p r o y e c t o . g e t I n v e s t i g a d o r e s ( ) . s i z e ( ) <1) {
a l e r t a ( ”No hay i n v e s t i g a d o r e s almacenados ” ) ;
} else {
i f ( proyecto . getInvestigadores () . get ( proyecto .
g e t P o s i c i o n U l t i m o I n v e s t i g a d o r ( ) ) == p r o y e c t o . g e t I n v e s t i g a d o r P p a l ( ) ) {
a l e r t a ( ”No s e puede b o r r a r e l u l t i m o pues e s e l p r i n c i p a l ” ) ;
} else {
proyecto . getInvestigadores () . eliminarUltimo () ;
}
}
}
void l i s t a r I n v e s t i g a d o r e s ( P r o y e c t o & p r o y e c t o ) {
i f ( p r o y e c t o . g e t I n v e s t i g a d o r e s ( ) . s i z e ( ) <1) {
a l e r t a ( ”No hay i n v e s t i g a d o r e s almacenados ” ) ;
} else {
f or ( unsigned int i =0 ; i <p r o y e c t o . g e t I n v e s t i g a d o r e s ( ) . s i z e ( ) ; i ++) {
c o u t << ”Num. ” << i << ” −−−−−−−−−−−−−−−−−−” << e n d l ;
cout<< p r o y e c t o . g e t I n v e s t i g a d o r e s ( ) . g e t ( i ) ;
}
}
}
void m o f i c a r D a t o s I n v e s t i g a d o r ( P r o y e c t o & p r o y e c t o ) {
unsigned int p o s i c i o n =0;
i f ( p r o y e c t o . g e t I n v e s t i g a d o r e s ( ) . s i z e ( ) <1) {
a l e r t a ( ”No hay i n v e s t i g a d o r e s almacenados ” ) ;
} else {
l i s t a r I n v e s t i g a d o r e s ( proyecto ) ;
p o s i c i o n = getNum ( ” P o s i c i o n ” ) ;
i f ( p o s i c i o n <p r o y e c t o . g e t I n v e s t i g a d o r e s ( ) . s i z e ( ) ) {
Investigador ∗ inv = proyecto . g e t I n v e s t i g a d o r e s () . get ( p o s i c i o n ) ;
c o u t << i n v ;
c o u t <<e n d l << ” I n t r o d u z c a l o s d a t o s en e l mismo orden ” << e n d l ;
c i n >> i n v ;
} else {
a l e r t a ( ”La p o s i c i o n i n t r o d u c i d a no e s c o r r e c t a ” ) ;
}
}
}

Proyecto.h

#i f n d e f PROYECTO H INCLUDED
#define PROYECTO H INCLUDED
#include ” Base . h”
#include ” Fecha . h”
#include ” L i s t a I n v e s t i g a d o r e s V e c t o r . h”

class Proyecto {
public :
Proyecto ( ) ;
s t r i n g &getNombre ( ) ;
s t r i n g &g e t D e s c r i p c i o n ( ) ;
s t r i n g getToString () ;
Fecha& g e t I n i c i o ( ) ;
Fecha &g e t F i n ( ) ;
double &g e t P r e s u p u e s t o ( ) ;
Investigador ∗ getInvestigadorPpal () ;

Página 18 de 20
Proyecto gestion de investigadores

int g e t P o s i c i o n U l t i m o I n v e s t i g a d o r ( ) ;
void s e t I n v e s t i g a d o r P p a l ( I n v e s t i g a d o r ∗ ) ;
ListaInvestigadoresVector & getInvestigadores () ;

private :
s t r i n g nombre ;
string descripcion ;
double p r e s u p u e s t o ;
Investigador ∗ invesPpal ;
ListaInvestigadoresVector investigadores ;
Fecha i n i c i o ;
Fecha f i n ;
};
#endif // PROYECTO H INCLUDED

Proyecto.cpp

#include ” Fecha . h”
#include ” P r o y e c t o . h”
#include<sstream >
using namespace s t d ;

Proyecto : : Proyecto ( ) {
presupuesto = 0;
}
s t r i n g& P r o y e c t o : : getNombre ( ) {
return nombre ;
}
s t r i n g& P r o y e c t o : : g e t D e s c r i p c i o n ( ) {
return d e s c r i p c i o n ;
}

Fecha& P r o y e c t o : : g e t I n i c i o ( ) {
return i n i c i o ;
}
Fecha& P r o y e c t o : : g e t F i n ( ) {
return f i n ;
}
double &P r o y e c t o : : g e t P r e s u p u e s t o ( ) {
return p r e s u p u e s t o ;
}
I n v e s t i g a d o r ∗ Proyecto : : g e t I n v e s t i g a d o r P p a l ( ) {
return i n v e s P p a l ;
}
int P r o y e c t o : : g e t P o s i c i o n U l t i m o I n v e s t i g a d o r ( ) {
ListaInvestigadoresVector & l = getInvestigadores () ;
Fecha maxFecha = l . g e t ( 0 )−>getEntr ada ( ) ;
int numUltimo = 0 ; //Numero d e l i n v de maxima f e c h a
f or ( unsigned int n = 0 ; n < l . s i z e ( ) ; n++) {
i f ( l . g e t ( n )−>getEntr ada ( ) > maxFecha ) {
numUltimo = n ;
maxFecha = l . g e t ( n )−>getEntr ada ( ) ;
}
}
return numUltimo ;
}
void P r o y e c t o : : s e t I n v e s t i g a d o r P p a l ( I n v e s t i g a d o r ∗ i ) {

Página 19 de 20
Proyecto gestion de investigadores

invesPpal = i ;
}
L i s t a I n v e s t i g a d o r e s V e c t o r & Proyecto : : g e t I n v e s t i g a d o r e s ( ) {
return i n v e s t i g a d o r e s ;
}
s t r i n g Proyecto : : getToString ( ) {
stringstream st ;
s t <<e n d l
<<”Nombre : ” << getNombre ( ) << e n d l
<<” D e s c r i p c i o n : ” << g e t D e s c r i p c i o n ( ) << e n d l
<<” P r e s u p u e s t o : ” << g e t P r e s u p u e s t o ( ) << e n d l
<<” Fecha I n c i o : ” << g e t I n i c i o ( ) . t o S t r i n g ( )
<<” Fecha Fin : ” << g e t F i n ( ) . t o S t r i n g ( ) <<e n d l ;
s t << ” I n v e s t i g a d o r e s : ” <<e n d l ;
f or ( unsigned int n= 0 ; n<g e t I n v e s t i g a d o r e s ( ) . s i z e ( ) ; n++) {
Investigador ∗ i = getInvestigadores () . get (n) ;
i f ( i == g e t I n v e s t i g a d o r P p a l ( ) ) {
s t << ” I n v e s t i g a d o r p r i n c i p a l ” << e n d l ;
}
s t << g e t I n v e s t i g a d o r e s ( ) . g e t ( n )−>g e t T o S t r i n g ( ) << e n d l ;
}
return s t . s t r ( ) ;
}

Página 20 de 20

S-ar putea să vă placă și