Advertisement
Guest User

Untitled

a guest
May 20th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <time.h>
  4. #include <math.h>
  5.  
  6. using namespace std;
  7.  
  8. class punkt
  9. {
  10. public:
  11. punkt();
  12. punkt(int a,int b);
  13. int getx();
  14. void setx(int x);
  15. int gety();
  16. void sety(int y);
  17. void operator~(); //wypisz
  18.  
  19. protected:
  20. int x;
  21. int y;
  22. };
  23.  
  24. punkt::punkt()
  25. {
  26. x=0;
  27. y=0;
  28. }
  29.  
  30. punkt::punkt(int a,int b)
  31. {
  32. x=a;
  33. y=b;
  34. }
  35.  
  36. int punkt::getx()
  37. {
  38. return x;
  39. }
  40.  
  41. int punkt::gety()
  42. {
  43. return y;
  44. }
  45.  
  46. void punkt::setx(int a)
  47. {
  48. x=a;
  49. }
  50.  
  51. void punkt::sety(int a)
  52. {
  53. y=a;
  54. }
  55.  
  56. void punkt::operator~()
  57. {
  58. cout<<"Punkt: ("<<x<<","<<y<<")"<<endl;
  59. }
  60.  
  61. class pixel:public punkt
  62. {
  63. public:
  64. pixel(int x,int y,int c);
  65. int getk();
  66. void setk(int c);
  67. void operator~();
  68. float oblicz(pixel &p);
  69.  
  70. protected:
  71. int kolor;
  72. };
  73.  
  74. pixel::pixel(int x,int y,int c) : punkt(x,y)
  75. {
  76. kolor=c;
  77. }
  78.  
  79. int pixel::getk()
  80. {
  81. return kolor;
  82. }
  83.  
  84. void pixel::setk(int c)
  85. {
  86. kolor=c;
  87. }
  88.  
  89. void pixel::operator~()
  90. {
  91. cout<<"X= "<<x<<" Y= "<<y<<" Kolor: "<<kolor<<endl;
  92. }
  93.  
  94. float pixel::oblicz(pixel &p)
  95. {
  96. return sqrt(pow((x-p.x),2)+pow((y-p.y),2));
  97. }
  98.  
  99. int main(){
  100. punkt P1(1,2);
  101. ~P1;
  102. pixel P11(6,5,5);
  103. pixel P12(7,13,2);
  104. ~P11;
  105. ~P12;
  106. cout<<"Odleglosc miedzy punktami: "<<P11.oblicz(P12)<<endl;
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement