逛一圈....c++教室,好地方.....
#include<iostream>#include<cmath>
using namespace std;
class Point
{
public:
Point(void){cout<<"调用构造函数"<<endl;};
Point(int a,int b);
Point(int a,int b,int d);
Point(Point &p);
Point(Point& p1,Point& p2);
void move(int a,int b);
double distance(Point p1,Point p2);
void countj(Point p1,Point p2);
int display1(){return c;}
private:
int x;
int y;
int z;
int c; //两点之间的距离用c表示
};
Point:: Point(int a,int b)
{
x=a;
y=b;
cout<<"点的坐标为:("<<x<<","<<y<<")"<<endl;
}
Point:: Point(int a,int b,int d)
{
x=a;y=b;z=d;
cout<<"点的坐标为:("<<x<<","<<y<<","<<z<<")"<<endl;
}
Point:: Point(Point& p1,Point& p2) //借用两个按引用调用的参数的构造函数求两个点的法向量
{
Point p3;
p3.x=p1.y*p2.z-p1.z*p2.y;
p3.y=p1.z*p2.x-p1.x*p2.z;
p3.z=p1.x*p2.y-p1.y*p2.x;
cout<<"两坐标的法向量为;("<<p3.x<<","<<p3.y<<","<<p3.z<<")"<<endl;
}
Point:: Point(Point &p)
{
x=p.x;
y=p.y;
cout<<"点的坐标为:("<<x<<","<<y<<")"<<endl;
}
void Point::move(int a,int b)
{
x=a;
y=b;
cout<<"点的位置移动到了:("<<x<<","<<y<<")"<<endl;
}
double Point::distance( Point p1,Point p2) //定义的求数量级函数
{
int dx;
int dy;
double distance;
dx=p1.x-p2.x;
dy=p1.y-p2.y;
distance=sqrt(pow(dx,2)+pow(dy,2));
return distance;
}
void Point::countj(Point p1,Point p2)
{
c=p1.x*p2.x+p1.y*p2.y;
}
int main()
{
Point t1(2,3);
Point t2(t1);
t1.move(6,6);
cout<<endl<<endl;
Point t3;
cout<<"两点之间的距离为:"<<t3.distance(t1,t2)<<endl;
cout<<endl<<endl;
Point t4;
t4.countj(t1,t2);
cout<<"两点之间的距离为:"<<t4.display1()<<endl;
cout<<endl<<endl;
Point t5(2,4,6);
Point t6(5,6,2);
Point t7(t5,t6);
system("pause");
return 0;
}