Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write, a C++ program that computes the distance of a point (x,y) from the origin

ID: 3620818 • Letter: W

Question

Write, a C++ program that computes the distance of a point (x,y) from the origin. Do not use global variables.

Program should ask for the x and y coordinates of the point (each is an int) . Do this by writing a function called get_value that returns an integer (note that you will have to call this function twice one for the x coordinate and then again for the y coordinate,in order to get both coordinates of a single point) HINT: put the prompt to the user in the calling code..

Program then calls a function, compute_distance ,which again you must write, that calculates and returns the distance of the point from the origin.

Main should then print out the point in the form (x,y) and its distance from the origin.

Have your program ONLY do the calculation when x and y are both nonnegative. If the user enters a negative value for one of the coordinates, print a message stating the restriction and allow him to keep entering another value until he gets that coordinate right.
(put this restriction inside the function get_value)

Explanation / Answer

please rate - thanks #include <iostream>
#include <cmath>
using namespace std;
int get_value(char);
double compute_distance(int,int);
int main()
{int x,y;
double distance;
x=get_value('x');
y=get_value('y');
distance=compute_distance(x,y);
cout<<"point("<<x<<","<<y<<") is "<<distance<<" unit's from the origin ";
system("pause");
return 0;
}
int get_value(char c)
{int n;
cout<<"Enter a value for "<<c<<": ";
cin>>n;
while(n<0)
    {cout<<"cannot be negative ";
     cout<<"Enter a value for "<<c<<": ";
     cin>>n;
     }
return n;
}
double compute_distance(int x,int y)
{double d;
d=sqrt(x*x+y*y);
return d;
}