Advertisement
szmelu

zaj3

Nov 8th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. //plik.h
  2. #include <iostream>
  3. #include <ctime>
  4. #include <cmath>
  5. using namespace std;
  6. #pragma once
  7. struct Punkt {
  8. int x;
  9. int y;
  10. Punkt(int, int);
  11. Punkt(int, int, int);
  12. };
  13. class Odcinek {
  14. Punkt *poczatek;
  15. Punkt *koniec;
  16. public:
  17. double dlugoscodcinka();
  18. Odcinek(int, int, int, int, int);
  19. };
  20. class Okrag {
  21. friend int przeciecie(Okrag, Okrag);
  22. friend double Odcinek::dlugoscodcinka();
  23. friend void wypisz(Okrag, Okrag);
  24. static int licznik;
  25. Punkt *srodek;
  26. int promien;
  27. public:
  28. Okrag(int, int, int);
  29. Okrag(int, int, int, int);
  30. Okrag();
  31. static int getLicznik();
  32. ~Okrag();
  33. };
  34. //klasy.cpp
  35. #include <iostream>
  36. #include <ctime>
  37. #include <cmath>
  38. #include "plik.h"
  39. using namespace std;
  40. int Okrag::licznik = 0;
  41. Punkt::Punkt(int s, int e)
  42. {
  43. int zakres = e - s;
  44. x = rand() % zakres + s;
  45. y = rand() % zakres + s;
  46. }
  47. Punkt::Punkt(int a, int b, int c)
  48. {
  49. x = a;
  50. y = b;
  51. }
  52. Odcinek::Odcinek(int s, int e, int s1, int e1, int c)
  53. {
  54. poczatek = new Punkt(s, e, c);
  55. koniec = new Punkt(s1, e1, c);
  56. }
  57.  
  58. double Odcinek::dlugoscodcinka()
  59. {
  60. return sqrt(pow((koniec->x - poczatek->x), 2) + pow((koniec->y - poczatek->y), 2));
  61.  
  62. }
  63. Okrag::Okrag(int a, int b, int prom)
  64. {
  65. ++licznik;
  66. srodek = new Punkt(a, b, promien);
  67. promien = prom;
  68. }
  69. Okrag::Okrag(int s, int e, int s1, int e1)
  70. {
  71. ++licznik;
  72. srodek = new Punkt(s, e);
  73. int zakres = e1 - s1;
  74. promien = rand() % zakres + s1;
  75. }
  76. int Okrag::getLicznik()
  77. {
  78. return licznik;
  79. }
  80. Okrag::~Okrag()
  81. {
  82. --licznik;
  83. }
  84. //main.cpp
  85. #include <iostream>
  86. #include <ctime>
  87. #include <cmath>
  88. #include "plik.h"
  89. using namespace std;
  90. int icos = 0;
  91. void wypisz(Okrag A, Okrag B)
  92. {
  93. //if (przeciecie(A, B) == 1)
  94. //cout << "(" << A.srodek->x << ", " << A.srodek->y << ", " << A.promien << ") i (" << B.srodek->x << ", " << B.srodek->y << ", " << B.promien << ") - rozlaczne zewnetrznie" << endl;
  95. //if (przeciecie(A, B) == 2)
  96. //cout << "(" << A.srodek->x << ", " << A.srodek->y << ", " << A.promien << ") i (" << B.srodek->x << ", " << B.srodek->y << ", " << B.promien << ") - styczne zewnetrznie" << endl;
  97. if (przeciecie(A, B) == 3)
  98. {
  99. icos++;
  100. cout << "(" << A.srodek->x << ", " << A.srodek->y << ", " << A.promien << ") i (" << B.srodek->x << ", " << B.srodek->y << ", " << B.promien << ") - przecinajace sie" << endl;
  101. }
  102. //if (przeciecie(A, B) == 4)
  103. //cout << "(" << A.srodek->x << ", " << A.srodek->y << ", " << A.promien << ") i (" << B.srodek->x << ", " << B.srodek->y << ", " << B.promien << ") - styczne wewnetrznie" << endl;
  104. //if (przeciecie(A, B) == 5)
  105. //cout << "(" << A.srodek->x << ", " << A.srodek->y << ", " << A.promien << ") i (" << B.srodek->x << ", " << B.srodek->y << ", " << B.promien << ") - rozlaczne wewnetrznie" << endl;
  106. //if (przeciecie(A, B) == 6)
  107. //cout << "(" << A.srodek->x << ", " << A.srodek->y << ", " << A.promien << ") i (" << B.srodek->x << ", " << B.srodek->y << ", " << B.promien << ") - wspolsrodkowe" << endl;
  108. else if (icos == 0)
  109. cout << "Nie ma okregow przecinajacych sie" << endl;
  110. }
  111. int przeciecie(Okrag A, Okrag B)
  112. {
  113. Odcinek odc(A.srodek->x, A.srodek->y, B.srodek->x, B.srodek->y, 0);
  114. if ((odc.dlugoscodcinka() < (A.promien + B.promien)) && (odc.dlugoscodcinka()>abs(A.promien - B.promien)))
  115. return 3;
  116. else if (odc.dlugoscodcinka() > (A.promien + B.promien))
  117. return 1;
  118. else if (odc.dlugoscodcinka() == (A.promien + B.promien))
  119. return 2;
  120. else if (odc.dlugoscodcinka() == abs(A.promien - B.promien))
  121. return 4;
  122. else if (odc.dlugoscodcinka() < abs(A.promien - B.promien))
  123. return 5;
  124. else
  125. return 6;
  126.  
  127. }
  128. int main()
  129. {
  130. srand(time(NULL));
  131. cout << "licznik: " << Okrag::getLicznik() << endl;
  132. Okrag A(0,0,5);
  133. Okrag B(3,4,5);
  134. wypisz(A, B);
  135. Okrag** sto1 = new Okrag*[100];
  136. Okrag** sto2 = new Okrag*[100];
  137. for (int i = 0; i < 100; i++)
  138. sto1[i] = new Okrag(-10, 10, 1, 20);
  139. for (int i = 0; i < 100; i++)
  140. sto2[i] = new Okrag(-10, 10, 1, 20);
  141. for (int i = 0; i < 100; i++)
  142. wypisz(*sto1[i], *sto2[i]);
  143. for (int i = 0; i < 100; i++)
  144. {
  145. delete sto1[i];
  146. delete sto2[i];
  147. }
  148. delete[] sto1;
  149. delete[] sto2;
  150.  
  151. cout << "licznik: " << Okrag::getLicznik() << endl;
  152. system("pause");
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement