Click here to Skip to main content
11,645,893 members (77,873 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C++
After writing this program, debugging it, I am not getting desired output:
using namespace std;
class point 
	int x;
	int y;
	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;
	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;
Posted 16-Sep-12 19:42pm
Edited 17-Sep-12 4:53am
Sandeep Mewara at 17-Sep-12 2:00am
What is the output that you get?

Did you DEBUG and see how the execution flows?
Joan Murt at 17-Sep-12 2:03am
Let's see, this is not a question, it is a mere code dump.
I can see this is your first post here, but you should have read the posting guidelines that appear when you are creating your question.
Improve it putting a little of effort in it and please describe your problem clearly.
Sandeep has done that for you, but you should put your code snippets inside code blocks.
Wes Aday at 17-Sep-12 10:16am
You did not include math.h for the sqrt function. What is your definition of "desired output"?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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 ...
Joan Murt at 17-Sep-12 11:56am
No Richard, no... this is completely wrong, the program had to represent pink unicorns in the screen, a completely correct mathematical result is not desired... :rolleyes: <= this is a small joke... This morning, when I've seen this post I've not been able to find out anything special or strange in it... You've just confirmed it... It works... X|
Richard MacCutchan at 17-Sep-12 12:11pm
:)) You could just have posted the joke here, I think I would have understood your point.
Wes Aday at 17-Sep-12 17:22pm
Wow... oddly enough, that is exactly the same answer I got.... :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 523
1 514
2 Sergey Alexandrovich Kryukov 503
3 Afzaal Ahmad Zeeshan 368
4 F-ES Sitecore 279
0 OriginalGriff 1,143
1 994
2 Sergey Alexandrovich Kryukov 808
3 Afzaal Ahmad Zeeshan 702
4 DamithSL 691

Advertise | Privacy | Mobile
Web02 | 2.8.150731.1 | Last Updated 17 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100