题目具体是这样的,我写的代码是这样的,然后我设置了一个Point类,一个Rectangle类就是不知道出了什么问题,想要设置两个点,不知道该怎么求面积,大一新生,想求解此题。
include
using namespace std;
class Point
{
public:
void setx(int x) {
m_x = x;
}
int getx()
{
return m_x;
}
void sety(int y)
{
m_y = y;
}
int gety()
{
return m_y;
}
private:
int m_x;
int m_y;
};
class Rectangle {
public:
void setbottomleft(Point bottomleft) { m_bottomleft = bottomleft;
}
Point getbottomleft()
{
return m_bottomleft;
}
void settopright(Point topright)
{
m_topright = topright;
}
Point gettopright()
{
return m_topright;
}
private:
Point m_bottomleft;
Point m_topright;
};
void area(Point& b, Point& t) {
int S= (b.getx() - t.getx()) * (b.gety() - t.gety());
}
int main() {
Point bottomleft;
bottomleft.setx(2);
bottomleft.sety(2);
Point topright;
topright.sety(3);
topright.sety(4);
cout << "矩形的面积为:" << area(bottomleft, topright) << endl;
}