wenbao与类

 

 

不知道是什么鬼。。。。

 1 #include <iostream>
 2 #include <cmath>
 3 using namespace std;
 4 struct Tpoint{
 5     int x, y, z;
 6     void init(int a, int b, int c){//初始化(赋值)
 7         x = a, y = b, z = c;
 8     }
 9     Tpoint operator + (const Tpoint &m){//重载+
10         Tpoint T;
11         T.x = m.x + x, T.y = m.y + y, T.z = m.z + z;
12         return T;
13     }
14     Tpoint operator - (const Tpoint &m){//重载-
15         Tpoint T;
16         T.x = x - m.x, T.y = y - m.y, T.z = z - m.z;
17         return T;
18     }
19     double dist(Tpoint n){//计算距离
20         return sqrt(pow((double)(x-n.x), 2) + pow((double)(y-n.y), 2) + pow((double)(z-n.z), 2));
21     }
22     void read(){//读取
23         printf("x = %d, y = %d, z = %d\n", x, y, z);
24     }
25 };
26 int main(){
27     Tpoint T, N, M;
28     T.init(1, 2, 3);
29     T.read();
30     N.init(2, 3, 4);
31     N.read();
32     M = T + N;
33     M.read();
34     M = T - N;
35     M.read();
36     printf("%lf\n", T.dist(N));
37     return 0;
38 }

 

 

 

 

 

 

 

 

只有不断学习才能进步!

 

posted @ 2018-04-14 13:49  wenbao  阅读(81)  评论(0编辑  收藏  举报