类的简单运算
1 #include <iostream> 2 using namespace std; 3 4 class rectangle 5 { 6 private: 7 int length,width; 8 public: 9 rectangle(){}; 10 rectangle(int a,int b); 11 rectangle tlength(rectangle A,rectangle B); 12 void display(rectangle C); 13 }; 14 rectangle::rectangle(int a,int b) 15 { 16 length=a;width=b; 17 } 18 rectangle rectangle::tlength(rectangle A,rectangle B) 19 { 20 A.length= A.length + B.length; 21 A.width=A.width+B.width; 22 return A; 23 } 24 void rectangle::display(rectangle C) 25 { 26 cout<<(C.length+C.width)*2; 27 } 28 void main() 29 { 30 rectangle A(1,2),B(3,4),C; 31 C=C.tlength(A,B); 32 C.display(C); 33 }