难题啊对于这个"类"
//大家帮我看一下怎样用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";
}