Error - no operator ">>" matches these operands

Pages: 12
Hi, i'm beginner in c++. Currently facing some issue on my codes. Below is the snippets of codes that are having issues. The error is @ " h >> p2d; "
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
#include <ostream>
#include <set>

#include "Point2D.h"
#include "Point3D.h"
#include "Line2D.h"
#include "Line3D.h"
#include "MyTemplates.h"

using namespace std;

Point2D point2d;
Point3D point3d;
Line2D line2d;
Line3D line3d;
string no_of_lines, filename, infile, outfile;
ifstream myfile;
ofstream myyfile;
int lines;
void intro_menu();
void read_in_data();
void filtering_criteria();
void sorting_criteria();
void sorting_order();
void view_data();
void store_data();

set<Point2D> pointtwod;
set<Point3D> pointthreed;
set<Line2D> linetwod;
set<Line3D> linethreed;

enum FilteringCriteria
{
	POINT2D, POINT3D, LINE2D, LINE3D,
};
FilteringCriteria fc = POINT2D;
ostream& operator << (ostream& os, FilteringCriteria fc)
{
	switch (fc)
	{
	case POINT2D:
		return os << "Point2D";

	case POINT3D:
		return os << "Point3D";

	case LINE2D:
		return os << "Line2D";

	case LINE3D:
		return os << "Line3D";
	}
}

enum SortingCriteria
{
	pt1, pt2, pt3, length,
};
SortingCriteria sc = pt1;
ostream& operator << (ostream& os, SortingCriteria sc)
{
	switch (sc)
	{
	case pt1:
		return os << "Pt. 1's (x, y) values";

	case pt2:
		return os << "Pt. 2's (x, y) values";

	case pt3:
		return os << "Pt.3 's (x, y, z) values";

	case length:
		return os << "Length";
	}
}

enum SortingOrder
{
	ASC, DESC,
};
SortingOrder so = ASC;
ostream& operator << (ostream& os, SortingOrder so)
{
	switch (so)
	{
	case pt1:
		return os << "Ascending Order";

	case pt2:
		return os << "Descending Order";
	}
}

int main() {
	int choice;
	string no_of_lines;
	intro_menu();
	cin >> choice;
	switch (choice)
	{
	case 1:
	{
		read_in_data();
		main();
	}
	case 2:
	{
		filtering_criteria();
		main();
	}
	case 3:
	{
		sorting_criteria();
		main();
	}
	case 4:
	{
		sorting_order();
		main();
	}
	case 5:
	{
		main();
	}
	case 6:
	{
		cout << "Store Data" << "\n";
		main();
	}
	}
}


void read_in_data()
{
	string name, test_string;
	int count = 0;
	cout << "Please Enter Filename : ";
	cin >> filename;
	myfile.open(filename.c_str(),std::ios::in);
	if (myfile.is_open())
	{
		while (getline(myfile, no_of_lines))
			++lines;
		cout << lines << " records read in successfully" << "\n";
	}

	while (myfile.good())
	{
		getline(myfile, name, ',');
		getline(myfile, test_string, '\n');

		if (name == "Point2D")
		{
			stringstream coordinates(test_string);
			Point2D *p2d = new Point2D();
			string s;

			while (coordinates.good())
			{
				getline(coordinates, s, ']');

				if (s.size() > 0)
				{
					s = s.substr(1);
					stringstream h(s);
					h >> p2d;
					pointtwod.insert(*p2d);
					count++;
				}
			}
		}
		else if (name == "Point3D")
		{
			stringstream coordinates(test_string);
			Point3D *p3d = new Point3D();
			string s;

			while (coordinates.good())
			{
				getline(coordinates, s, ']');

				if (s.size() > 0)
				{
					s = s.substr(1);
					stringstream c(s);
					//c >> *p3d;
					pointthreed.insert(*p3d);
					count++;
				}
			}
		}
		else if (name == "Line2D")
		{
			stringstream coordinates(test_string);
			Line2D *l2d = new Line2D();
			//c >> *l2d;
			linetwod.insert(*l2d);
			count++;
		}
		else if (name == "Line3D")
		{
			stringstream coordinates(test_string);
			Line3D *l3d = new Line3D();
			//c >> *l3d;
			linethreed.insert(*l3d);
			count++;
		}
	}
	cout << count << " records read in successfully." << "\n";
	myfile.close();
}

Need help on resolving this error in order to carry on with my coding... :(
Last edited on
h >> p2d;
std::stringstream does not support pointer input directly.
As well as that particular error, there are a number of other issues with the code - as far as it is available - the headers would be useful too.

1. In standard C++ main() may not be called. It is best to avoid this, usually by using a loop instead, as the code may not compile if you use a different compiler, (or change the settings of the current compiler).

2. Flawed logic in a few places.
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
#include <ostream>
#include <set>

#include "Point2D.h"
#include "Point3D.h"
#include "Line2D.h"
#include "Line3D.h"
#include "MyTemplates.h"

using namespace std;

Point2D point2d;
Point3D point3d;
Line2D line2d;
Line3D line3d;
string no_of_lines, filename, infile, outfile;
ifstream myfile;
ofstream myyfile;
int lines;

void intro_menu();
void read_in_data();
void filtering_criteria();
void sorting_criteria();
void sorting_order();
void view_data();
void store_data();

set<Point2D> pointtwod;
set<Point3D> pointthreed;
set<Line2D> linetwod;
set<Line3D> linethreed;

enum FilteringCriteria
{
    POINT2D, POINT3D, LINE2D, LINE3D,
};

FilteringCriteria fc = POINT2D;
ostream& operator << (ostream& os, FilteringCriteria fc)
{
    switch (fc)
    {
        case POINT2D:
            return os << "Point2D";

        case POINT3D:
            return os << "Point3D";

        case LINE2D:
            return os << "Line2D";

        case LINE3D:
            return os << "Line3D";
    }
}

enum SortingCriteria
{
    pt1, pt2, pt3, length,
};

SortingCriteria sc = pt1;
ostream& operator << (ostream& os, SortingCriteria sc)
{
    switch (sc)
    {
        case pt1:
            return os << "Pt. 1's (x, y) values";

        case pt2:
            return os << "Pt. 2's (x, y) values";

        case pt3:
            return os << "Pt.3 's (x, y, z) values";

        case length:
            return os << "Length";
    }
}

enum SortingOrder
{
    ASC, DESC,
};

SortingOrder so = ASC;
ostream& operator << (ostream& os, SortingOrder so)
{
    switch (so)
    {
        case pt1:
            return os << "Ascending Order";

        case pt2:
            return os << "Descending Order";
    }
}

int main() 
{
    int choice;
    string no_of_lines;
    intro_menu();
    cin >> choice;
    switch (choice)
    {
        case 1:
        {
            read_in_data();
            main();
        }
        
        case 2:
        {
            filtering_criteria();
            main();
        }
        
        case 3:
        {
            sorting_criteria();
            main();
        }
        
        case 4:
        {
            sorting_order();
            main();
        }
        
        case 5:
        {
            main();
        }
        
        case 6:
        {
            cout << "Store Data" << "\n";
            main();
        }
    }
}


void read_in_data()
{
    string name, test_string;
    int count = 0;
    //cout << "Please Enter Filename : ";
    //cin >> filename;
    //myfile.open(filename.c_str(),std::ios::in);
    myfile.open("/Users/darwinlau/Desktop/Assn3/Assn3/messy.txt");
    if (myfile.is_open())
    {
        while (getline(myfile, no_of_lines))
            ++lines;
        cout << lines << " records read in successfully" << "\n";
    }

    while (myfile.good())
    {
        getline(myfile, name, ',');
        getline(myfile, test_string, '\n');

        if (name == "Point2D")
        {
            stringstream coordinates(test_string);
            Point2D *p2d = new Point2D();
            string s;

            while (coordinates.good())
            {
                getline(coordinates, s, ']');

                if (s.size() > 0)
                {
                    s = s.substr(1);
                    stringstream h(s);
                    h >> p2d;                                 // compile error
                    pointtwod.insert(*p2d);
                    count++;
                }
            }
        }
        else if (name == "Point3D")
        {
            stringstream coordinates(test_string);
            Point3D *p3d = new Point3D();
            string s;

            while (coordinates.good())
            {
                getline(coordinates, s, ']');

                if (s.size() > 0)
                {
                    s = s.substr(1);
                    stringstream c(s);
                    //c >> *p3d;
                    pointthreed.insert(*p3d);
                    count++;
                }
            }
        }
        else if (name == "Line2D")
        {
            stringstream coordinates(test_string);
            Line2D *l2d = new Line2D();
            //c >> *l2d;
            linetwod.insert(*l2d);
            count++;
        }
        else if (name == "Line3D")
        {
            stringstream coordinates(test_string);
            Line3D *l3d = new Line3D();
            //c >> *l3d;
            linethreed.insert(*l3d);
            count++;
        }
    }
    
    cout << count << " records read in successfully." << "\n";
    myfile.close();
}


For example, after the loop has completed
161
162
        while (getline(myfile, no_of_lines))
            ++lines;
the status of myfile will be fail. The position within the file will be right at the end.

Hence the following loop at line 166 cannot succeed
166
167
168
169
    while (myfile.good())
    {
        getline(myfile, name, ',');
        getline(myfile, test_string, '\n');

Before commencing that loop, you would need to clear the file status and reset the position to the start. There is also another logic error. even if the status is good at line 166, it doesn't predict the future, one or both of the following getlines may fail, but the code doesn't check for that.

One might code it like this.
166
167
168
169
170
    myfile.clear();     // reset flags
    myfile.seekg(0);    // reset position to start
    
    while ( getline(myfile, name, ',')  && getline(myfile, test_string, '\n'))
    {

http://www.cplusplus.com/reference/ios/ios/clear/
http://www.cplusplus.com/reference/istream/istream/seekg/


There are similar errors (around lines 177 and 197) - it's hard to debug without an example of the input file "messy.txt" - as well as the other headers.
Last edited on
OHHH! Cool! understand more now, and edited my codes. But however... I'm now facing a different error that is totally new to me, as shown below...

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__functional_base:63:21: Invalid operands to binary expression ('const Point2D' and 'const Point2D')

1
2
3
4
5
6
7
8
9
10
11
#if _LIBCPP_STD_VER > 11
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCPP_TYPE_VIS_ONLY less : binary_function<_Tp, _Tp, bool>
{
    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 
    bool operator()(const _Tp& __x, const _Tp& __y) const
        {return __x < __y;}
};

Which i think is due to this para of codes...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
            std::stringstream coordinates(str);
            Point2D *p2d = new Point2D();
            std::string s;
            
            while(coordinates.good())
            {
                std::getline(coordinates, s, ']');
                
                if (s.size() > 0)
                {
                    s = s.substr(1);
                    std::stringstream c(s);
                    c << p2d;
                    pointtwod.insert(*p2d);
                    count++;
Last edited on
pointtwod is a std::set<Point2D>
A set has two characteristics:
the elements are unique (no duplicates)
the elements are ordered in sequence

In order to satisfy that, it must be possible to compare two objects of type Point2D to see whether one is greater than the other.

In order to get the code to begin to compile, I created this header:
Point2D.h
1
2
3
4
5
6
7
class Point2D {

public:
    friend std::istream & operator >> (std::istream & is, Point2D & p2d);
    bool operator < (const Point2D & rhs) const;

};


The >> operator is in order to allow the object to be extracted from an input stream.
The < operator is required in order to compare two objects.
I couldn't define the body for these functions as I don't have the rest of the header declaration for that type.

Also similar headers for the other types.

By the way, I don't see a need for the use of a pointer here
 
    Point2D *p2d = new Point2D();

A straightforward Point2D p2d; would be simpler (and avoid a memory leak).
Last edited on
Some guesswork here:
Point2D.h
1
2
3
4
5
6
7
8
9
class Point2D {
    double x;
    double y;
public:
    friend std::istream & operator >> (std::istream & is, Point2D & p2d);
    friend std::ostream & operator << (std::ostream & os, const Point2D & p2d);
    bool operator < (const Point2D & rhs) const;

};

corresponding function definitions:
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
std::ostream & operator << (std::ostream & os, const Point2D & p2d)
{
    os << '[' << p2d.x << ',' << p2d.y << ']';
    return os;
}

std::istream & operator >> (std::istream & is, Point2D & p2d)
{
    char left = ' ', comma= ' ', right = ' ';
    is >> left >> p2d.x >> comma >> p2d.y >> right;

    if (!(left == '[' && comma == ',' && right == ']'))
      is.setstate(std::ios::failbit);
    return is;
}

bool Point2D::operator < (const Point2D & rhs) const
{
    if (x < rhs.x)
        return true;
    if ( (x == rhs.x) && (y < rhs.y))
        return true;
            
    return false;
}


A guess at the input file format:
Point2D, [3, 4] [7.5, -9.2] [11.11, 32.14] 

corresponding code in main program (inside function read_in_data()):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
    while ( getline(myfile, name, ',')  && getline(myfile, test_string, '\n') )
    {
        if (name == "Point2D")
        {
            stringstream coordinates(test_string);
            Point2D p2d;

            while (coordinates >> p2d)
            {
                pointtwod.insert(p2d);
                count++;
            }
        }
        else if (etc. ....)

Hi, sorry to trouble again..
How come there's always a [0, 0] appearing at the first line of my result, which was not inside my TXT file... and, the distFrOrigin always display 0.000. Is there anywhere that i did incorrectly again?

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "Point2D.h"
#include "MyTemplates.h"
#include <iostream>
#include <string>
#include <limits>
#include <iomanip>
#include <cmath>

using namespace std;

Point2D::Point2D()
{
}

Point2D::Point2D(int x, int y)
{
    x = x;
    y = y;
}

int Point2D::getX()
{
    return x;
}

void Point2D::setX(int x)
{
    x = x;
}

int Point2D::getY()
{
    return y;
}

void Point2D::setY(int y)
{
    y = y;
}

double Point2D::getScalarValue()
{
    return distFrOrigin;
}

void Point2D::setDistFrOrigin()
{
    distFrOrigin = sqrt(pow(x,2) + pow(y,2));
}

ostream & operator << (ostream & os, const Point2D & p2d)
{
    os << '[' << p2d.x << ',' << "\t\t" << p2d.y << ']' << "\t\t" << fixed << setprecision(3) << p2d.distFrOrigin << '\n';
    return os;
}

istream & operator >> (istream & is, Point2D & p2d)
{
    char left = ' ', comma= ' ', right = ' ';
    is >> left >> p2d.x >> comma >> p2d.y >> right;
    
    if (!(left == '[' && comma == ',' && right == ']'))
        is.setstate(ios::failbit);
    return is;
}

bool Point2D::operator < (const Point2D & rhs) const
{
    if (x < rhs.x)
        return true;
    if ( (x == rhs.x) && (y < rhs.y))
        return true;
    
    return false;
}
How come there's always a [0, 0] appearing at the first line of my result, which was not inside my TXT file... and, the distFrOrigin always display 0.000. Is there anywhere that i did incorrectly again?

It's not possible to respond to questions about things you didn't show, an example of your input file would be a good start. The whole code so it's possible to compile and run the same code which you are running would help.

A couple of things in the code you did post.
This constructor:
1
2
3
Point2D::Point2D()
{
}
doesn't do anything. It leaves the member variables containing garbage. You should set them to a default (zero usually).
Commonly done like this:
1
2
3
4
5
6
Point2D::Point2D()
{
    x = 0.0;
    y = 0.0;
    distFrOrigin = 0.0;
}


but a better syntax is like this:
1
2
3
Point2D::Point2D() : x(0.0), y(0.0), distFrOrigin(0.0)
{ 
}

In this case the difference is trivial, but for more complex types e.g. std::string it is more efficient.

The other constructor might look like this:
1
2
3
4
Point2D::Point2D(double X, double Y) : x(X), y(Y) 
{
    setDistFrOrigin();
} 

note the call to setDistFrOrigin() to set the value of distFrOrigin.

That still leaves a few other gaps to be plugged. Hint - when one has to patch the code in multiple places it can be a sign that the design needs reconsidering. Depending on how frequently the value of distFrOrigin is needed, it might be better to avoid storing it at all, and instead calculate it on-the-fly as required. For example, instead of
1
2
3
4
double Point2D::getScalarValue() const
{
    return distFrOrigin;
}

you might instead put
1
2
3
4
double Point2D::getScalarValue() const
{
    return sqrt(x*x + y*y);
}


Note, x*x is both easier to type and more efficient than a function call to pow(). In some cases (compiler dependent), the latter may even give floating point approximations rather than an exact result.

Regarding the comment on plugging the gaps - if you continue with the current design, remember that any time either or both x or y are changed, then distFrOrigin needs to be recalculated.
Last edited on
After whole day finding the errors, i still unable to make my program show the distance from origin...

Point2D.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "Point2D.h"
#include "MyTemplates.h"
#include <iostream>
#include <string>
#include <limits>
#include <iomanip>
#include <cmath>

using namespace std;

Point2D::Point2D() : x(0), y(0), distFrOrigin(0.000)
{
}

Point2D::Point2D(int x, int y) : x(x), y(y)
{
    x = x;
    y = y;
    setDistFrOrigin();
}

int Point2D::getX()
{
    return x;
}

void Point2D::setX(int x)
{
    x = x;
}

int Point2D::getY()
{
    return y;
}

void Point2D::setY(int y)
{
    y = y;
}

double Point2D::getScalarValue() const
{
    return distFrOrigin;
}

void Point2D::setDistFrOrigin()
{
    distFrOrigin = sqrt((x * x) + (y * y));
}

ostream & operator << (ostream & os, const Point2D & p2d)
{
    os << '[' << p2d.x << ',' << "\t\t" << p2d.y << ']' << "\t\t" << fixed << setprecision(3) << p2d.distFrOrigin << '\n';
    return os;
}

istream & operator >> (istream & is, Point2D & p2d)
{
    char left = ' ', comma= ' ', right = ' ';
    is >> left >> p2d.x >> comma >> p2d.y >> right;
    
    if (!(left == '[' && comma == ',' && right == ']'))
        is.setstate(ios::failbit);
    return is;
}

bool Point2D::operator < (const Point2D & rhs) const
{
    if (x < rhs.x)
        return true;
    if ((x == rhs.x) && (y < rhs.y))
        return true;
    return false;
}

Point2D.h
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
#ifndef Point2D_h
#define Point2D_h

#include <iostream>
#include <fstream>
#include <ostream>
#include <cmath>
#include <string>
#include <stdio.h>

using namespace std;

class Point2D
{
    
protected:
    int x;
    int y;
    double distFrOrigin;
    void setDistFrOrigin();
    
public:
    Point2D();
    Point2D(int, int);

    int getX();
    void setX(int);
    int getY();
    void setY(int);
    double getScalarValue() const;
    
    friend istream & operator >> (istream & is, Point2D & p2d);
    friend ostream & operator << (ostream & os, const Point2D & p2d);
    bool operator < (const Point2D & rhs) const;
};
#endif 


This is where i will show out the results...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void view_data()
{
    cout << "\n" << "Filtering Criteria: " << fc << "\n";
    cout << "Sorting Criteria : " << sc << "\n";
    cout << "Sorting Order: " << so << "\n";
    cout << "\n";
    
    switch(fc)
    {
        case POINT2D:
            cout << " X" << "\t\t" << " Y" << "\t\t" << "Dist. Fr Origin" << "\n";
            cout << "------------------------------------" << "\n";
            for (set <Point2D> :: iterator itr = pointtwod.begin(); itr != pointtwod.end(); itr++)
            {
                cout << const_cast <Point2D&> (*itr);
            }
            break;
Last edited on
Thanks for posting more of the code - particularly the output view_data().


mrmartin93 wrote:
still unable to make my program show the distance from origin...

I don't have time right now to test this (maybe later) but for now, I go back to previous comment:
Chervil wrote:
any time either or both x or y are changed, then distFrOrigin needs to be recalculated.


Let's list the places where either x or y is changed:
1
2
3
4
5
Point2D::Point2D()
Point2D::Point2D(int x, int y)
void Point2D::setX(int x)
void Point2D::setY(int y)
istream & operator >> (istream & is, Point2D & p2d)


Now check in which of those distFrOrigin is set according to the updated values of x and y.

Sorry this reply is so brief - I have to go out soon.
Hi, thanks for your prompt reply...

Ya, the program will read the x and y from a txt file, each line of x and y will be different. Thus, need to calculate the area everytime.
Ya, the program will read the x and y from a txt file, each line of x and y will be different. Thus, need to calculate the area everytime.

area? I thought it was distance.

Anyway I hope you figured out that you need to add code inside each of these functions to set the correct value of distFrOrigin:
1
2
3
void Point2D::setX(int x)
void Point2D::setY(int y)
istream & operator >> (istream & is, Point2D & p2d)


In the function view_data(), rather than an additional cast like this:
 
    const_cast <Point2D&> (*itr)

I'd suggest simply change the type of itr from
 
    set <Point2D> :: iterator itr
to
 
    set <Point2D> :: const_iterator itr


The line cout << *itr << '\n'; would be ok, but it doen't do what the column headings state.

Perhaps something like this:
1
2
cout << setw(10) << itr->getX() << setw(10) << itr->getY() 
     << setw(10) << itr->getScalarValue() << '\n';

Last edited on
Sorry, is distance...

Somehow understand what you trying to teach me, but have no idea why it just doesn't work... it just doesn't display the distance from origin... it can't even get calculated out from my Point2D.cpp... Is there any where that i've missed out while checking my codes?

Even if i self-input the variable to calculate distance from origin, the result will still be 0.000

I think my error should be here... But guess i'm not experienced enough to notice out my own mistakes...
<POINT2D.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "Point2D.h"
#include "MyTemplates.h"
#include <iostream>
#include <ostream>
#include <fstream>
#include <sstream>
#include <string>
#include <limits>
#include <iomanip>
#include <cmath>

using namespace std;

Point2D::Point2D() : x(0), y(0), distFrOrigin(0.000)
{
}

Point2D::Point2D(int X, int Y)
{
    x = X;
    y = Y;
}

int Point2D::getX()
{
    return x;
}

void Point2D::setX(int set_x)
{
    x = set_x;
}

int Point2D::getY()
{
    return y;
}

void Point2D::setY(int set_y)
{
    y = set_y;
}

double Point2D::getScalarValue() const
{
    return distFrOrigin;
}

void Point2D::setDistFrOrigin()
{
    distFrOrigin = sqrt((x * x) + (y * y));
}

ostream & operator << (ostream& os, const Point2D& p2d)
{
    os << '[' << p2d.x << ',' << "\t\t" << p2d.y << ']' << "\t\t" << fixed << setprecision(3) << p2d.distFrOrigin << '\n';
    return os;
}

istream & operator >> (istream & is, Point2D & p2d)
{
    char left = ' ', comma= ' ', right = ' ';
    is >> left >> p2d.x >> comma >> p2d.y >> right;
    
    if (!(left == '[' && comma == ',' && right == ']'))
        is.setstate(ios::failbit);
    return is;
}

bool Point2D::operator < (const Point2D & rhs) const
{
    if (x < rhs.x)
        return true;
    if ((x == rhs.x) && (y < rhs.y))
        return true;
    return false;
}

<POINT2D.H>
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
#ifndef Point2D_h
#define Point2D_h

#include <iostream>
#include <fstream>
#include <ostream>
#include <cmath>
#include <string>
#include <stdio.h>

using namespace std;

class Point2D
{
    
protected:
    int x;
    int y;
    double distFrOrigin;
    void setDistFrOrigin();
    
public:
    Point2D();
    Point2D(int, int);

    int getX();
    void setX(int);
    int getY();
    void setY(int);
    double getScalarValue() const;
    
    friend istream & operator >> (istream & is, Point2D & p2d);
    friend ostream & operator << (ostream & os, const Point2D & p2d);
    bool operator < (const Point2D & rhs) const;
};
#endif 
Last edited on
<MAIN.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <set>
#include "Point2D.h"
#include "Point3D.h"
#include "Line2D.h"
#include "Line3D.h"

using namespace std;

Point2D point2d;
Point3D point3d;
Line3D line3d;
Line2D line2d;
string no_of_lines, filename, infile, outfile;
ifstream ifs;
ofstream ofs;
int lines;
void intro_menu();
void read_in_data();
void filtering_criteria();
void sorting_criteria();
void sorting_order();
void view_data();

set<Point2D> pointtwod;
set<Point3D> pointthreed;
set<Line2D> linetwod;
set<Line3D> linethreed;

enum FilteringCriteria
{
    POINT2D, POINT3D, LINE2D, LINE3D,
};
FilteringCriteria fc = POINT2D;
ostream& operator << (ostream& os, FilteringCriteria fc)
{
    switch(fc)
    {
        case POINT2D:
            return os << "Point2D";
            
        case POINT3D:
            return os << "Point3D";
            
        case LINE2D:
            return os << "Line2D";
            
        case LINE3D:
            return os << "Line3D";
    }
}

enum SortingCriteria
{
    pt1, pt2, pt3, length,
};
SortingCriteria sc = pt1;
ostream& operator << (ostream& os, SortingCriteria sc)
{
    switch(sc)
    {
        case pt1:
            return os << "Pt. 1's (x, y) values";
            
        case pt2:
            return os << "Pt. 2's (x, y) values";
            
        case pt3:
            return os << "Pt.3 's (x, y, z) values";
            
        case length:
            return os << "Length";
    }
}

enum SortingOrder
{
    ASC, DESC,
};
SortingOrder so = ASC;
ostream& operator << (ostream& os, SortingOrder so)
{
    switch(so)
    {
        case pt1:
            return os << "Ascending Order";
            
        case pt2:
            return os << "Descending Order";
    }
}

void read_in_data()
{
    string classname, str;
    int count;
    cout << "Please Enter Filename : ";
    cin >> filename;
    myfile.open(filename.c_str(),std::ios::in);
    if(ifs.is_open())
    {
    while (getline(ifs, classname, ',') && getline(ifs, str, '\n'))
        if (classname == "Point2D")
        {
            stringstream coordinates(str);
            Point2D p2d;
            while (coordinates >> p2d)
            {
                pointtwod.insert(p2d);
                count++;
            }
        }
        else if (classname == "Point3D")
        {
        stringstream coordinates(str);
        Point3D p3d;
        while (coordinates >> p3d)
            {
            pointthreed.insert(p3d);
            count++;
            }
        }
        else if (classname == "Line2D")
        {
            stringstream coordinates(str);
            Line2D l2d;
            while (coordinates >> l2d)
            {
                linetwod.insert(l2d);
                count++;
            }
        }
        else if (classname == "Line3D")
        {
            stringstream coordinates(str);
            Line3D l3d;
            coordinates >> l3d;
            linethreed.insert(l3d);
        count++;
        }
    cout << count << " records read in successfully." << "\n";
    ifs.close();
    }
}

void filtering_criteria()
{
    string input_filter;
    cout << "\n" << "---------------------------------------------------------------" << "\n";
    cout << "-----------------  SPECIFY FILTERING CRITERIA  ----------------" << "\n";
    cout << "CURRENT : " << fc << "\n";
    cout << "---------------------------------------------------------------" << "\n";
    cout << "\n";
    cout << "a)\t" << POINT2D << " records" << "\n";
    cout << "b)\t" << POINT3D << " records" << "\n";
    cout << "c)\t" << LINE2D << " records" << "\n";
    cout << "d)\t" << LINE3D << " records" << "\n" << "\n";
    cout << "Please Enter Your Criteria (a - d) : ";
    cin >> input_filter;
    cout << "\n";
    switch(input_filter[0])
    {
        case 'a':
            fc = POINT2D;
            break;
            
        case 'b':
            fc = POINT3D;
            break;
            
        case 'c':
            fc = LINE2D;
            break;
            
        case 'd':
            fc = LINE3D;
            break;
            
        default:
            cout << "Wrong Input. Please Try Again." << "\n";
            break;
    }
    cout << "Filtering criteria successfully set to " << fc << "." << "\n";
}

void sorting_criteria()
{
    string input_sort;
    cout << "Specifying Sorting Criteria (Current: " << sc << ")" << "\n" << "\n";
    cout << "a)\t" << pt1 << "\n";
    cout << "b)\t" << pt2 << "\n";
    cout << "c)\t" << length << "\n";
    cout << "Please Enter Your Criteria (a - c) : ";
    cin >> input_sort;
    
    switch(input_sort[0])
    {
        case 'a':
            sc = pt1;
            break;
            
        case 'b':
            sc = pt2;
            break;
            
        case 'c':
            sc = length;
            break;
            
        default:
            cout << "Wrong Input. Please Try Again." << "\n";
            break;
    }
    cout << "Sorting criteria successfully set to " << sc << "." << "\n";
}

void sorting_order()
{
    string input_order;
    cout << "Specifying Sorting Order (Current: " << so << ")" << "\n" << "\n";
    cout << "a)\t" << ASC << "\n";
    cout << "b)\t" << DESC << "\n";
    cout << "Please enter your order (a or b): ";
    cin >> input_order;
    
    switch(input_order[0])
    {
        case 'a':
            so = ASC;
            break;
            
        case 'b':
            so = DESC;
            break;
            
        default:
            cout << "Wrong Input. Please Try Again." << "\n";
    }
}

void view_data()
{
    cout << "\n" << "Filtering Criteria: " << fc << "\n";
    cout << "Sorting Criteria : " << sc << "\n";
    cout << "Sorting Order: " << so << "\n";
    cout << "\n";
    
    switch(fc)
    {
        case POINT2D:
            cout << " X" << "\t\t" << " Y" << "\t\t" << "Dist. Fr Origin" << "\n";
            cout << "------------------------------------" << "\n";
            for (set <Point2D> :: const_iterator itr = pointtwod.begin(); itr != pointtwod.end(); itr++)
            {
                cout << const_cast <Point2D&> (*itr);
            }
            break;
            
        case POINT3D:
            cout << " X" << "\t\t" << "Y" << "\t\t" << "Z" << "\t\t" << "Dist. Fr Origin" << "\n";
            cout << "----------------------------------------------------" << "\n";
            for (set <Point3D> :: const_iterator itr = pointthreed.begin(); itr != pointthreed.end(); itr++)
            {
                cout << const_cast <Point3D&> (*itr);
            }
            break;
            
        case LINE2D:
            cout << " P1-X  P1-Y     P2-X  P2-Y  Length" << "\n";
            cout << "-----------------------------------" << "\n";
            
            for (set <Line2D> :: const_iterator itr = linetwod.begin(); itr != linetwod.end(); itr++)
            {
                cout << const_cast <Line2D&> (*itr);
            }
            break;
            
        case LINE3D:
            cout << " P1-X   P1-Y   P1-Z   P2-X   P2-Y   P2-Z   Length" << "\n";
            cout << "-----------------------------------------------" << "\n";
            for (set <Line3D> :: const_iterator itr = linethreed.begin(); itr != linethreed.end(); itr++)
            {
                cout << const_cast <Line3D&> (*itr);
            }
        break;
    }
}
Finally made it to display the distance from origin!!!
One last question... how do i sort the set (e.g. Point2D) by ascending / descending order & by X axis, Y axis or Distance Length?

Some snippets of what i've tried playing around...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void view_data()
{
    cout << "\n" << "Filtering Criteria: " << fc << "\n";
    cout << "Sorting Criteria : " << sc << "\n";
    cout << "Sorting Order: " << so << "\n";
    cout << "\n";
    
    switch(fc)
    {
        case POINT2D:
            cout << " X" << "\t\t" << " Y" << "\t\t" << "Dist. Fr Origin" << "\n";
            cout << "------------------------------------" << "\n";
            for (set <Point2D, less<Point2D>> :: const_iterator itr = pointtwod.begin(); itr != pointtwod.end(); itr++)
            {
                cout << const_cast <Point2D&> (*itr);
            }
            break;

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
void sorting_order()
{
    string input_order;
    cout << "Specifying Sorting Order (Current: " << so << ")" << "\n";
    cout << "\n";
    cout << "a)\t" << ASC << "\n";
    cout << "b)\t" << DESC << "\n";
    cout << "Please enter your order (a or b): ";
    cin >> input_order;
    
    switch(input_order[0])
    {
        {
        case 'a':
            so = ASC;
            set<Point2D, less<Point2D>> :: iterator p = pointtwod.begin();
            while (p != pointtwod.end())
            {
                cout << *p << "\n";
                p++;
            }
            break;
        }
        {
        case 'b':
            so = DESC;
            break;
        }
        {
        default:
            cout << "Wrong Input. Please Try Again." << "\n";
        }
    }
}

1
2
3
4
set<Point2D, less<Point2D>> pointtwod;
set<Point3D, less<Point3D>> pointthreed;
set<Line2D, less<Line2D>> linetwod;
set<Line3D, less<Line3D>> linethreed;
Just a quick note - I haven't forgotten this thread, but have been a bit tied up with other matters.
okay sure! really appreciate your help..
@Chervil ... sorry, need your help urgently... as i need to submit my coding soon... sorry :(
Actually I've been looking at this today. I tried to use as much as possible of your most recent code - though some of it was incomplete or didn't compile for me.

Anyway, one issue I think is that you are using std::set as a container. If you sort by 'distance from origin', some unique points will no longer have a unique sort order - more than one point may be at the same distance etc.

There are a number of solutions - I just went for one which was familiar, use a temporary std::vector to hold a copy of the data, and then sort according to requirements.

Roughly, I have this:
Point2D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
ostream & operator << (ostream& os, const Point2D& p2d)
{
    os << fixed << setprecision(3) << '[' 
       << std::setw(10) << p2d.x << ',' 
       << std::setw(10) << p2d.y << ']' 
       << std::setw(10) << p2d.distFrOrigin;
    return os;
}

istream & operator >> (istream & is, Point2D & p2d)
{
    char left = ' ', comma= ' ', right = ' ';
    is >> left >> p2d.x >> comma >> p2d.y >> right;   
    
    if (!(left == '[' && comma == ',' && right == ']'))
        is.setstate(ios::failbit);
    else
        p2d.setDistFrOrigin();	
    return is;
}


main.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
void sorting_order()
{
    string input_order;
    cout << "Specifying Sorting Order (Current: " << so << ")" << "\n";
    cout << "\n";
    cout << "a)\t" << ASC << "\n";
    cout << "b)\t" << DESC << "\n";
    cout << "Please enter your order (a or b): ";
    cin >> input_order;
    
    switch(input_order[0])
    {
        {
        case 'a':
            so = ASC;
            break;
        }
        {
        case 'b':
            so = DESC;
            break;
        }
        {
        default:
            cout << "Wrong Input. Please Try Again." << "\n";
        }
    }
}


1
2
3
4
5
6
7
8
9
10
11
12
void view_data()
{
    cout << "\n" << "Filtering Criteria: " << fc << "\n";
    cout << "Sorting Criteria : " << sc << "\n";
    cout << "Sorting Order: " << so << "\n";
    cout << "\n";
    
    switch(fc)
    {
        case POINT2D:
            view_Point2D();
            break;


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
bool p2d_length_ASC(const Point2D& left, const Point2D& right)
{
    return left.getScalarValue() < right.getScalarValue();
}

bool p2d_length_DESC(const Point2D& left, const Point2D& right)
{
    return left.getScalarValue() > right.getScalarValue();
}

void view_Point2D()
{
    cout << std::setw( 7) << "X" 
         << std::setw(11) << "Y"  
         << std::setw(24) << "Dist. Fr Origin" << "\n";
//    cout << "------------------------------------" << "\n";
//        
//    for (set <Point2D> :: const_iterator itr = pointtwod.begin(); itr != pointtwod.end(); itr++)
//    {
//        cout << *itr << '\n';
//    }
    
    cout << "------------------------------------" << "\n";
    std::vector<Point2D> points(pointtwod.begin(), pointtwod.end());
    if (sc == length &&  so == DESC)
        std::sort(points.begin(), points.end(), p2d_length_DESC);
    else if (sc == length &&  so == ASC)
        std::sort(points.begin(), points.end(), p2d_length_ASC);
     
    for (size_t i=0; i<points.size(); ++i)
        cout << points[i] << '\n';    
    
}


That is incomplete - only added a couple of the many sorting options.
my input and output:
Point2D, [3, 4] [7.5, -9.2] [11.11, 32.14] 
Point2D, [-3, 4] [7.5, 8.5] [1.9230769230769230769,  4.6153846153846153846] 
Point2D, [3, -4] [-7.5, 8.5]  


Please Enter Filename : 8 records read in successfully.

Filtering Criteria: Point2D
Sorting Criteria : Pt. 1's (x, y) values
Sorting Order: Ascending Order

      X          Y         Dist. Fr Origin
------------------------------------
[    -7.500,     8.500]    11.336
[    -3.000,     4.000]     5.000
[     1.923,     4.615]     5.000
[     3.000,    -4.000]     5.000
[     3.000,     4.000]     5.000
[     7.500,    -9.200]    11.870
[     7.500,     8.500]    11.336
[    11.110,    32.140]    34.006
Specifying Sorting Criteria (Current: Pt. 1's (x, y) values)

a)      Pt. 1's (x, y) values
b)      Pt. 2's (x, y) values
c)      Length
Please Enter Your Criteria (a - c) : Sorting criteria successfully set to Length.
Specifying Sorting Order (Current: Ascending Order)

a)      Ascending Order
b)      Descending Order
Please enter your order (a or b):
Filtering Criteria: Point2D
Sorting Criteria : Length
Sorting Order: Descending Order

      X          Y         Dist. Fr Origin
------------------------------------
[    11.110,    32.140]    34.006
[     7.500,    -9.200]    11.870
[    -7.500,     8.500]    11.336
[     7.500,     8.500]    11.336
[    -3.000,     4.000]     5.000
[     1.923,     4.615]     5.000
[     3.000,    -4.000]     5.000
[     3.000,     4.000]     5.000
Specifying Sorting Order (Current: Descending Order)

a)      Ascending Order
b)      Descending Order
Please enter your order (a or b):
Filtering Criteria: Point2D
Sorting Criteria : Length
Sorting Order: Ascending Order

      X          Y         Dist. Fr Origin
------------------------------------
[    -3.000,     4.000]     5.000
[     1.923,     4.615]     5.000
[     3.000,    -4.000]     5.000
[     3.000,     4.000]     5.000
[    -7.500,     8.500]    11.336
[     7.500,     8.500]    11.336
[     7.500,    -9.200]    11.870
[    11.110,    32.140]    34.006

Thank you!!! and one last last final help required... How do i show Line2D out from Point2D... It keep showing me 5 and -5 whether i display the output, but 1 , 4 and 5 are missing... in my txt file, it is Line2D, [5, 7], [3, 8]
1
2
3
4
5
The output needed is : -
   point1-x    point1-y    point2-x   point2-y   length
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
      [5,            7]             [3,            8]           5
      [-14,         40]          [50,          3]          25


I couldn't display the Point2 of X and Y axis.
Line2D.H
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
#ifndef Line2D_h
#define Line2D_h

#include <stdio.h>
#include <iostream>
#include <string>
#include "Point2D.h"

using namespace std;

class Line2D : public Point2D
{
private:
    Point2D pt1;
    Point2D pt2;

protected:
    double length;
    void setLength();

public:
    Line2D();
    Line2D(Point2D, Point2D);
    Point2D getPt1() const;
    Point2D getPt2() const;
    double getScalarValue() const;

    void setPt1(Point2D);
    void setPt2(Point2D);
    
    friend istream & operator >> (istream & is, Line2D & l2d);
    friend ostream & operator << (ostream & os, const Line2D & l2d);
    bool operator < (const Line2D & rhs) const;
};
#endif 

Line2D.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <iostream>
#include <ostream>
#include <fstream>
#include <sstream>
#include <string>
#include <limits>
#include <iomanip>
#include <cmath>
#include "Line2D.h"
#include "Point2D.h"

using namespace std;

Line2D::Line2D()
{
    pt1 = Point2D();
    pt2 = Point2D();
}

Line2D::Line2D(const Point2D point1, const Point2D point2)
{
    pt1 = point1;
    pt2 = point2;
    setLength();
    length = getScalarValue();
}

Point2D Line2D::getPt1() const
{
    pt1.Point2D::getX();
    pt1.Point2D::getY();
    return pt1;
}

void Line2D::setPt1(Point2D PT1)
{
    this -> pt1 = PT1;
    setLength();
}

Point2D Line2D::getPt2() const
{
    pt2.Point2D::getX();
    pt2.Point2D::getY();
    return pt2;
}

void Line2D::setPt2(Point2D PT2)
{
    this -> pt2 = PT2;
    setLength();
}

double Line2D::getScalarValue() const
{
    return length;
}

void Line2D::setLength()
{
    length = sqrt(pow((pt1.getX() - pt2.getX()),2) + pow((pt1.getY() - pt2.getY()),2));
}

ostream & operator << (ostream & out, const Line2D& l2d)
{
    out << '[' << l2d.x << ',' << "\t\t" << l2d.y << ']' << "\t\t " << '[' << l2d.getX() << ',' << "\t\t" << l2d.pt2.y << ']' << "\t\t" << fixed << setprecision(3) << l2d.length << '\n';
    return out;
}

istream & operator >> (istream& in, Line2D& l2d)
{
    char left = ' ', comma= ' ', right = ' ';
    in >> left >> l2d.x >> comma >> l2d.y >> right;
    
    if (!(left == '[' && comma == ',' && right == ']'))
        in.setstate(ios::failbit);
    else
        l2d.setLength();
    return in;
}

bool Line2D::operator < (const Line2D& rhs) const
{
    if (x < rhs.x)
        return true;
    if ((x == rhs.x) && (y < rhs.y))
        return true;
    return false;
}

Point2D.h
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
#ifndef Point2D_h
#define Point2D_h

#include <iostream>
#include <fstream>
#include <ostream>
#include <cmath>
#include <string>
#include <stdio.h>

using namespace std;

class Point2D
{
protected:
    int x;
    int y;
    double distFrOrigin;
    void setDistFrOrigin();
    
public:
    Point2D();
    Point2D(int x, int y);

    int getX() const;
    void setX(int);
    int getY() const;
    void setY(int);
    double getScalarValue() const;
    
    friend istream& operator >> (istream & in, Point2D& p2d);
    friend ostream& operator << (ostream& out, const Point2D& p2d);
    bool operator < (const Point2D & rhs) const;
};
#endif 

MAIN.CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void view_data()
{
    cout << "\n" << "Filtering Criteria: " << fc << "\n";
    cout << "Sorting Criteria : " << sc << "\n";
    cout << "Sorting Order: " << so << "\n";
    cout << "\n";
    
    switch(fc)
    {
        case LINE2D:
            cout << " P1-X" << "\t\t" << "P1-Y" << "\t\t" << "P2-X" << "\t\t" << "P2-Y" << "\t\t" << "Length" << "\n";
            cout << "----------------------------------------------------" << "\n";
            
            for (set <Line2D> :: const_iterator itr = linetwod.begin(); itr != linetwod.end(); itr++)
            {
                cout << const_cast <Line2D&> (*itr);
            }
            break;
}
Last edited on
Pages: 12