CSE1002 Sort a Given Set of Points
Design a OOP model to represent a point in a two dimensional space and overload the operators >>,<<, > and ==. Given 'n' points, design an algorithm and write a C++ code to sort them in desceding order. While sorting a point is said to be greater than the other based on their x-coordinate value. If value of x-coordinate is same for both the points then make a decision based on their value of y-coordinate.
==============================================================
UML:
CODE:
istream& operator>>(istream& in,point &p)
{
in>>p.x>>p.y;
return in;
}
ostream& operator<<(ostream& out,point& p)
{
out<<p.x<<endl<<p.y<<endl;
return out;
}
bool point::operator==(point& p)
{
return p.x==x&&p.y==y;
}
bool point::operator>(point& p)
{
if(p.x==x)
return y>p.y;
return x>p.x;
}
void sort_Points(point *p,int s)
{
point temp;
for(int i=0;i<s;i++)
for(int j=i+1;j<s;j++)
if(*(p+j)>*(p+i))
{temp=*(p+i);
*(p+i)=*(p+j);
*(p+j)=temp;}
}
Casino of the Sky - Mapyro
ReplyDeleteMapyro. 1 Southwell Way, Glacford, Connecticut Address. 1.5m, Glacford, CT 경상남도 출장샵 06382 Address. 1.5m. Glacford, 서산 출장안마 Connecticut 06382 Address. 1.5m. Glacford, Connecticut 06382 Address. 1.5m. Glacford, Connecticut 06382 Address. 충청북도 출장샵 1.5m. 경상북도 출장안마 Glacford, 창원 출장샵 Connecticut 06382.