1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <cmath>
using namespace std;
typedef double numeric_t;
typedef long index_t;
class point_t {
numeric_t x, y;
public:
point_t() {x=0, y=0;}
point_t(const numeric_t x1, const numeric_t x2) {x=x1; y=x2;}
inline void setX(const numeric_t val) {x=val;}
inline void setY(const numeric_t val) {y=val;}
inline numeric_t X() {return x;}
inline numeric_t Y() {return y;}
inline point_t offset(const numeric_t dx, const numeric_t dy) {return point_t(x+dx, y+dy);}
inline bool operator == (const point_t & otherP) {return (x==otherP.x) && (y==otherP.y);}
inline bool operator != (const point_t & otherP) {return (x!=otherP.x) || (y!=otherP.y);}
friend ostream & operator << (ostream & stm, const point_t & pt) {return stm <<"("<<pt.x<<", "<<pt.y<<")";}
friend istream & operator >> (istream & stm, point_t & pt);
};
istream & operator >> (istream & stm, point_t & pt) {
numeric_t xx, yy;
string a, b, c;
if(stm >> a >> xx >> b >> yy >> c && a == "(" && b == "," && c == ")" )
{
pt=point_t(xx, yy) ;
}
return stm ;
}
inline numeric_t distance(point_t & p1, point_t & p2) {return sqrt((p1.X()-p2.X())*(p1.X()-p2.X())+(p1.Y()-p2.Y())*(p1.Y()-p2.Y()));}//this is the one with problems,
int main() {
cout<<"Enter two points:"<<endl;
point_t p1, p2, p3;
cin>>p1>>p2;
cout<<p1.X()<<p1.Y()<<p2.X()<<p2.Y()<<endl;
cout<<p1<<endl<<p2<<endl;
p3=p2.offset(1,-7);
cout<<p3;
bool eee;
eee=(p1==p3);
cout<<eee<<endl;
numeric_t thevalue, v1, v2;
cin>>v1>>v2;
thevalue=v1+v2;
// thevalue=distance(p1, p2); /* if I use this function, then there will be compiling problems like: point_t has no member of difference_type, something like that, I don't understand*/
cout<<thevalue<<endl;
return 0;
}
|