实验三

#include<iostream>
using namespace std;
class retangle{
	public:
		retangle(double x,double y); 
		double area();
		private:
			double length,width;
};
retangle::retangle(double x, double y)
{
	length=x;
	width=y;
}
double retangle::area()
{
	return length*width;
}
int main()
{
	double length,width;
	cout<<"Please enter the length and the ";
	cin>>length>>width;
	retangle c(length,width);
	cout << c.area()<<endl;
	return 0;
}

#include<iostream>
using namespace std;
class complex{
    public:
      complex(double r,double i);
      void add(complex c2);
      void show();
    private:
      double real,imaginary;
         
};
complex::complex(double r,double i)
{
    real= r;
    imaginary=i;
}
void complex::add(complex c2){
    real+=c2.real;
    imaginary+=c2.imaginary;
}
void complex::show(){
    cout<<real<<"+"<<imaginary<<"i"<<endl;
}
int main()
{
    complex c1(3.0,5.0);
    complex c2(4.5,0);
    c1.add(c2);
    c1.show();
    return 0;
}

原文地址:https://www.cnblogs.com/Nicholastwo/p/8732778.html