C ++程序未返回所需的输出 [英] C++ program not returning desired output
本文介绍了C ++程序未返回所需的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
编写此程序后,对其进行调试,我没有得到想要的输出:
After writing this program, debugging it, I am not getting desired output:
#include<iostream>
using namespace std;
class point
{
private:
int x;
int y;
public:
void setPoint(int xcoord,int ycoord)
{
x = xcoord; y = ycoord;
}
int getX()
{return (x);}
int getY()
{return (y);}
void showPoint()
{ cout << "(" << x << ","<< y <<")";
}
};
int main()
{
point pt1,pt2;
double dx, dy, dist;
pt1.setPoint(-3,2);
pt2.setPoint(2,5);
dx = pt2.getX() - pt1.getX();
dy = pt2.getY() - pt1.getY();
dist = sqrt (dx*dx + dy*dy);
cout << "The distance between two points"; pt1.showPoint();
cout << "and";pt2.showPoint();
cout << "is"<< dist << endl;
return 0;
推荐答案
我刚刚对此进行了测试,答案是正确的:
dx等于5
dy等于3
dx * dx + dy * dy等于25 + 9 = 34
34的平方根是5.83095 ...
I just tested this and the answer is correct:
dx is equal to 5
dy is equal to 3
dx*dx + dy*dy is equal to 25 + 9 = 34
The square root of 34 is 5.83095 ...
这篇关于C ++程序未返回所需的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文