算长方形的面积和周长,错哪里了?请大神之处并修改。
#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;
}
rectangle::showarea()
{cout<<"该矩形的面积为:"<< length*width<<endl;}
rectangle::setlengthandwidth()
{cout<<"该矩形的周长为:"<<(length+width)*2<<endl;}
int main()
{rectangle rec1(5,5);
cout<<"rectangle1 output1:"<<endl;
rec1.showarea();
rec1.setlengthandwidth();
return 0;
}