#include<iostream>
using namespace std;
class rectangle {
public:
double area(double l,double w);
private:
double length,width;
};
double rectangle::area(double l,double w)
{
length=l;
width=w;
return length*width;
}
int main()
{
rectangle Rectangle;
double length,width;
cin>>length>>width;
cout<<Rectangle.area(length,width)<<endl;
return 0;
}
![](https://images2018.cnblogs.com/blog/1351920/201804/1351920-20180408221209924-481368421.png)
#include<iostream>
using namespace std;
class Complex
{
public:
Complex(double r0,double i0){
real=r0;
imaginary=i0;
};
Complex(Complex &c0);
void add(Complex &C0)
void show();
private:
double real,imaginary;
};
void Complex::add(Complex &c0)
{
real+=c0.real,imaginary+=c0.imaginary;
}
void Complex::show()
{
cout<<real'+'<<imaginary<<'i'<<endl;
}
int main()
{
Complex c1(3,5);
Complex(4.5);
c1.add(c2);
c2.show();
return 0;
}
![](https://images2018.cnblogs.com/blog/1351920/201804/1351920-20180408223010520-729111367.png)