实验三

 

1
#include<iostream> 2 using namespace std; 3 class rect{ 4 public: 5 rect(float L,float W){ 6 length=L; 7 wide=W; 8 } 9 area_print(){ 10 cout<<length*wide; 11 } 12 private: 13 float length,wide; 14 }; 15 16 int main(){ 17 float length,wide; 18 cin>>length>>wide; 19 rect a(length,wide); 20 a.area_print(); 21 return 0; 22 23 }
 1 #include<iostream>
 2 using namespace std;
 3 class Complex {
 4     public:
 5         Complex(float at,float bt) {
 6             a=at;
 7             b=bt;
 8         }
 9         Complex(float at) {
10             a=at;
11         }
12         void add(Complex &p) {
13             a=a+p.a;
14             b=b+p.b;
15         }
16         void show() {
17             cout<<a<<"+"<<b<<"i";
18         }
19     private:
20         float a,b;
21 };
22 int main(){    
23     Complex c1(3,5);
24     Complex c2=4.5;
25     c1.add(c2);
26     c1.show();
27     return 0;
28 }

posted @ 2018-04-08 12:04  YYWZS  阅读(137)  评论(3编辑  收藏  举报