Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Create 2 separate scripts that will check whether 4 coordinates of 4 vertices

ID: 3673549 • Letter: 1

Question

1. Create 2 separate scripts that will check whether 4 coordinates of 4 vertices will form a square, rectangle, or other kind of quadrangle. If they form a square or a rectangle, your script should calculate the size of the shape.

Output suggestion.

Please type in x-component of coordinate 1 .

Please type in y-component of coordinate 1 . (This goes from coordinate 1 to coordinate 4)

Here is the result.

Those vertices will form a square with size of xxx.xx

(or)

Those vertices will form a rectangle with size of xxx.xx

(or)

Those vertices will not form neither square nor rectangle.

Come up with 2 different algorithm that will do this!

The two different methods on decision making part should create the same result (Give it a try!)


PLEASE BE SURE TO USE DEV C++ (<stdio.h>)

Thank you in advance!

Explanation / Answer

class Point
{
int x,y;
Point(int x1,int y1)
{
   x=x1;
   y=y1;
}

}

bool checkRectangle(Point p1, Point p2, Point p3, Point p4)
{
if (p1.x > p4.x || p3.x > p2.x)
return false;
if (p1.y < p4.y || p3.y < p2.y)
return false;

return true;
}


int calDist(Point p, Point q)
{
return (p.x - q.x)*(p.x - q.x) +
(p.y - q.y)*(p.y - q.y);
}
bool checkSquare(Point p1, Point p2, Point p3, Point p4)
{
int d2 = calDist(p1, p2);
int d3 = calDist(p1, p3);
int d4 = calDist(p1, p4);

if (d2 == d3 && 2*d2 == d4)
{
int d = calDist(p2, p4);
return (d == calDist(p3, p4) && d == d2);
}

if (d3 == d4 && 2*d3 == d2)
{
int d = calDist(p2, p3);
return (d == calDist(p2, p4) && d == d3);
}
if (d2 == d4 && 2*d2 == d3)
{
int d = calDist(p2, p3);
return (d == calDist(p3, p4) && d == d2);
}

return false;
}

class Test
{
int main()

{
int x1,x2,x3,x4,y1,y2,y3,y4;
cout<<"Please type in x-component of coordinate 1:"
cin>>x1;
cout<<"Please type in y-component of coordinate 1:"
cin>>y1;
cout<<"Please type in x-component of coordinate 2:"
cin>>x2;
cout<<"Please type in y-component of coordinate 2:"
cin>>y2;
cout<<"Please type in x-component of coordinate 3:"
cin>>x3;
cout<<"Please type in y-component of coordinate 3:"
cin>>y3;
cout<<"Please type in x-component of coordinate 4:"
cin>>x4;
cout<<"Please type in y-component of coordinate 4:"
cin>>y4;

Point p1=new Point(x1,y1);
Point p2new Point(x2,y2);
Point p3=new Point(x3,y3);
Point p4=new Point(x4,y4);
bool squareflag=false;
checkSquare(p1, p2, p3, p4)?squareflag=true:squareflag=false;
if(squareflag)
{
cout<<"Square"
int dist=calDist(p1,p2);
cout<<"Are of square is:"<<dist*dist;
}
if(!squareflag)
   if (checkRectangle(p1, p2, p3, p4))
       {
           cout<<"Rectangle";
           int dist1=calDist(p1,p2);
           int dist2=calDist(p2,p3);
           cout<<"Are of rectangle is:"<<dist1*dist2;

       }
       else "quadrangle"
}
}

I hope this helps! Have a good day :)