码迷,mamicode.com
首页 > 其他好文 > 详细

类的简单运算

时间:2014-11-05 16:41:21      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   os   sp   div   log   bs   

 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 }

 

类的简单运算

标签:style   blog   io   color   os   sp   div   log   bs   

原文地址:http://www.cnblogs.com/yll-sww/p/4076597.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!