#include<iostream>
#include<cstdlib>
class Screen
{
private:
int width;
int height;
public:
int setWidth(int width_);
int setHeight(int height_);
int getWidth();
int getHeight();
Screen(int width_,int height_);
Screen();
void exitWhenInvalidScreen(int width_, int height_);//检测屏幕的宽与高是否 符合逻辑
};
int Screen::getWidth()
{
return width;
}
int Screen::getHeight()
{
return height;
}
int Screen::setHeight(int height_)
{
height=height_;
}
int Screen::setWidth(int width_)
{
width=width_;
}
Screen::Screen()
{
std::cout<<"screen"<<std::endl;
width=640;
height=480;
}
Screen::Screen(int width_,int height_)
{
exitWhenInvalidScreen(width_,height_);
std::cout<<"screen"<<std::endl;
width=width_;
height=height_;
}
void Screen::exitWhenInvalidScreen(int width_,int height_)
{
if(width_<=0||width_>1000||height_<=0||height_>1000)
{
std::cout<<"invalib screen size";
exit(0);
}
}
class MyRectangle
{
private:
Screen* screen;
int x1;
int y1;
int x2;
int y2;
public:
MyRectangle(int x1_,int y1_,int x2_,int y2_,Screen* screen_);
MyRectangle();
void setCoordinations(int x1_, int y1_, int x2_, int y2_);
void setScreen(Screen &screen_); //用于设置该类的实例所对应的Screen对象
void Draw();
};
MyRectangle::MyRectangle()
{
std::cout << "myrectangle" << std::endl;
x1=0;
y1=0;
x2=0;
y2=0;
}
MyRectangle::MyRectangle(int x1_,int y1_,int x2_,int y2_,Screen* screen_)
{
std::cout << "myrectangle" << std::endl;
x1=x1_;
y1=y1_;
x2=x2_;
y2=y2_;
screen=screen_;
}
void MyRectangle::setCoordinations(int x1_,int y1_,int x2_,int y2_)
{
x1=x1_;
y1=y1_;
x2=x1_;
y2=y2_;
}
void MyRectangle::setScreen(Screen &screen_)
{
screen=&screen_;
}
void MyRectangle::Draw()
{
if(x1<=0||x1>=x2||x2>=screen->getWidth())
{
std::cout << "invalid myrectangle" << std::endl;
return;
}
if(y1<=0||y1>=y2||y2>=screen->getHeight())
{
std::cout << "invalid myrectangle" << std::endl;
return;
}
std::cout << x1 << " " << y1<< " " << x2 - x1 << " " << y2 - y1<< std::endl;
}
int main() {
int width, height;
std::cin >> width >> height;
Screen screen (width, height);
int leftX, leftY, rightX, rightY;
std::cin >> leftX >> leftY >> rightX >> rightY;
MyRectangle myRectangle1 (leftX, leftY, rightX, rightY, &screen);
MyRectangle* myRectangles = new MyRectangle[2];
myRectangles[1].setCoordinations(10, 300, 700, 500);
myRectangles[1].setScreen(screen);
myRectangle1.Draw();
for (int i = 0; i < 2; i++) {
myRectangles[i].setScreen(screen);
(myRectangles+i) -> Draw();
}
delete [] myRectangles;
return 0;
}