Advertisement
Guest User

Untitled

a guest
May 23rd, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <vector>
  4. #include <math.h>
  5.  
  6. using namespace std;
  7.  
  8. class Poligon{
  9. private:
  10. vector<double> x;
  11. vector<double> y;
  12. int n;
  13. public:
  14. void setPoligon(int m,vector<double>p,vector<double>q){
  15. n=m;x=p;y=q;
  16. }
  17. void print(){
  18. cout << "[" << fixed << setprecision(2) << x[0] << "," << y[0] << "]" << "-" << "[" << x[n-1] << "," << y[n-1] << "]" << endl;
  19. cout << fixed << setprecision(2) << keliling() << endl;
  20. }
  21. double keliling(){
  22. double Kx,Ky,Kl,K=0;
  23. for(int i=0;i<n-1;i++){
  24. Kx=(x[i]-x[i+1])*(x[i]-x[i+1]);
  25. Ky=(y[i]-y[i+1])*(y[i]-y[i+1]);
  26. K+=sqrt(Kx+Ky);
  27. }
  28. Kl=sqrt(((x[0]-x[n-1])*(x[0]-x[n-1])) + ((y[0]-y[n-1])*(y[0]-y[n-1])));
  29. K=(K+Kl);
  30. return K;
  31. }
  32. };
  33.  
  34. int main (){
  35. int n;
  36. cin >> n;
  37. vector<double> vx;
  38. vector<double> vy;
  39. Poligon g;
  40. double x,y;
  41. for(int i=0;i<n;i++){
  42. cin >> x >> y;
  43. vx.push_back(x);
  44. vy.push_back(y);
  45. g.setPoligon(n,vx,vy);
  46. }
  47. g.print();
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement