#include<iostream>
#include<iomanip>
using namespace std;
class area
{
	private:
		int w,l;//定义宽度,长度
    public:
	void setdate(float a=0,float b=0);
    void showarea(); 
};
void area::setdate(float a,float b)//输入宽度,长度 
{
	w=a;
	l=b;
}
inline void area::showarea()//输出面积 
{
	cout<<setfill(' ')<<setw(4)<<(float)w*l<<endl;
}
int main()
{
	area a1;
	cout<<"set and output"<<endl;
	a1.setdate(66,6.2);
	a1.showarea();
	return 0;
}

  

#include<iostream>
using namespace std;
class Complex
{
	public:
		Complex(float x0,float y0);
		Complex(float x0);
		void add(Complex &c);
		void show();
	private:
	float x;
	float y;	 
};
Complex::Complex(float x0,float y0)
{
	x=x0;
	y=y0;
}
Complex::Complex(float x0)
{
	x=x0;
} 
void Complex::add(Complex &c)
{
	x+=c.x;
	y+=c.y;
}
void Complex::show()
{
	cout<<x<<"+"<<y<<"i";
}
int main()
{
	Complex c1(3,5);
	Complex c2=4.5;
	c1.add(c2);
	c1.show();
	return 0; 
}

  

实验4-11中,我定义的是float型变量,但不论我怎么输入,输出的都是整型,我不知道哪里出错了,希望有大神能帮我解决。

实验4-20中有很多我还不怎么理解,只是照葫芦画瓢,其中第一个complex(float,float)如果赋了初值,则int main中出现错误,也希望大神能够解答。