The exercise consists in implementing a TAD Point, with the operations abscissa (returns the x), ordered (returns the y) and distance (calculates the distance between two points).
The exercise is simple and this is my code:
file: dot.h
#ifndef PUNTO_H
#define PUNTO_H
class Punto
{
public:
//Constructores primero
Punto();
//Construye un punto a (0,0)
Punto(float x, float y);
//Construye un punto con lo que le den
//Operaciones
float abscisa();
//POST: devuelve el valor x del punto actual
float ordenada();
//POST devuelve el valor y del punto actual
float distancia(Punto p1, Punto p2);
//POST: devuelve el vector distancia p1-p2
private:
float x_, y_;//coordenadas del punto actual
};
#endif // PUNTO_H
file: dot.cpp
#include "punto.h"
#include <cmath>
Punto::Punto()
{
x_ = 0.0;
y_ = 0.0;
}
Punto::Punto(float x, float y)
{
x_ = x;
y_ = y;
}
float Punto::abscisa()
{
return x_;
}
float Punto::ordenada()
{
return y_;
}
float Punto::distancia(Punto p1, Punto p2)
{
float dis = sqrt(pow(2,((p1.x_) - (p2.x_))) + pow(2,((p1.y_)-(p2.y_))));
return dis;
}
file: main.cpp HERE GIVES ME THE ERROR ...
#include <iostream>
#include "punto.h"
using namespace std;
int main()
{
Punto s1(1.0,2.0);//Constructor dandole valores a las coordenadas
Punto s2;// valores vacíos a las coordenadas
float x = distancia(s1, s2);//ERROR 'distancia' was not declared in this scope
cout << x << endl;
return 0;
}
Use QT in linux mint to program. How is this error solved?
PS: I've already looked at this post and I do not it's the same error because I do have the distance function in the scope of the Point class.