标题:算长方形的面积和周长,错哪里了?请大神之处并修改。
取消只看楼主
_Strike
Rank: 2
等 级:论坛游民
帖 子:133
专家分:72
注 册:2016-3-22
结帖率:90.63%
已结贴  问题点数:15 回复次数:1 
算长方形的面积和周长,错哪里了?请大神之处并修改。
#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;
}
搜索更多相关主题的帖子: private include public normal 长方形 
2016-04-19 17:32
_Strike
Rank: 2
等 级:论坛游民
帖 子:133
专家分:72
注 册:2016-3-22
得分:0 
好的 谢谢啦
2016-04-19 22:20



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-463842-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.995843 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved