-->
当前位置:首页 > 题库

PROGRAMMING:Calculation of distance between two points

Luz5年前 (2021-05-10)题库497
A basic class framework is given
class Point_ 1D
{ protected:
float x;// The X coordinate of 1D point
public:
Point_ 1D(float p = 0.0);
float distance(const Point_ 1D & p2);
}
Point_ 1D creates a derived class for the base class_ 2D, add a protection data member:
float y;// The Y coordinate of a point on the 2D plane
Point_ 2D creates a derived class for the direct base class_ 3D, add a data protection member:
float z;// Z-coordinate of point in 3D solid space
Generate the above class and write the main function, according to the basic information of the input point, establish the point object, and calculate the distance from the point to the origin.
Input format: the test input contains several test cases, and each test case occupies one line (the type of point (1 represents 1D point, 2 represents 2D point, 3 represents 3D point), the first point coordinate information (related to the type of point) and the second point coordinate information (related to the type of point)). When 0 is read in, the input ends and the corresponding result is not output.
Input example:
1 -1 0
2 3 4 0 0
3 1 2 2 0 0 0
0
Output example:
Distance from Point -1 to Point 0 is 1
Distance from Point(3,4) to Point(0,0) is 5
Distance from Point(3,3,3) to Point(0,0,0) is 3






answer:If there is no answer, please comment