C++的一道简单的题,计算点和面的距离,我的提示出错大家帮我看喜下哪里错了吧?谢谢
#include<iostream>#include<cmath>usingnamespacestd;classMian;classPoint{public:Point(...
#include<iostream>
#include<cmath>
using namespace std;
class Mian;
class Point{
public:
Point(float x=0,float y=0,float z=0){}
float getX(){return x;}
float getY(){return y;}
float getZ(){return z;}
friend float Mian(Point &p1,Mian &m1);
friend float dist(Point &p1,Mian &m1);
private:
float x,y,z;
};
class Mian{
public:
Mian(float a=0,float b=0,float c=0,float d=0){}
float getA(){return a;}
float getB(){return b;}
float getC(){return c;}
float getD(){return d;}
friend float dist(Point &p1,Mian &m1);
private:
float a,b,c,d;
};
float dist(Point &p1,Mian &m1){
float x=p1.x*m1.a;
float y=p1.y*m1.b;
float z=p1.z*m1.c;
float d=m1.d;
float a=m1.a;
float b=m1.b;
float c=m1.c;
return static_cast<float>(sqrt((x+y+z+d)*(x+y+z+d))/sqrt(a*a+b*b+c*c));
}
float main(){
float a,b,c,d,x,y;
cout<<"请输入点的坐标x,y"<<endl;
cin>>x>>y;
cout<<"请输入这个面ax+by+cz+d=0的系数a,b,c,d"<<endl;
cin>>a>>b>>c>>d;
Point myp1(x,y);
Mian mym1(a,b,c,d);
cout<<"点的面的距离为:"<<endl;
cout<<dist(myp1,mym1)<<endl;
return 0;
} 展开
#include<cmath>
using namespace std;
class Mian;
class Point{
public:
Point(float x=0,float y=0,float z=0){}
float getX(){return x;}
float getY(){return y;}
float getZ(){return z;}
friend float Mian(Point &p1,Mian &m1);
friend float dist(Point &p1,Mian &m1);
private:
float x,y,z;
};
class Mian{
public:
Mian(float a=0,float b=0,float c=0,float d=0){}
float getA(){return a;}
float getB(){return b;}
float getC(){return c;}
float getD(){return d;}
friend float dist(Point &p1,Mian &m1);
private:
float a,b,c,d;
};
float dist(Point &p1,Mian &m1){
float x=p1.x*m1.a;
float y=p1.y*m1.b;
float z=p1.z*m1.c;
float d=m1.d;
float a=m1.a;
float b=m1.b;
float c=m1.c;
return static_cast<float>(sqrt((x+y+z+d)*(x+y+z+d))/sqrt(a*a+b*b+c*c));
}
float main(){
float a,b,c,d,x,y;
cout<<"请输入点的坐标x,y"<<endl;
cin>>x>>y;
cout<<"请输入这个面ax+by+cz+d=0的系数a,b,c,d"<<endl;
cin>>a>>b>>c>>d;
Point myp1(x,y);
Mian mym1(a,b,c,d);
cout<<"点的面的距离为:"<<endl;
cout<<dist(myp1,mym1)<<endl;
return 0;
} 展开
展开全部
//如有问题,再探讨
#include<iostream>
#include<cmath>
using namespace std;
class Mian;
class Point{
public:
Point(float x=0,float y=0,float z=0){}
float getX(){return x;}
float getY(){return y;}
float getZ(){return z;}
//friend float Mian(Point &p1,Mian &m1); 这里注释掉,要么函数名改改,不要和类Mian重名了
friend float _Mian(Point &p1,Mian &m1);
friend float dist(Point &p1,Mian &m1);
private:
float x,y,z;
};
class Mian{
public:
Mian(float a=0,float b=0,float c=0,float d=0){}
float getA(){return a;}
float getB(){return b;}
float getC(){return c;}
float getD(){return d;}
friend float dist(Point &p1,Mian &m1);
private:
float a,b,c,d;
};
float dist(Point &p1,Mian &m1)
{
float x=p1.x*m1.a;
float y=p1.y*m1.b;
float z=p1.z*m1.c;
float d=m1.d;
float a=m1.a;
float b=m1.b;
float c=m1.c;
return static_cast<float>(sqrt((x+y+z+d)*(x+y+z+d))/sqrt(a*a+b*b+c*c));
}
float main()
{
float a,b,c,d,x,y;
cout<<"请输入点的坐标x,y"<<endl;
cin>>x>>y;
cout<<"请输入这个面ax+by+cz+d=0的系数a,b,c,d"<<endl;
cin>>a>>b>>c>>d;
Point myp1(x,y);
Mian mym1(a,b,c,d);
cout<<"点的面的距离为:"<<endl;
cout<<dist(myp1,mym1)<<endl;
return 0;
}
#include<iostream>
#include<cmath>
using namespace std;
class Mian;
class Point{
public:
Point(float x=0,float y=0,float z=0){}
float getX(){return x;}
float getY(){return y;}
float getZ(){return z;}
//friend float Mian(Point &p1,Mian &m1); 这里注释掉,要么函数名改改,不要和类Mian重名了
friend float _Mian(Point &p1,Mian &m1);
friend float dist(Point &p1,Mian &m1);
private:
float x,y,z;
};
class Mian{
public:
Mian(float a=0,float b=0,float c=0,float d=0){}
float getA(){return a;}
float getB(){return b;}
float getC(){return c;}
float getD(){return d;}
friend float dist(Point &p1,Mian &m1);
private:
float a,b,c,d;
};
float dist(Point &p1,Mian &m1)
{
float x=p1.x*m1.a;
float y=p1.y*m1.b;
float z=p1.z*m1.c;
float d=m1.d;
float a=m1.a;
float b=m1.b;
float c=m1.c;
return static_cast<float>(sqrt((x+y+z+d)*(x+y+z+d))/sqrt(a*a+b*b+c*c));
}
float main()
{
float a,b,c,d,x,y;
cout<<"请输入点的坐标x,y"<<endl;
cin>>x>>y;
cout<<"请输入这个面ax+by+cz+d=0的系数a,b,c,d"<<endl;
cin>>a>>b>>c>>d;
Point myp1(x,y);
Mian mym1(a,b,c,d);
cout<<"点的面的距离为:"<<endl;
cout<<dist(myp1,mym1)<<endl;
return 0;
}
追问
能告诉我为什么必须注释吗?谢谢
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-04-20
展开全部
算出的结果我不知道对不对
#include<iostream>
#include<cmath>
using namespace std;
class Mian;
class Point
{
public:
Point(float x=0,float y=0,float z=0){}
float getX(){return x;}
float getY(){return y;}
float getZ(){return z;}
// friend float Mian(Point &p1,Mian &m1);
friend float dist(Point &p1,Mian &m1);
private:
float x,y,z;
};
class Mian
{
public:
Mian(float a=0,float b=0,float c=0,float d=0){}
float getA(){return a;}
float getB(){return b;}
float getC(){return c;}
float getD(){return d;}
friend float dist(Point &p1,Mian &m1);
private:
float a,b,c,d;
};
float dist(Point &p1,Mian &m1){
float x=p1.x*m1.a;
float y=p1.y*m1.b;
float z=p1.z*m1.c;
float d=m1.d;
float a=m1.a;
float b=m1.b;
float c=m1.c;
return static_cast<float>(sqrt((x+y+z+d)*(x+y+z+d))/sqrt(a*a+b*b+c*c));
}
int main(){
float a,b,c,d,x,y;
cout<<"请输入点的坐标x,y"<<endl;
cin>>x>>y;
cout<<"请输入这个面ax+by+cz+d=0的系数a,b,c,d"<<endl;
cin>>a>>b>>c>>d;
Point myp1(x,y);
Mian mym1(a,b,c,d);
cout<<"点的面的距离为:"<<endl;
cout<<dist(myp1,mym1)<<endl;
return 0;
}
#include<iostream>
#include<cmath>
using namespace std;
class Mian;
class Point
{
public:
Point(float x=0,float y=0,float z=0){}
float getX(){return x;}
float getY(){return y;}
float getZ(){return z;}
// friend float Mian(Point &p1,Mian &m1);
friend float dist(Point &p1,Mian &m1);
private:
float x,y,z;
};
class Mian
{
public:
Mian(float a=0,float b=0,float c=0,float d=0){}
float getA(){return a;}
float getB(){return b;}
float getC(){return c;}
float getD(){return d;}
friend float dist(Point &p1,Mian &m1);
private:
float a,b,c,d;
};
float dist(Point &p1,Mian &m1){
float x=p1.x*m1.a;
float y=p1.y*m1.b;
float z=p1.z*m1.c;
float d=m1.d;
float a=m1.a;
float b=m1.b;
float c=m1.c;
return static_cast<float>(sqrt((x+y+z+d)*(x+y+z+d))/sqrt(a*a+b*b+c*c));
}
int main(){
float a,b,c,d,x,y;
cout<<"请输入点的坐标x,y"<<endl;
cin>>x>>y;
cout<<"请输入这个面ax+by+cz+d=0的系数a,b,c,d"<<endl;
cin>>a>>b>>c>>d;
Point myp1(x,y);
Mian mym1(a,b,c,d);
cout<<"点的面的距离为:"<<endl;
cout<<dist(myp1,mym1)<<endl;
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
main函数怎么是float的,应该是 int main()
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询