Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4.  
  5. struct Circle {
  6. double x,y,r;
  7. };
  8.  
  9. Circle read_circle(double x, double y, double r) {
  10. return Circle{x,y,r};
  11. }
  12.  
  13. bool overlapped(Circle C1, Circle C2) {
  14. double dist = sqrt(pow(C1.x - C2.x, 2) + pow(C1.y - C2.y, 2));
  15. return (dist < (C1.r + C2.r));
  16. }
  17.  
  18. int main() {
  19. int x,y,r,itr;
  20. std::cout << "Input the x-coordinate of circle 1" << std::endl << "x= ";
  21. std::cin >> x;
  22. std::cout << "Input the y-coordinate of circle 1" << std::endl << "y= ";
  23. std::cin >> y;
  24. std::cout << "Input the radius of circle 1" << std::endl << "r= ";
  25. std::cin >> r;
  26.  
  27. Circle circle1 = read_circle(x,y,r);
  28.  
  29. itr = 2;
  30.  
  31. std::vector<Circle> circle_list;
  32.  
  33. while(1)
  34. {
  35. std::cout << "Input the x-coordinate of circle " << itr << std::endl << "x= ";
  36. std::cin >> x;
  37. std::cout << "Input the y-coordinate of circle " << itr << std::endl << "y= ";
  38. std::cin >> y;
  39. std::cout << "Input the radius of circle " << itr << std::endl << "r= ";
  40. std::cin >> r;
  41.  
  42. if (r < 0)
  43. break;
  44.  
  45. circle_list.push_back(read_circle(x,y,r));
  46.  
  47. // std::cout << "overlapped" << std::endl << std::endl;
  48.  
  49. if (overlapped(circle1,circle_list[itr - 2]))
  50. std::cout << "overlapped" << std::endl << std::endl;
  51. else
  52. std::cout << "not overlapped" << std::endl << std::endl;
  53.  
  54. itr++;
  55. }
  56.  
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement