Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <vector>
- #include <math.h>
- using namespace std;
- class Poligon{
- private:
- vector<double> x;
- vector<double> y;
- int n;
- public:
- void setPoligon(int m,vector<double>p,vector<double>q){
- n=m;x=p;y=q;
- }
- void print(){
- cout << "[" << fixed << setprecision(2) << x[0] << "," << y[0] << "]" << "-" << "[" << x[n-1] << "," << y[n-1] << "]" << endl;
- cout << fixed << setprecision(2) << keliling() << endl;
- }
- double keliling(){
- double Kx,Ky,Kl,K=0;
- for(int i=0;i<n-1;i++){
- Kx=(x[i]-x[i+1])*(x[i]-x[i+1]);
- Ky=(y[i]-y[i+1])*(y[i]-y[i+1]);
- K+=sqrt(Kx+Ky);
- }
- Kl=sqrt(((x[0]-x[n-1])*(x[0]-x[n-1])) + ((y[0]-y[n-1])*(y[0]-y[n-1])));
- K=(K+Kl);
- return K;
- }
- };
- int main (){
- int n;
- cin >> n;
- vector<double> vx;
- vector<double> vy;
- Poligon g;
- double x,y;
- for(int i=0;i<n;i++){
- cin >> x >> y;
- vx.push_back(x);
- vy.push_back(y);
- g.setPoligon(n,vx,vy);
- }
- g.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement