标签:形参 real http 构造函数 ble image 函数 img div
四、实验结论
1 #include<iostream> 2 using namespace std; 3 class Rectangle 4 { 5 public: 6 Rectangle(float len,float wid) 7 {length=len; 8 width=wid; 9 10 } 11 float getarea() 12 { 13 return length*width; 14 15 } 16 Rectangle(Rectangle &r) 17 {}//没搞懂哪个地方能用到复制构造函数。。求大神解解惑O(∩_∩)O ,灰常感谢! 18 ~ Rectangle() {} 19 private: 20 float length; 21 float width; 22 }; 23 int main() 24 { float x,y; 25 cout<<"输入长和宽"<<endl; 26 cin>>x >>y; 27 Rectangle rec(x,y); 28 cout<<"矩形面积:"<<rec.getarea()<<endl; 29 return 0; 30 }
1 #include<iostream> 2 using namespace std; 3 class Complex 4 { 5 public: 6 Complex(double r0,double i0) 7 { 8 real=r0,imaginary=i0; 9 }; 10 Complex(double r0) 11 { 12 real=r0; 13 }; 14 Complex(Complex &c0); 15 void add(Complex &c0); 16 void show(); 17 private: 18 double real,imaginary; 19 }; 20 21 void Complex::add(Complex &c0) 22 { 23 real+=c0.real,imaginary+=c0.imaginary; 24 } 25 void Complex::show() 26 { 27 cout<<real<<(imaginary>0 ? ‘+‘:‘-‘)<<imaginary<<‘i‘<<endl; 28 } 29 int main() 30 { 31 Complex c1(3,5); 32 Complex c2(4.5); 33 c1.add(c2); 34 c1.show(); 35 return 0; 36 }
五、实验总结与体会
对于类的掌握还是不太好,尤其是对于复制构造函数的使用,感觉4-11这道题目用不到复制构造函数。(最重要的是,我也不知道怎么在代码里面把复制构造函数那个再加上去,求大神指点!)
对于UML类图,我感觉一张小图片上把实参名 形参名都给规定的好了,感觉变相的把大家的代码也给弄相似了。
标签:形参 real http 构造函数 ble image 函数 img div
原文地址:https://www.cnblogs.com/wuyijie/p/8745940.html