标题:难题啊对于这个"类"
取消只看楼主
liuguanglei
Rank: 2
等 级:论坛游民
帖 子:41
专家分:26
注 册:2012-8-15
结帖率:80%
已结贴  问题点数:10 回复次数:0 
难题啊对于这个"类"
//大家帮我看一下怎样用string来给这个矩形输出颜色(例如:输出red)
#include<iostream.h>
#include<string>
class Rectangle
{
public:
    double GetWidth();
    double GetLength();
    double GetArea();
    double GetPerimeter();
    void SetWidth(double myWidth);
    void SetLength(double myLength);
private:
    double length;
    double width;
};
double Rectangle::GetWidth()
{
    return width;
}
double Rectangle::GetLength()
{
    return length;
}
double Rectangle::GetArea()
{   
    return width*length;
}
double Rectangle::GetPerimeter()
{
    return 2*(width+length);
}
void  Rectangle::SetWidth(double myWidth)
{
   if(myWidth>0)
       width=myWidth;
}
void  Rectangle::SetLength(double myLength)
{
    if(myLength>0)
        length=myLength;
}
void main()
{
    Rectangle t1;
    double n,m;
    cout<<"please input width and length:\n";
    cin>>n;
    cin>>m;
    t1.SetWidth(n);
    t1.SetLength(m);
    t1.GetArea();
    t1.GetPerimeter();
    cout<<"width="<<t1.GetWidth()<<"\n"<<"length="<<t1.GetLength()<<"\n";
    cout<<"Area="<<t1.GetArea()<<"\n"<<"Perimeter="<<t1.GetPerimeter()<<"\n";
}
搜索更多相关主题的帖子: double void private include public 
2012-11-07 00:36



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




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

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