#include<iostream>
using namespace std;
class Rectangle
{
private:
int left_x,left_y;
int right_x,right_y;
public:
Rectangle(int x_1,int y_1,int x_2,int y_2);
int Rectangle_S();
void output();
void outputCenter();
};
Rectangle::Rectangle(int x_1,int y_1,int x_2,int y_2):left_x(x_1),left_y(y_1),right_x(x_2),right_y(y_2)
{
}
int Rectangle::Rectangle_S()
{
return (right_y-left_y)*(right_x-left_x);
}
void Rectangle::output()
{
cout<<"left_x="<<left_x<<endl;
cout<<"left_y="<<left_y<<endl;
cout<<"right_x="<<right_x<<endl;
cout<<"right_y="<<right_y<<endl;
}
void Rectangle::outputCenter()
{
cout<<"center=("<<(left_x+right_x)/2<<','<<(left_y+right_y)/2<<')'<<endl;
}
int main()
{
Rectangle rec(10,10,20,20);
cout<<"S="<<rec.Rectangle_S()<<endl;
rec.output();
rec.outputCenter();
return 0;
}
矩形类
最新推荐文章于 2023-11-17 16:26:23 发布