Question

programming in Microsoft visual studio. Write a C++ program for the following algorithm. Compile, run, and...

programming in Microsoft visual studio.


Write a C++ program for the following algorithm. Compile, run, and verify the result by choosing some test data.
Prompt user to write X1 value in double
Read X1
Prompt user to write X2 value in double
Read X2
Prompt user to write Y1 value in double
Read Y1
Prompt user to write Y2 value in double
Read Y2
Compute the lengths of the two sides of the right triangle generated by the two points
Compute the distance between the two points, which is equal to the length of the hypotenuse of the triangle.
Display the distance between the two points    

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:-

#include<iostream>
#include<math.h>
using namespace std;
int main(){
double X1, X2, Y1, Y2, len1, len2,distance;
cout<<"Enter value of X1"<<endl;
cin>>X1;
cout<<"Enter value of X2"<<endl;
cin>>X2;
cout<<"Enter value of Y1"<<endl;
cin>>Y1;
cout<<"Enter value of Y2"<<endl;
cin>>Y2;
if(X1>X2){ len1=X1-X2;
}
else{
len1=X2-X1;
}
if(Y2>Y1){
len2=Y2-Y1;
}
else{
len2=Y1-Y2;
}
distance=sqrt(len1*len1+len2*len2);
cout<<"The distance between the two points is "<<distance;
}

You can verify this program by giving different values to points

For eg, if X1=0, X2=3, Y1=0, Y2=4

Then the distance between points (0,0) and (3,4) is 5

Output:-

Please like the answer if it is helpful to you. If any doubt,ask in comments.

Add a comment
Know the answer?
Add Answer to:
programming in Microsoft visual studio. Write a C++ program for the following algorithm. Compile, run, and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT