Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. #include<iostream>
  2. # include <cmath>
  3. using namespace std;
  4. class Punkt
  5. {
  6. double x;
  7. double y;
  8. public:
  9. Punkt (double xx, double yy);
  10. Punkt();
  11. Punkt (Punkt & p);
  12. double zwroc_x();
  13. double zwroc_y();
  14. void ustaw_x(double xx);
  15. void ustaw_y(double yy);
  16. double odleglosc_od_punktu(Punkt & p);
  17. double odleglosc_od_0();
  18. void przesun_o_wektor(double xxx,double yyy);
  19. int lezy_w_cwiartce();
  20. bool jest_symetryczny_wzgl_0(Punkt &p);
  21. void wyswietl();
  22. double pobierz();
  23. };
  24. Punkt::Punkt (double xx, double yy)
  25. {
  26. x=xx;
  27. y=yy;
  28. }
  29. Punkt::Punkt()
  30. {
  31. x=0;
  32. y=0;
  33. }
  34. Punkt::Punkt (Punkt & p)
  35. {
  36. x=p.x;
  37. y=p.y;
  38. }
  39. double Punkt::zwroc_x()
  40. {
  41. return x;
  42. }
  43. double Punkt::zwroc_y()
  44. {
  45. return y;
  46. }
  47. void Punkt::ustaw_x(double xx)
  48. {
  49. x=xx;
  50. }
  51. void Punkt::ustaw_y(double yy)
  52. {
  53. y=yy;
  54. }
  55. double Punkt:: odleglosc_od_punktu(Punkt &p)
  56. {
  57. return sqrt((p.x-x)*(p.x-x)+(p.y-y)*(p.y-y));
  58. }
  59. double Punkt::odleglosc_od_0()
  60. {
  61. return sqrt(x*x+y*y);
  62. }
  63. void Punkt::przesun_o_wektor(double xxx,double yyy)
  64. {
  65. x+=xxx;
  66. y+=yyy;
  67. }
  68. int Punkt::lezy_w_cwiartce()
  69. {
  70. if(x>0 and y>0)
  71. {
  72. return 1;
  73. }
  74. else if (x<0 and y>0)
  75. {
  76. return 2;
  77. }
  78. else if (x<0 and y<0)
  79. {
  80. return 3;
  81. }
  82. else if(x==0 or y==0)
  83. {
  84. return 0;
  85. }
  86. else
  87. {
  88. return 4;
  89. }
  90.  
  91. }
  92. bool Punkt::jest_symetryczny_wzgl_0(Punkt &p)
  93. {
  94. if (x==-1*p.x and y==-1*p.y)
  95. {
  96. return true;
  97. }
  98. else
  99. {
  100. return false;
  101. }
  102. }
  103. void Punkt::wyswietl()
  104. {
  105. cout<<"("<<x<<","<<y<<")"<<endl;
  106. }
  107.  
  108. double Punkt::pobierz()
  109. {
  110. cout << "Podaj x:"<<endl;
  111. cin >> x;
  112. cout << "Podaj y:"<<endl;
  113. cin >> y;
  114. return x,y;
  115. }
  116.  
  117. int main()
  118. {
  119. Punkt x1(-1,1);
  120. Punkt x2(11,6);
  121. Punkt x3 (-11,-6);
  122. Punkt x4;
  123. Punkt x5 (-1,2);
  124. cout << x1.odleglosc_od_punktu(x2) << endl;
  125. cout << x5.odleglosc_od_0() << endl;
  126. x1.przesun_o_wektor(4,6);
  127. cout << x1.zwroc_x() << " " << x1.zwroc_y() << endl;
  128. cout << x2.lezy_w_cwiartce() << endl;
  129. cout << x2.jest_symetryczny_wzgl_0(x3) << endl;
  130. x2.wyswietl();
  131. x4.wyswietl();
  132. x4.pobierz();
  133. x4.wyswietl();
  134.  
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement