let the code below be the point class. x and y represent the coordinates for a g
ID: 3534466 • Letter: L
Question
let the code below be the point class. x and y represent the coordinates for a given point on a cartesian coordinate plane.
class point{
private:
float x;
float y;
publics:
point() //constructor
{
x=0; y=0;
}
// another inline constructor that takes two float arguments
void showpt(){cout<<x<<','<<y;}
//get distance () getter function that returns the point's distance from the origin
};
a. fill the space above by writing another constructor that takes two float arguments
and sets the private members x and y to the two arguments passed in.
b. write the getter function getdistance() that returns teh distance object is from the origin. you will need
the sqrt() function. fill in space above.
Explanation / Answer
class point{
private:
float x;
float y;
publics:
point() //constructor
{
x=0; y=0;
}
point(float a,float b)
{
x=a;
y=b;
}
// another inline constructor that takes two float arguments
void showpt()
{
cout<<x<<','<<y;
}
//get distance () getter function that returns the point's distance from the origin
float distance()
{
flaot distance;
distance=x*x+y*y;
distance=sqrt(distance);
return distance;
}
};
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.