Questa è la mia classe:
#ifndef POINT_H
#define POINT_H
class point
{
public:
point();
point( float a, float b );
float getX();
float getY();
float getPolarP();
float getPolarAng();
float dist( point b );
void setCart( float a, float b );
void setPolar( float a, float b );
private:
float x;
float y;
float p;
float ang;
};
#endif
il suo cpp:
#include "point.h"
#include "cmath"
point::point() { x = 0; y = 0; p = 0; ang = 0; }
point::point(float a, float b) {
x = a; y = b;
p = sqrt(pow(a,2)+pow(b,2));
ang = atan2(b, a);
}
float point::getX() { return x; }
float point::getY() { return y; }
void point::setCart(float a, float b) {
x = a; y = b;
p = sqrt(pow(x,2)+pow(y,2));
ang = atan2(y, x);
}
float point::dist( point b ) {
return sqrt(pow(b.getX() - x, 2) + pow(b.getY() - y, 2));
}
float point::getPolarP() { return p; }
float point::getPolarAng() { return ang; };
void point::setPolar(float a, float b) {
p = a; ang = b;
x = p*cos(ang);
y = p*sin(ang);
}
e un pezzo del main:
point* pt[6];
float x1, y1;
bool exit = false;
char e;
cout << "x1 = ";
cin >> x1;
cout << "y1 = ";
cin >> y1;
pt[1] = new point(x1, y1);
cout << "x2 = ";
cin >> x1;
cout << "y2 = ";
cin >> y1;
pt[2] = new point(x1, y1);
perchè quindi questo non va?
cout << pt[1]->dist(pt[2]);
????