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

PROGRAMMING:Distance from point to origin (inheritance)

Luz5年前 (2021-05-10)题库425
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( );// Calculate the distance from the current point to the origin
}
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
2 3 4
3 1 2 2
0
Output example:
Distance from Point -1 to original point is 1
Distance from Point(3,4) to original point is 5
Distance from Point(1,2,2) to original point is 3






answer:If there is no answer, please comment