#include<iostream.h>
#include<math.h>
//using namespace std;
class Point
{
public:
Point(int xx=0,int yy=0){X=xx;Y=yy;}
char name[30];
int PUTX(){return X;}
int PUTY(){return Y;}
void GETX(int m){X=m;}
void GETY(int n){Y=n;}
Point operator + (Point q[]);
private:
int X,Y;
};
Point Point::operator + (Point q[],int a)
{
double A,B,C;
A=X-q[a].PUTX;
B=Y-q[a].PUTY;
C=sqrt(A*A+B*B);
return C;
}
class Circle:public Point
{
public:
int PUTR(){return radius;}
void GETR(int k){radius=k;}
char name[30];
private:
int radius;
};
class Rectangle:public Point
{
public:
int PUTS(){return length*width;}
void GETL(int t){length=t;}
void GETW(int h){width=h;}
char name[30];
private:
int length,width;
};void main()
{
int a,b,c,d,e,f,j,g,k,l,i;
int M,N,distance;
int count1=0,count2=0,count3=0;
Circle p[30];
Point q[30];
Rectangle r[30];
for(i=0;i<30;i++)
{
cout<<"输入人物坐标(以回车结束)及人物名称。(按1继续,按0退出)"<<endl;
cin>>a;
if(a==1)
{
cin>>b>>c;
q[i].GETX(b);
q[i].GETY(c);
cin>>q[i].name;
count1++;
}
if(a==0)
{
i=30;
}
cout<<"总人物个数为"<<count1<<endl;
} cout<<"输入人物号"<<endl;
cin>>M>>N;
distance=q[M] + q[N];
cout<<distance<<endl;
报错:E:\c++\作业\课设.cpp(18) : error C2511: '+' : overloaded member function 'class Point (class Point [],int)' not found in 'Point'
E:\c++\作业\课设.cpp(5) : see declaration of 'Point'
E:\c++\作业\课设.cpp(141) : error C2679: binary '+' : no operator defined which takes a right-hand operand of type 'class Point' (or there is no acceptable conversion)我是想通过前面已经输入的数组的坐标 计算下距离
}
#include<math.h>
//using namespace std;
class Point
{
public:
Point(int xx=0,int yy=0){X=xx;Y=yy;}
char name[30];
int PUTX(){return X;}
int PUTY(){return Y;}
void GETX(int m){X=m;}
void GETY(int n){Y=n;}
Point operator + (Point q[]);
private:
int X,Y;
};
Point Point::operator + (Point q[],int a)
{
double A,B,C;
A=X-q[a].PUTX;
B=Y-q[a].PUTY;
C=sqrt(A*A+B*B);
return C;
}
class Circle:public Point
{
public:
int PUTR(){return radius;}
void GETR(int k){radius=k;}
char name[30];
private:
int radius;
};
class Rectangle:public Point
{
public:
int PUTS(){return length*width;}
void GETL(int t){length=t;}
void GETW(int h){width=h;}
char name[30];
private:
int length,width;
};void main()
{
int a,b,c,d,e,f,j,g,k,l,i;
int M,N,distance;
int count1=0,count2=0,count3=0;
Circle p[30];
Point q[30];
Rectangle r[30];
for(i=0;i<30;i++)
{
cout<<"输入人物坐标(以回车结束)及人物名称。(按1继续,按0退出)"<<endl;
cin>>a;
if(a==1)
{
cin>>b>>c;
q[i].GETX(b);
q[i].GETY(c);
cin>>q[i].name;
count1++;
}
if(a==0)
{
i=30;
}
cout<<"总人物个数为"<<count1<<endl;
} cout<<"输入人物号"<<endl;
cin>>M>>N;
distance=q[M] + q[N];
cout<<distance<<endl;
报错:E:\c++\作业\课设.cpp(18) : error C2511: '+' : overloaded member function 'class Point (class Point [],int)' not found in 'Point'
E:\c++\作业\课设.cpp(5) : see declaration of 'Point'
E:\c++\作业\课设.cpp(141) : error C2679: binary '+' : no operator defined which takes a right-hand operand of type 'class Point' (or there is no acceptable conversion)我是想通过前面已经输入的数组的坐标 计算下距离
}
{
public:
Point(int xx=0,int yy=0){X=xx;Y=yy;}
char name[30];
int PUTX(){return X;}
int PUTY(){return Y;}
void GETX(int m){X=m;}
void GETY(int n){Y=n;}
Point operator + (Point q[]); <<=== 自己看,和下面那有啥不同,不错才怪呢..
private:
int X,Y;
};
Point Point::operator + (Point q[],int a)
{
double A,B,C;
A=X-q[a].PUTX; // <===这是个类内变量,上面没有的?
B=Y-q[a].PUTY; // <=== ............
C=sqrt(A*A+B*B);
return C;
}
#include <iostream>
//#include <math.h>
//using namespace std;
class Point
{
public:
public:
Point(int xx=0,int yy=0)
{
X=xx;Y=yy;
}
char name[30];
int PUTX(){return X;}
int PUTY(){return Y;}
void GETX(int m){X=m;}
void GETY(int n){Y=n;}
Point operator + (Point q)
{
double A,B,C;
A=X-q.PUTX();
B=Y-q.PUTY();
C=sqrt(A*A+B*B);
return q;
}
private:
int X,Y;
}; class Circle:public Point
{
public:
Circle()
{
}
public:
int PUTR(){return radius;}
void GETR(int k){radius=k;}
char name[30];
private:
int radius;
};
class Rectangle:public Point
{
public:
Rectangle()
{
}public:
int PUTS(){return length*width;}
void GETL(int t){length=t;}
void GETW(int h){width=h;}
char name[30];
private:
int length,width;
}; void main()
{
int a,b,c,d,e,f,j,g,k,l,i;
int M,N;
int count1=0,count2=0,count3=0;
Circle p[30];
Point q[30];
// Rectangle rr[30];
for(i=0;i <30;i++)
{
cout<<"输入人物坐标(以回车结束)及人物名称。(按1继续,按0退出)" <<endl;
cin>>a;
if(a==1)
{
cin>>b>>c;
q[i].GETX(b);
q[i].GETY(c);
cin>>q[i].name;
count1++;
}
if(a==0)
{
i=30;
}
cout <<"总人物个数为" <<count1 <<endl;
} cout <<"输入人物号" <<endl;
cin>>M>>N;
Point distance=q[M]+q[N];
cout <<distance.PUTX()<<endl;
}