改错 明天前需答案#include #include //CPoint类表示平面直角坐标系中的一个点class CPoint{private:double m_X; //x坐标double m_Y; //y坐标public:void CPoint(double x,double y) //***(1)***{m_X = x;m_Y = y;}//Copy构造CPoint(CPoin

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/25 21:00:03
改错 明天前需答案#include #include //CPoint类表示平面直角坐标系中的一个点class CPoint{private:double m_X; //x坐标double m_Y; //y坐标public:void CPoint(double x,double y) //***(1)***{m_X = x;m_Y = y;}//Copy构造CPoint(CPoin

改错 明天前需答案#include #include //CPoint类表示平面直角坐标系中的一个点class CPoint{private:double m_X; //x坐标double m_Y; //y坐标public:void CPoint(double x,double y) //***(1)***{m_X = x;m_Y = y;}//Copy构造CPoint(CPoin
改错 明天前需答案
#include
#include
//CPoint类表示平面直角坐标系中的一个点
class CPoint
{
private:
double m_X; //x坐标
double m_Y; //y坐标
public:
void CPoint(double x,double y) //***(1)***
{
m_X = x;
m_Y = y;
}
//Copy构造
CPoint(CPoint p) //***(2)***
{
m_X = p.GetX();
m_Y = p.GetY();
}
double GetX() { return m_X; } //获得x坐标
double GetY() { return m_Y; } //获得y坐标
void SetX(double val){ m_X = val; } //设置x坐标
void SetY(double val){ m_Y = val; } //设置y坐标
//对运算符“-”进行重载,求两个点之间的差
CPoint - (CPoint & point) //***(3)***
{
CPoint p(m_X - point.GetX(),m_Y - point.GetY());
return p;
}
//获得该坐标点到原点的距离
double GetModulus()
{
return sqrt(m_X^2 + m_Y^2); //***(4)***
}
};
//CTriangle类表示一条直线
class CTriangle
{
private:
CPoint m_Point1; //第一个顶点
CPoint m_Point2; //第二个顶点
CPoint m_Point3; //第三个顶点
//获得两个点之间的距离
double GetDistance(CPoint & p1,CPoint & p2)
{
CPoint dp = p1 - p2;
return dp //***(5)*** 此处修改后不得使用sqrt函数
}
public:
//构造函数,要求输入三个坐标点
CTriangle(double x1,double y1,double x2,double y2,double x3,double y3)
:m_Point1(x1,y1),m_Point2(x2,y2),m_Point3(x3,y3)
{
}
//计算三角形面积,该函数的完整定义置于类的外部
bool IsobtuseTriangle();
};
bool CPoint::IsobtuseTriangle() //***(6)***
{
//计算三条边的边长
double a = GetDistance(m_Point1,m_Point2);
double b = GetDistance(m_Point2,m_Point3);
double c = GetDistance(m_Point1,m_Point3);
if (a * a + b * b < c * c) return true; else return false; //***(7)***
if (b * b + c * c < a * a) return true; else return false; //***(8)***
if (a * a + c * c < b * b) return true; else return false; //***(9)***
return false;
}
void main()
{
CTriangle triangle(Point(0,0),Point(2,1),Point(2,-5)); //***(10)*** 修改此
行时,不得修改三角形三个顶点的坐标
if (triangle.IsobtuseTriangle())
cout

改错 明天前需答案#include #include //CPoint类表示平面直角坐标系中的一个点class CPoint{private:double m_X; //x坐标double m_Y; //y坐标public:void CPoint(double x,double y) //***(1)***{m_X = x;m_Y = y;}//Copy构造CPoint(CPoin
//CPoint类表示平面直角坐标系中的一个点
class CPoint
{
private:
double m_X; //x坐标
double m_Y; //y坐标
public:
CPoint(double x,double y) //***(1)***
{
m_X = x;
m_Y = y;
}
//Copy构造
CPoint(CPoint &p) //***(2)***
{
m_X = p.GetX();
m_Y = p.GetY();
}
double GetX() { return m_X; } //获得x坐标
double GetY() { return m_Y; } //获得y坐标
void SetX(double val){ m_X = val; } //设置x坐标
void SetY(double val){ m_Y = val; } //设置y坐标
//对运算符“-”进行重载,求两个点之间的差
CPoint operator- (CPoint & point) //***(3)***
{
CPoint p(m_X - point.GetX(),m_Y - point.GetY());
return p;
}
//获得该坐标点到原点的距离
double GetModulus()
{
return sqrt(m_X*m_X + m_Y*m_Y); //***(4)***
}
};
//CTriangle类表示一条直线
class CTriangle
{
private:
CPoint m_Point1; //第一个顶点
CPoint m_Point2; //第二个顶点
CPoint m_Point3; //第三个顶点
//获得两个点之间的距离
double GetDistance(CPoint & p1,CPoint & p2)
{
CPoint dp = p1 - p2;
return dp.GetModulus(); //***(5)*** 此处修改后不得使用sqrt函数
}
public:
//构造函数,要求输入三个坐标点
CTriangle(CPoint p1,CPoint p2,CPoint p3)
:m_Point1(p1),m_Point2(p2),m_Point3(p3)
{
}
//计算三角形面积,该函数的完整定义置于类的外部
bool IsobtuseTriangle();
};
bool CTriangle::IsobtuseTriangle() //***(6)***
{
//计算三条边的边长
double a = GetDistance(m_Point1,m_Point2);
double b = GetDistance(m_Point2,m_Point3);
double c = GetDistance(m_Point1,m_Point3);
if (a * a + b * b < c * c) return true; else return false; //***(7)***
if (b * b + c * c < a * a) return true; else return false; //***(8)***
if (a * a + c * c < b * b) return true; else return false; //***(9)***
return false;
}
void main()
{
CTriangle triangle(CPoint(0,0),CPoint(2,1),CPoint(2,-5)); //***(10)*** 修改此行时,不得修改三角形三个顶点的坐标
if (triangle.IsobtuseTriangle())
cout