Advertisement
Guest User

Untitled

a guest
May 29th, 2015
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <vector>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. class Poligon{
  9. protected:
  10. vector<double> x;
  11. vector<double> y;
  12. int n;
  13. public:
  14. void setPoligon(int r, double s, double t){
  15. n=r;
  16. x.push_back(s);
  17. y.push_back(t);
  18. }
  19. };
  20.  
  21. class Segitiga : public Poligon{
  22. private:
  23. double L[100];
  24. public:
  25. double luas(){
  26. double Det, Luas=0;
  27. for(int i=0;i<n;i++){
  28. Det=0;
  29. Det+=x[i*3]*y[1+(i*3)] + x[2+(i*3)]*y[i*3] + x[1+(i*3)]*y[2+(i*3)] - (x[2+(i*3)]*y[1+(i*3)] + x[i*3]*y[2+(i*3)] + x[1+(i*3)]*y[i*3]);
  30. L[i]=abs(Det/2);
  31. Luas+=L[i];
  32. }
  33. return Luas/n;
  34. }
  35.  
  36. int besar(){
  37. int besar=0;
  38. for(int i=0;i<n;i++){
  39. if(L[i]>luas()) besar++;
  40. }
  41. return besar;
  42. }
  43.  
  44. void print(){
  45. cout << fixed << setprecision(2) << luas()<< " ";
  46. }
  47. void printBesar(){
  48. cout << besar() << " ";
  49. }
  50. };
  51.  
  52. class Segiempat : public Poligon{
  53. private:
  54. double P[100];
  55. public:
  56. double luas(){
  57. double Px,Py,Pz,Luas=0,index=0;
  58. for(int i=0;i<n;i++){
  59. P[i]=0;
  60. for(int j=0;j<3;j++){
  61. Px =((x[index+j+1]-x[index+j])*(x[index+j+1]-x[index+j]));
  62. Py =((y[index+j+1]-y[index+j])*(y[index+j+1]-y[index+j]));
  63. P[i]+=sqrt(Px+Py);
  64. }
  65. Pz=sqrt((x[i*4]-x[(i*4)+3])*(x[i*4]-x[(i*4)+3]) + (y[i*4]-y[(i*4)+3])*(y[i*4]-y[(i*4)+3]));
  66. P[i]+=Pz;
  67. Luas+=(P[i]/4)*(P[i]/4);
  68. index+=4;
  69. }
  70. return Luas/n;
  71. }
  72.  
  73. int besar(){
  74. int besar=0;
  75. for(int i=0;i<n;i++){
  76. if(P[i]>luas()) besar++;
  77. }
  78. return besar;
  79. }
  80.  
  81. void print(){
  82. cout << fixed << setprecision(2) << luas() << endl;
  83. }
  84. void printBesar(){
  85. cout << besar() << endl;
  86. }
  87. };
  88.  
  89. int main (){
  90. int n,m;
  91. Segiempat E;
  92. Segitiga T;
  93. double x,y;
  94.  
  95. cin >> n;
  96. for(int i=0;i<n*3;i++){
  97. cin >> x >> y;
  98. T.setPoligon(n,x,y);
  99. }
  100.  
  101. cin >> m;
  102. for(int i=0;i<m*4;i++){
  103. cin >> x >> y;
  104. E.setPoligon(m,x,y);
  105. }
  106.  
  107. T.print();
  108. E.print();
  109. T.printBesar();
  110. E.printBesar();
  111. return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement