Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- struct Circle {
- double x,y,r;
- };
- Circle read_circle(double x, double y, double r) {
- return Circle{x,y,r};
- }
- bool overlapped(Circle C1, Circle C2) {
- double dist = sqrt(pow(C1.x - C2.x, 2) + pow(C1.y - C2.y, 2));
- return (dist < (C1.r + C2.r));
- }
- int main() {
- int x,y,r,itr;
- std::cout << "Input the x-coordinate of circle 1" << std::endl << "x= ";
- std::cin >> x;
- std::cout << "Input the y-coordinate of circle 1" << std::endl << "y= ";
- std::cin >> y;
- std::cout << "Input the radius of circle 1" << std::endl << "r= ";
- std::cin >> r;
- Circle circle1 = read_circle(x,y,r);
- itr = 2;
- std::vector<Circle> circle_list;
- while(1)
- {
- std::cout << "Input the x-coordinate of circle " << itr << std::endl << "x= ";
- std::cin >> x;
- std::cout << "Input the y-coordinate of circle " << itr << std::endl << "y= ";
- std::cin >> y;
- std::cout << "Input the radius of circle " << itr << std::endl << "r= ";
- std::cin >> r;
- if (r < 0)
- break;
- circle_list.push_back(read_circle(x,y,r));
- // std::cout << "overlapped" << std::endl << std::endl;
- if (overlapped(circle1,circle_list[itr - 2]))
- std::cout << "overlapped" << std::endl << std::endl;
- else
- std::cout << "not overlapped" << std::endl << std::endl;
- itr++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement