如何利用C++绘制一个矩形框,并且能设置线条的宽度与颜色
1个回答
展开全部
#include<iostream.h>
#include<math.h>
class Rectangle{
public:
Rectangle(double,double,double,double);
Rectangle();
double Width();
double Height();
double Girth();
double Area();
private:
double x0,y0,x1,y1;
};
Rectangle::Rectangle(double a,double b,double c,double d){
x0=a;
y0=b;
x1=c;
y1=d;
}
Rectangle::Rectangle(){
cout<<"输入矩形左下角坐标"<<endl;
cin>>x0>>y0;
cout<<"再输入矩形右上角坐标"<<endl;
cin>>x1>>y1;
}
double Rectangle::Width(){
return fabs(x1-x0);
}
double Rectangle::Height(){
return fabs(y1-y0);
}
double Rectangle::Girth(){
return (this->Width()+this->Height())*2;
}
double Rectangle::Area(){
return this->Width()*this->Height();
}
void main(){
Rectangle test(0.11,100,56,999.154);
cout<<"矩形长为:"<<test.Width()<<" "<<"宽为:"<<test.Height()<<endl
<<"矩形周长为:"<<test.Girth()<<endl
<<"矩形面积为:"<<test.Area()<<endl;
}
#include<math.h>
class Rectangle{
public:
Rectangle(double,double,double,double);
Rectangle();
double Width();
double Height();
double Girth();
double Area();
private:
double x0,y0,x1,y1;
};
Rectangle::Rectangle(double a,double b,double c,double d){
x0=a;
y0=b;
x1=c;
y1=d;
}
Rectangle::Rectangle(){
cout<<"输入矩形左下角坐标"<<endl;
cin>>x0>>y0;
cout<<"再输入矩形右上角坐标"<<endl;
cin>>x1>>y1;
}
double Rectangle::Width(){
return fabs(x1-x0);
}
double Rectangle::Height(){
return fabs(y1-y0);
}
double Rectangle::Girth(){
return (this->Width()+this->Height())*2;
}
double Rectangle::Area(){
return this->Width()*this->Height();
}
void main(){
Rectangle test(0.11,100,56,999.154);
cout<<"矩形长为:"<<test.Width()<<" "<<"宽为:"<<test.Height()<<endl
<<"矩形周长为:"<<test.Girth()<<endl
<<"矩形面积为:"<<test.Area()<<endl;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询