PLEASE EXPLAIN BEGINNING AT A = WHAT ARE WE DOING THIS IS C++ #include <iostream
ID: 3692167 • Letter: P
Question
PLEASE EXPLAIN BEGINNING AT A = WHAT ARE WE DOING THIS IS C++
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double m, c, r, a, b;
double A, B, C, d;
double x1, x2, y1, y2;
// get data
cout << "Enter the slope of the line: ";
cin >> m;
cout << "Enter the y-inter of line: " ;
cin >> c;
cout << "Enter the x-value of the center of circle: ";
cin >> a;
cout << "Enter the y-value of the center of circle: ";
cin >> b;
cout << "Enter the radius of circle: ";
cin >> r;
// compute intersection equations
A = pow(m,2) + 1;
B = -2*a + 2*(c-b)*m;
C = pow(a,2) + pow((c-b),2) - pow(r,2);
d = pow(B,2) - 4*A*C;
x1 = (-B - sqrt(d))/(2*A);
x2 = (-B + sqrt(d))/(2*A);
y1 = m*x1 + c;
y2 = m*x2 + c;
cout << "The intersection points are (" << x1 << "," << y1 << ") and ("
<< x2 << "," << y2 << ")." << endl;
return 0;
}
Explanation / Answer
//The process is mentioned in comments
#include<conio.h>
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double m, c, r, a, b;
double A, B, C, d;
double x1, x2, y1, y2;
// get data
// accepts the data from user
cout << "Enter the slope of the line: ";
cin >> m; //let us suppose the user entered 5
cout << "Enter the y-inter of line: " ;
cin >> c; //let us suppose the user entered 2
cout << "Enter the x-value of the center of circle: ";
cin >> a; //let us suppose the user entered 3
cout << "Enter the y-value of the center of circle: ";
cin >> b; //let us suppose the user entered 1
cout << "Enter the radius of circle: ";
cin >> r; //let us suppose the user entered 5
// compute intersection equations
// calculate pow(m,2)+1 and assigns it to A
// pow(m,2) gives m to the power of 2
A = pow(m,2) + 1; //for the given values A will be 26
// calculate -2*a + 2*(c-b)*m and assign it to B
B = -2*a + 2*(c-b)*m; // for the given values B will be 4
// calculate pow(a,2) + pow((c-b),2) - pow(r,2) and assign it to C
C = pow(a,2) + pow((c-b),2) - pow(r,2); //for the given values C will be -15
// calculate pow(B,2) - 4*A*C and assign it to d
d = pow(B,2) - 4*A*C; // for the given values d will be 1576
// calculate (-B - sqrt(d))/(2*A) and assign it to x1
//sqrt(d) gives the squareroot of d
x1 = (-B - sqrt(d))/(2*A); // for the given values x1 will be -0.840363
// calculate (-B + sqrt(d))/(2*A) and assign it to x2
x2 = (-B + sqrt(d))/(2*A); // for the given values x2 will be 0.686517
// calculate m*x1 + c and assign it to y1
y1 = m*x1 + c; // for the given values y1 will be -2.20182
// calculate m*x2 + c and assign it to y2
y2 = m*x2 + c; // for the given values y2 will be 5.43258
//Finally print the intersecting points
//The intersecting point are (x1,y1) and (x2,y2)
cout << "The intersection points are (" << x1 << "," << y1 << ") and ("<< x2 << "," << y2 << ")." << endl;
return 0;
}
Step by step calculations:
Suppose the user enters
m = 5, c = 2, a = 3 , b = 1, r= 5
Now A= pow(m,2) + 1;
Pow(m,2) returns m to the power of 2, i.e, 5 * = 25
A = pow(m,2) + 1;
Next B = -2*a + 2*(c-b)*m;
Which means B= (-2) * 3 + 2 * (2-1) * 5
Next C = pow(a,2) + pow((c-b),2) - pow(r,2)
Next d = pow(B,2) - 4*A*C;
Next x1 = (-B - sqrt(d))/(2*A);
Next x2 = (-B + sqrt(d))/(2*A);
Next y1 = m*x1 + c;
Next y2 = m*x2 + c;
Finally the intersection points are (-0.840363 , -2.20181) and (0.686517,5.43258)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.