Advertisement
Guest User

Untitled

a guest
Jul 26th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <cmath>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. class Punkt
  9. {
  10. public:
  11. float x;
  12. float y;
  13. void display()
  14. {
  15. cout<<"("<<x<<", "<<y<<")";
  16. }
  17. Punkt(float positionX, float positionY)
  18. {
  19. x=positionX;
  20. y=positionY;
  21. }
  22.  
  23. Punkt()
  24. {
  25. x=0;
  26. y=0;
  27. }
  28.  
  29. };
  30. float liczOdleglosc(Punkt A, Punkt B)
  31. {
  32. float AB = sqrt((A.x - B.x)*(A.x - B.x)+(A.y - B.y)*(A.y - B.y));
  33. return AB;
  34. }
  35. class Trojkat
  36. {
  37. public:
  38. Punkt A, B, C;
  39.  
  40. float liczPole()
  41. {
  42. float AB = liczOdleglosc( A, B);
  43. float d, e, f;
  44. d=(B.y-A.y)/(B.x-A.x);
  45. e=A.y-d*A.x;
  46. f=C.y-(-1/d)*C.x;
  47. Punkt P;
  48. P.x=(f-e)/(d+(1/d));
  49. P.y=(-1/d)*P.x+f;
  50. float PC = liczOdleglosc( P, C);
  51. return (AB*PC)/2;
  52. }
  53. float liczObwod()
  54. {
  55. float AB = liczOdleglosc( A, B);
  56. float CB = liczOdleglosc( C, B);
  57. float AC = liczOdleglosc( A, C);
  58. return AB+CB+AC;
  59. }
  60. void display()
  61. {
  62. cout<<"A("<<A.x<<", "<<A.y<<"), B("<<B.x<<", "<<B.y<<"), C("<<C.x<<", "<<C.y<<")";
  63. }
  64. Trojkat()
  65. {
  66. A = Punkt(0, 0);
  67. B = Punkt(1, 0);
  68. C = Punkt(0, 1);
  69. }
  70. Trojkat(Punkt a1, Punkt b1, Punkt c1)
  71. {
  72. A=a1;
  73. B=b1;
  74. C=c1;
  75. }
  76.  
  77. static int i;
  78. ~Trojkat()
  79. {
  80. cout<<"Destroying object nr"<<(i++)<<endl;
  81. }
  82. bool sprawdzenie(Punkt A, Punkt B, Punkt C, Punkt P)
  83. {
  84.  
  85. float d1, d2, d3;
  86. d1 = P.x*(A.y-B.y) + P.y*(B.x-A.x) + (A.x*B.y-A.y*B.x);
  87. d2 = P.x*(B.y-C.y) + P.y*(C.x-B.x) + (B.x*C.y-B.y*C.x);
  88. d3 = P.x*(C.y-A.y) + P.y*(A.x-C.x) + (C.x*A.y-C.y*A.x);
  89. if(d1>0 && d2>0 && d3>0 || d1==0 && d2==0 && d3==0 || d1<0 && d2<0 && d3<0)
  90. {
  91. return true;
  92. }
  93. else {return false;}
  94.  
  95. }
  96. };
  97. int Trojkat::i = 0;
  98. int main()
  99. { Punkt A, B, C, P;
  100. cout<<"Wspolrzedne punktu:"<<endl<<"Podaj P(x,y)"<<endl;
  101. cin>>P.x>>P.y;
  102. cout<<"Wspolrzedne trojkata:"<<endl<<"Podaj A(x,y)"<<endl;
  103. cin>>A.x>>A.y;
  104. cout<<"Podaj B(x,y)"<<endl;
  105. cin>>B.x>>B.y;
  106. cout<<"Podaj C(x,y)"<<endl;
  107. cin>>C.x>>C.y;
  108. Trojkat::sprawdzenie(A,B,C,P); <--- error: cannot call member function 'bool Trojkat::sprawdzenie(Punkt, Punkt, Punkt, Punkt)'
  109. without object| nie wiem co ΕΊle :<
  110. if(Trojkat::sprawdzenie(A,B,C,P)==true )
  111. {
  112. cout<<"Nalezy.";
  113. }
  114. if(Trojkat::sprawdzenie(A,B,C,P)==false)
  115. {
  116. cout<<"Nie nalezy.";
  117. }
  118.  
  119.  
  120. return 0;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement