New to classes

Hello,
I am a beginner new to classes. I am trying to write a point class that displays two points when tested. However, when I test it I get my two numbers with 5 additional numbers between them i.e (1,7) I get 1684937. Here is my code and I would appreciate any help, thank you.
Point class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Specification file for the Point class

#ifndef POINT_H
#define POINT_H
#include <iostream>
using namespace std;
class Point;
ostream& operator<< (ostream &, const Point &);
class Point
{
private:
   double x;
   double y;
public:
	Point(); //Default constructor
	Point(double, double); //Constructor
	void setPoints(double, double);
	double getX();
	double getY();
	friend ostream& operator<< (ostream &, const Point &); //friend overloaded << operator
 };

#endif

Point.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Implementation file for the Point class
#include <iostream>
#include "Point.h"
using namespace std;

//***********************************************************
// Initialise  point x and y
//***********************************************************

Point::Point()
{
   x = 0.0;
   y = 0.0;
 
}

//***********************************************************
// Constructor accepts arguments for x and y
//***********************************************************

Point::Point(double pointx, double pointy)
{
   x = pointx;
   y = pointy;
 
}
//***********************************************************
// setPoints sets the value of points x and y      
//***********************************************************

void Point::setPoints(double pointx, double pointy)
{
	x = pointx;
	y = pointy;
}
//***********************************************************
// getPointX gets the value of point x      
//***********************************************************

double Point::getX ()
{
	return x;
}

//***********************************************************
// getPointY gets the value of point y            
//***********************************************************

double Point::getY()
{
	return y;
}

ostream &operator<<(ostream &strm, const Point &pt)
{
  strm<< pt.x << ', ' << pt.y << '\n';

  return strm;
}

Test main
1
2
3
4
5
6
7
8
9
#include <iostream>
#include <iomanip>
#include "point.h"
using namespace std;
void main()
{
Point aPoint(7.0, 2.0);
	cout << aPoint;
}
Don't use void main(). Use int main instead. If your compiler does not complain change it. It surely is quite old.

Anyway your problem is here:
In Point.cpp line 56
change '\n' to "\n".

Also use same file. In main it's point.h in Point.cpp is Point.h.
You're wonderful, thank you :)
Topic archived. No new replies allowed.