Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Prostokat;
  6.  
  7. class Punkt {
  8. private:
  9. float x, y;
  10. string name;
  11.  
  12. public:
  13. Punkt() {
  14. x = 0;
  15. y = 0;
  16. name = "A";
  17. };
  18.  
  19. void load() {
  20. cout << "Podaj x punktu: ";
  21. cin >> x;
  22. cout << "Podaj y punktu: ";
  23. cin >> y;
  24. cout << "Podaj nazwe piunktu: ";
  25. cin >> name;
  26. }
  27.  
  28. friend void check(Punkt pkt, Prostokat p);
  29. };
  30.  
  31. class Prostokat {
  32. private:
  33. float x, y, height, width;
  34. string name;
  35.  
  36. public:
  37. Prostokat() {
  38. x = 0;
  39. y = 0;
  40. width = 1;
  41. height = 1;
  42. name = "rand";
  43. };
  44.  
  45. void load() {
  46. cout << "Podaj x: ";
  47. cin >> x;
  48. cout << "Podaj y: ";
  49. cin >> y;
  50. cout << "Podaj szerokosc: ";
  51. cin >> width;
  52. cout << "Podaj wysokosc: ";
  53. cin >> height;
  54. cout << "Podaj nazwe: ";
  55. cin >> name;
  56. }
  57.  
  58. friend void check(Punkt pkt, Prostokat p);
  59. };
  60.  
  61. void check(Punkt pkt, Prostokat p) {
  62. if ((pkt.x >= p.x) && (pkt.x <= p.x + p.width) && (pkt.y >= p.y) && (pkt.y <= p.y + p.height)) {
  63. cout << "Punkt " << pkt.name << " nalezy do prostokata: " << p.name << " ." << endl;
  64. }
  65. else {
  66. cout << "Punkt " << pkt.name << " NIE nalezy do prostokata: " << p.name << " ." << endl;
  67. }
  68. }
  69.  
  70. int main() {
  71.  
  72. int z, g;
  73. cout << "Podaj ile punktow chcesz wczytac: ";
  74. cin >> z;
  75. cout << "Podaj ile prostokatow chesz wczytac: ";
  76. cin >> g;
  77. Punkt * pkt = new Punkt[z];
  78. Prostokat * p1 = new Prostokat[g];
  79.  
  80. for (int i = 0; i < z; i++) {
  81. pkt[i].load();
  82. }
  83.  
  84. for (int i = 0; i < g; i++) {
  85. p1[i].load();
  86. }
  87.  
  88. for (int i = 0; i < g; i++) {
  89. for (int j = 0; j < z; j++) {
  90. check(pkt[j], p1[i]);
  91. }
  92. }
  93.  
  94. return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement