Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/01/2013, 12:25
Lotux5
 
Fecha de Ingreso: enero-2013
Mensajes: 25
Antigüedad: 11 años, 3 meses
Puntos: 0
Problema con clases [C++]

Alguien me puede decir que le pasa a mi código. El principal problema es que no me funciona la clase Segmento ya que al introducir la variable Segmento s1 me da error. Lo curioso es que la hice siguiendo los mismo pasos que la clase Punto la cual sí funciona. Por favor, respondedme rápido ya que el lunes tengo un examen.


Código C++:
Ver original
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. class Punto {
  7.     private:
  8.         double ejex, ejey;
  9.     public:
  10.         Punto();
  11.         Punto(double x, double y);
  12.         void SetP(double x, double y);
  13.         double GetX();
  14.         double GetY();
  15.         double distanciacon(Punto b);
  16. };
  17.  
  18. Punto::Punto(double x, double y)
  19. {
  20.     (*this).ejex=x;
  21.     (*this).ejey=y;
  22. }
  23.  
  24. Punto::Punto()
  25. {
  26.     (*this).ejex=0;
  27.     (*this).ejey=0;
  28. }
  29.  
  30. void Punto::SetP(double x, double y)
  31. {
  32.     (*this).ejex=x;
  33.     (*this).ejey=y;
  34. }
  35.  
  36. double Punto::GetX()
  37. {
  38.     return ejex;
  39. }
  40.  
  41. double Punto::GetY()
  42. {
  43.     return ejey;
  44. }
  45.  
  46. double Punto::distanciacon(Punto b)
  47. {
  48.  
  49.     return sqrt(pow((*this).ejex-b.ejex,2)+pow((*this).ejey-b.ejey,2));
  50. }
  51.  
  52. class Segmento{
  53.     private:
  54.         Punto p1, p2;
  55.  
  56.     public:
  57.         Segmento(Punto punto1, Punto punto2);
  58.         void SetS(Punto punto1, Punto punto2);
  59.         Punto GetP1() const;
  60.         Punto GetP2() const;
  61. };
  62.  
  63.  
  64. Segmento::Segmento(Punto punto1, Punto punto2)
  65. {
  66.     (*this).p1=punto1;
  67.     (*this).p2=punto2;
  68. }
  69.  
  70. void Segmento::SetS(Punto punto1, Punto punto2)
  71. {
  72.     (*this).p1=punto1;
  73.     (*this).p2=punto2;
  74. }
  75.  
  76. Punto Segmento::GetP1() const
  77. {
  78.     return p1;
  79. }
  80.  
  81. Punto Segmento::GetP2() const
  82. {
  83.     return p2;
  84. }
  85.  
  86. int main()
  87. {
  88.     Punto p1, p2;
  89.     double x1, x2, y1, y2;
  90.     cout << "Introduce un puntos: ";
  91.     cin >> x1 >> y1;
  92.     cout << "Introduce otro punto: ";
  93.     cin >> x2 >> y2;
  94.  
  95.     p1.SetP(x1,y1);
  96.     p2.SetP(x2,y2);
  97.  
  98.     Segmento s1;
  99.  
  100.  
  101. }