### how can i do that

i need to write a C++ program that outputs all distinct points from a given list of 10 points.where each point has x and y values (in the 2D plane)
For example,
Input:
x y
3 5
4 2
2 4
3 5
7 8
7 8
4 2
7 8
3 5
2 4

Output:
Distinct Points
x y
3 5
4 2
2 4
7 8
i need to use structure
like struct point {
int x; int y;
}

also i need to use array length will be 10.

how shall i do that?
Here is a little skeleton to get you started, have a look if you understand the concept.
Using a vector, operator overloading and algorithms would make your life much easier, but I am afraid this is a kind of exercise where your hands got handcuffed behind your back.
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344`` ``````#include using namespace std; struct Point { int x; int y; }; const int NUM_POINTS = 10; bool EqualPoints(const Point& p1, const Point& p2) { //check if the points are equal, return true if they are otherwise false } bool PointInArray(Point[] points, const Point& p) { // loop through all the points in array points for (int i = 0; i < NUM_POINTS; i++) { if (EqualPoints(points[i], tmp)) { return true; } } return false; } int main() { Point points[NUM_POINTS]; int index = -1; // stores the index of the last inserted point in the array. for (int = 0; i < NUM_POINTS; i++) { Point tmp; // read x and y into tmp // if tmp isn't in points, add it and increment index. } return 0; }``````

if you sort the list then adjacent items are either duplicates, or not.
you should use a vector, not array, for lots of reasons including built in sort.

When searching the array as in function `PointInArray()` above, no need to search the entire array. Just the part which is actually used. You could add an extra parameter which would be the current number of items.
Topic archived. No new replies allowed.