ADVERTISEMENT

One of the works done by our Robotics and Machine Learning division,
SELF-LEVELING QUADCOPTER
Arduino based Quadcopter.
Self-leveling is acheived by the aligning the quadcopter using the readings from the gryo as well as the accelerometer.
A four channel RC transmitter is used to control the movement of the quadcopter when in flight. Kindly subscribe to our YouTube Channel and stay tuned.

Tuesday 26 April 2016

CSE1002:BONUS:POLYGON

POLYGON
Design an class polygon to represent a polygon in a two dimensional space. Provide member functions to get the details of the polygon and compute area

UML:

CODE:

#include <cmath>
point::point()
{x=y=0;}
void point::get()
{cin>>x>>y;}
ostream& operator<<(ostream& Out,point p)
{
Out<<p.x<<" "<<p.y<<endl;
return Out;
}
void outofrange::what()
{
cout<<"Out of range";
}
polygon::polygon(int n)
{
num_Of_Ver=n;
vertices=new point[n];
}
polygon::~polygon()
{
delete(vertices);
}
void polygon::get()
{
vertices=new point[num_Of_Ver];
for(int i=0;i<num_Of_Ver;i++)
 cin>>(vertices+i)->x>>(vertices+i)->y;

}
point& polygon::operator[](int idx)
{
if(idx>num_Of_Ver)
 throw outofrange();
return *(vertices+idx);
}
double polygon::area()
{
double a;
for(int i=0;i<num_Of_Ver;i++)
 {
 a+=(vertices+i)->x*((vertices+(i+1)%num_Of_Ver)->y);
 a-=(vertices+i)->y*((vertices+(i+1)%num_Of_Ver)->x);
 }
 return abs(a/2);

}


No comments:

Post a Comment