a) Two points in a plane are specified using the coordinates(x1,y1) and (x2,y2).
ID: 3613367 • Letter: A
Question
a) Two points in a plane are specified using the coordinates(x1,y1) and (x2,y2). Write a program that calculates the slope of aline through two (non-vertical) points entered by the user. b) Write a program that accepts two points (see previousproblem) and determines the distance between them. a) Two points in a plane are specified using the coordinates(x1,y1) and (x2,y2). Write a program that calculates the slope of a line through two (non-vertical) points entered by the user. Slope=y2-y1/x2-x1 b) Write a program that accepts two points (see previousproblem) and determines the distance between them. Distance= root (x2-x1)^2+(y2-y1)^2Explanation / Answer
int main()
{
double x1,y1,x2,y2,s=0,d;
cout<<"Enter x1,y1:";
cin>>x1>>y1;
cout<<"Enter x2,y2:";
cin>>x2>>y2;
if(x2!=x1)
s = (y2-y1)/(x2-x1);
d = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
cout<<"Slope is :"<<s<<endl;
cout<<"Distance is :"<<d<<endl;
system("pause");
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.