1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
*
*File: circles_solutions.cpp
*Created by: Robert Marsch
*Created on: 2/3/2014
*Synopsis: To input the coordinates of a circle and radii of three circles and *report the location of the query point relative to the circles.
*/
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
int main()
{
int xa, xb, xc, xq, xy, ya, yb, yc, yq, ra, rb, rc;
int distancex1, distancey1, distancex2, distancey2, distancex3, distancey3;
int d1, d2, d3;
int k;
cout << "Enter x and y coordinates of circle A (2 values): ";
cin >> xa >> xb;
cout<< "Enter radius of circle A: ";
cin >> ra;
cout << "Enter x and y coordinates of circle B (2 values): ";
cin >> xb>> yb;
cout << "Enter radius of circle B: ";
cin >> rb;
cout << "Enter x and y coordinates of circle C (2 values): ";
cin >> xc >> yc;
cout << "Enter radius of circle C: ";
cin >> rc;
cout << "Enter x and y coordinate of query point (2 values): ";
cin >> xq >> yq;
distancex1 = (xq - xa);
distancey1 = (yq - ya);
distancex2 = (xq - xb);
distancey2 = (yq - yb);
distancex3 = (xq - xc);
distancey3 = (yq - yc);
d1 = sqrt(pow(distancex1,2)+pow(distancey1,2));
d2 = sqrt(pow(distancex2,2)+pow(distancey2,2));
d3 = sqrt(pow(distancex3,2)+pow(distancey3,2));
while (int k=1)
if((d1 <= ra) && (d2 <= rb) && (d3 <= rc))
{
cerr << "Circles A B and C contain point (" << xq << " ," << yq << "). " << endl;
exit(10);
}
else if ((d1 <= ra) && (d3 <= rc) && (d2 >= rb))
{
cerr << "Circles A and C contain point (" << xq << " ," << yq << "). " << endl;
exit(20);
}
else if((d3 >= rc) && (d1 <= ra) && (d2 <= rb))
{
cerr << "Circles A and B contain point (" << xq << " ," << yq << "). " << endl;
exit(30);
}
else if((d2 <= rb) && (d3 <= rc) && (d1 >= ra))
{
cerr << "Circles B and C contain point (" << xq << " ," << yq << "). " << endl;
exit(40);
}
else if((d2 >= rb) && (d3 >= rc) && (d1 <= ra))
{
cerr << "Circle A contains point (" << xq << " ," << yq << "). " << endl;
exit(50);
}
else if((d1 >= ra) && (d3 >= rc) && (d2 <= rb))
{
cerr << "Circle B contains point (" << xq << " ," << yq << "). " << endl;
exit(60);
}
else if((d1 >= ra) && (d3 >= rc) && (d2 <= rb))
{
cerr << "Circle C contains point (" << xq << " ," << yq << "). " << endl;
exit(70);
}
else if((d1 > ra) && (d2 > rb) && (d3 > rc))
{
cerr << "No circle contains point (" << xq << " ," << yq << "). " << endl;
exit(80);
}
return 0;
}
|