Diferencias entre las revisiones 18 y 20 (abarca 2 versiones)
Versión 18 con fecha 2019-10-03 20:54:48
Tamaño: 8808
Comentario:
Versión 20 con fecha 2019-10-03 21:00:38
Tamaño: 9010
Comentario:
Los textos eliminados se marcan así. Los textos añadidos se marcan así.
Línea 12: Línea 12:
{{{ {{{#!highlight c++
Línea 91: Línea 91:
{{{ {{{#!highlight c++
Línea 123: Línea 124:
{{{ {{{#!highlight c++
Línea 158: Línea 160:
{{{ {{{#!highlight c++
Línea 184: Línea 187:
{{{ {{{#!highlight c++
Línea 211: Línea 215:
{{{ {{{#!highlight c++
Línea 218: Línea 223:
Línea 241: Línea 247:
{{{ {{{#!highlight c++
Línea 275: Línea 281:
{{{ {{{#!highlight c++
Línea 281: Línea 288:
Línea 303: Línea 311:
{{{ {{{#!highlight c++
Línea 335: Línea 343:
{{{ {{{#!highlight c++
Línea 340: Línea 348:
Línea 363: Línea 372:
{{{ {{{#!highlight c++
Línea 370: Línea 379:
Línea 399: Línea 409:
{{{ {{{#!highlight c++

attachment:resumen-poo.png


Diagrama de ejemplo.

attachment:diagrama_clases2.png

Códigos fuente C++.

programa.cpp

   1 /*
   2  * Compilación: $ make
   3  * Ejecución:   $ ./programa
   4  */
   5 #include <list>
   6 #include <iostream>
   7 #include "Proteina.h"
   8 #include "Cadena.h"
   9 #include "Aminoacido.h"
  10 #include "Atomo.h"
  11 #include "Coordenada.h"
  12 
  13 void print_proteina (Proteina p) {
  14     cout << endl;
  15 
  16     cout << "ID: " << p.get_id() << " Nombre: " << p.get_nombre() << endl;
  17 
  18     for (Cadena c: p.get_cadenas()) {
  19         cout << "Cadena: " << c.get_letra() << endl;
  20 
  21         for (Aminoacido a: c.get_aminoacidos()) {
  22             cout << "\tAminoacido: " << a.get_nombre() << ":" << a.get_numero() << endl;
  23 
  24             for (Atomo at: a.get_atomos()) {
  25                 cout << "\t\tAtomo: " << at.get_nombre() << ":" << at.get_numero() << " [" <<
  26                 at.get_coordenada().get_x() << ", " << at.get_coordenada().get_y() << ", " <<
  27                 at.get_coordenada().get_z() << "]" << endl;
  28             }
  29         }
  30     }
  31 }
  32 
  33 /*
  34  */
  35 int main (int argc, char **argv) {
  36     list<Proteina> proteinas;
  37 
  38     // instancia una proteina.
  39     Proteina p1 = Proteina("1rmd", "RAG1 DIMERIZATION DOMAIN");
  40 
  41     // la agrega a la lista.
  42     proteinas.push_back(p1);
  43 
  44     // instancia una cadena.
  45     Cadena a = Cadena("A");
  46     // instancia y agrega aminoacidos a la cadena.
  47     Aminoacido r = Aminoacido("CIS", 1);
  48     // instancia atomo.
  49     Atomo at = Atomo("CA", 1, 2.3, 3.3, 2.2);
  50     // agrega el átomo al aminoacido.
  51     r.add_atomo(at);
  52     // agrega otro átomo.
  53     r.add_atomo(Atomo("N", 2, 1.1, 2.1, 2.5));
  54 
  55     a.add_aminoacido(r);
  56     a.add_aminoacido(Aminoacido("ALA", 2));
  57     a.add_aminoacido(Aminoacido("HIS", 3));
  58 
  59     // agrega la cadena a la proteína.
  60     p1.add_cadena(a);
  61 
  62     // crea otra cadena.
  63     Cadena b = Cadena("B");
  64     // agrega aminoacidos a la cadena.
  65     b.add_aminoacido(Aminoacido("CYS", 5));
  66     b.add_aminoacido(Aminoacido("CYS", 15));
  67     b.add_aminoacido(Aminoacido("TYR", 3));
  68 
  69     // agrega otra cadena a la proteína.
  70     p1.add_cadena(b);
  71 
  72     print_proteina(p1);
  73 
  74     return 0;
  75 }

Proteina.h

   1 #ifndef PROTEINA_H
   2 #define PROTEINA_H
   3 
   4 #include <list>
   5 #include <iostream>
   6 using namespace std;
   7 #include "Cadena.h"
   8 
   9 class Proteina {
  10     private:
  11         string id;
  12         string nombre;
  13         list<Cadena> cadenas;
  14 
  15     public:
  16         /* constructores */
  17         Proteina (string id, string nombre);
  18 
  19         /* métodos get and set */
  20         string get_nombre();
  21         string get_id();
  22 
  23         void set_nombre(string nombre);
  24         void set_id(string id);
  25         void add_cadena(Cadena cadena);
  26         list<Cadena> get_cadenas();
  27 };
  28 #endif
  29 

Proteina.cpp

   1 /*
   2  */
   3 
   4 #include <iostream>
   5 using namespace std;
   6 #include "Proteina.h"
   7 /* constructores */
   8 Proteina::Proteina (string id, string nombre) {
   9     this->nombre = nombre;
  10     this->id = id;
  11 }
  12 /* métodos get and set */
  13 string Proteina::get_nombre() {
  14     return this->nombre;
  15 }
  16 string Proteina::get_id() {
  17     return this->id;
  18 }
  19 void Proteina::set_nombre(string nombre) {
  20     this->nombre = nombre;
  21 }
  22 
  23 void Proteina::set_id(string id) {
  24     this->id = id;
  25 }
  26 void Proteina::add_cadena(Cadena cadena) {
  27     this->cadenas.push_back(cadena);
  28 }
  29 list<Cadena> Proteina::get_cadenas() {
  30     return this->cadenas;
  31 }

Cadena.h

   1 #ifndef CADENA_H
   2 #define CADENA_H
   3 #include <list>
   4 #include <iostream>
   5 using namespace std;
   6 #include "Aminoacido.h"
   7 class Cadena {
   8     private:
   9         string letra;
  10         list<Aminoacido> aminoacidos;
  11     public:
  12         /* constructores */
  13         Cadena (string letra);
  14 
  15         /* métodos get and set */
  16         string get_letra();
  17         list<Aminoacido> get_aminoacidos();
  18 
  19         void set_letra(string letra);
  20         void add_aminoacido(Aminoacido aminoacido);
  21 };
  22 #endif
  23 

Cadena.cpp

   1 /*
   2  */
   3 
   4 #include <iostream>
   5 using namespace std;
   6 #include "Cadena.h"
   7 /* constructores */
   8 Cadena::Cadena (string letra) {
   9     this->letra = letra;
  10 }
  11 /* métodos get and set */
  12 string Cadena::get_letra() {
  13     return this->letra;
  14 }
  15 void Cadena::set_letra(string letra) {
  16     this->letra = letra;
  17 }
  18 void Cadena::add_aminoacido(Aminoacido aminoacido) {
  19     this->aminoacidos.push_back(aminoacido);
  20 }
  21 list<Aminoacido> Cadena::get_aminoacidos() {
  22     return this->aminoacidos;
  23 }

Aminoacido.h

   1 #ifndef AMINOACIDO_H
   2 #define AMINOACIDO_H
   3 #include <list>
   4 #include <iostream>
   5 using namespace std;
   6 #include "Atomo.h"
   7 
   8 class Aminoacido {
   9     private:
  10         int numero;
  11         string nombre;
  12         list<Atomo> atomos;
  13 
  14     public:
  15         /* constructores */
  16         Aminoacido (string nombre, int numero);
  17 
  18         /* métodos get and set */
  19         string get_nombre();
  20         int get_numero();
  21 
  22         void set_nombre(string nombre);
  23         void set_numero(int numero);
  24         void add_atomo(Atomo atomo);
  25         list<Atomo> get_atomos();
  26 };
  27 #endif
  28 

Aminoacido.cpp

   1 /*
   2  */
   3 
   4 #include <iostream>
   5 using namespace std;
   6 #include "Aminoacido.h"
   7 /* constructores */
   8 Aminoacido::Aminoacido (string nombre, int numero) {
   9     this->nombre = nombre;
  10     this->numero = numero;
  11 }
  12 /* métodos get and set */
  13 string Aminoacido::get_nombre() {
  14     return this->nombre;
  15 }
  16 int Aminoacido::get_numero() {
  17     return this->numero;
  18 }
  19 void Aminoacido::set_nombre(string nombre) {
  20     this->nombre = nombre;
  21 }
  22 void Aminoacido::set_numero(int numero) {
  23     this->numero = numero;
  24 }
  25 void Aminoacido::add_atomo(Atomo atomo) {
  26     this->atomos.push_back(atomo);
  27 }
  28 list<Atomo> Aminoacido::get_atomos() {
  29     return this->atomos;
  30 }

Atomo.h

   1 #ifndef ATOMO_H
   2 #define ATOMO_H
   3 #include <iostream>
   4 using namespace std;
   5 #include "Coordenada.h"
   6 
   7 class Atomo {
   8     private:
   9         string nombre;
  10         int numero;
  11         Coordenada coordenada;
  12 
  13     public:
  14         /* constructores */
  15         Atomo (string nombre, int numero, float x, float y, float z);
  16 
  17         /* métodos get and set */
  18         string get_nombre();
  19         int get_numero();
  20 
  21         void set_nombre(string nombre);
  22         void set_numero(int numero);
  23         Coordenada get_coordenada();
  24 };
  25 #endif
  26 

Atomo.cpp

   1 /*
   2  */
   3 
   4 #include <iostream>
   5 using namespace std;
   6 #include "Atomo.h"
   7 /* constructores */
   8 Atomo::Atomo (string nombre, int numero, float x, float y, float z) {
   9     this->nombre = nombre;
  10     this->numero = numero;
  11     this->coordenada = Coordenada(x, y, z);
  12 }
  13 /* métodos get and set */
  14 string Atomo::get_nombre() {
  15     return this->nombre;
  16 }
  17 int Atomo::get_numero() {
  18     return this->numero;
  19 }
  20 void Atomo::set_nombre(string nombre) {
  21     this->nombre = nombre;
  22 }
  23 void Atomo::set_numero(int numero) {
  24     this->numero = numero;
  25 }
  26 Coordenada Atomo::get_coordenada() {
  27     return this->coordenada;
  28 }

Coordenada.h

   1 #ifndef COORDENADA_H
   2 #define COORDENADA_H
   3 #include <iostream>
   4 using namespace std;
   5 
   6 class Coordenada {
   7     private:
   8         float x;
   9         float y;
  10         float z;
  11 
  12     public:
  13         /* constructores */
  14         Coordenada ();
  15         Coordenada (float x, float y, float z);
  16 
  17         /* métodos get and set */
  18         void set_x(float x);
  19         void set_y(float y);
  20         void set_z(float z);
  21         float get_x();
  22         float get_y();
  23         float get_z();
  24 };
  25 #endif
  26 

Coordenada.cpp

   1 /*
   2  */
   3 
   4 #include <iostream>
   5 using namespace std;
   6 #include "Coordenada.h"
   7 
   8 /* constructores */
   9 Coordenada::Coordenada () {}
  10 Coordenada::Coordenada (float x, float y, float z) {
  11     this->x = x;
  12     this->y = y;
  13     this->z = z;
  14 }
  15 /* métodos get and set */
  16 void Coordenada::set_x(float x) {
  17     this->x = x;
  18 }
  19 void Coordenada::set_y(float y) {
  20     this->y = y;
  21 }
  22 void Coordenada::set_z(float z) {
  23     this->z = z;
  24 }
  25 float Coordenada::get_x() {
  26     return this->x;
  27 }
  28 float Coordenada::get_y() {
  29     return this->y;
  30 }
  31 float Coordenada::get_z() {
  32     return this->z;
  33 }

Makefile

   1 prefix=/usr/local
   2 CC = g++
   3 CFLAGS = -g -Wall
   4 SRC = programa.cpp Proteina.cpp Cadena.cpp Aminoacido.cpp Atomo.cpp Coordenada.cpp
   5 OBJ = programa.o Proteina.o Cadena.o Aminoacido.o Atomo.o Coordenada.o
   6 APP = programa
   7 all: $(OBJ)
   8     $(CC) $(CFLAGS)-o $(APP) $(OBJ)
   9 clean:
  10     $(RM) $(OBJ) $(APP)
  11 install: $(APP)
  12     install -m 0755 $(APP) $(prefix)/bin
  13 uninstall: $(APP)
  14     $(RM) $(prefix)/bin/$(APP)

POO (última edición 2019-10-03 21:05:33 efectuada por AlejandroValdes)