帮忙分析一下这个程序的每一步,我是初学者,因为刚转专业,没学过c++,谢谢了。
#include <iostream>using namespace std;
class rectangle{
public:
rectangle(int len=10,int wid=10);
rectangle(const rectangle &p);
~rectangle();
void disp()
{cout<<length<<" "<<width<<endl;}
void showarea();
void setlengthandwidth();
private:
int length,width;
};
rectangle::rectangle(int len, int wid)
{ length=len;
width=wid;
cout<<"Using normal constructor\n";
}
rectangle::rectangle(const rectangle &p)
{ length=2*p.length;
width=2*p.width;
cout<<"Using copy constructor\n";
}
rectangle::~rectangle()
{cout<<"destructing..."<<endl;
}
void rectangle::showarea()
{cout<<"该矩形的面积为:"<< length*width<<endl;}
void rectangle::setlengthandwidth()
{cout<<"该矩形的周长为:"<<(length+width)*2<<endl;}
int main()
{rectangle rec1(5,5);
cout<<"rectangle1 output1:"<<endl;
rec1.showarea();
rec1.setlengthandwidth();
return 0;
}