定义一个Test类,该类有私有成员x和y
为该类设计两个成员函数setXY1和setXY2,其中setXY1返回目的对象的指针,而setXY2返回目的对象的引用
main函数已经写好,请根据main函数的内容完成该类的设计:
int main(){
int x,y;
cin>>x>>y;
Test t(x,y);
t.setXY1(10,10)->showXY();
t.setXY2(20,20).showXY();
return 0;
}
输入描述输入x和y
输出描述按样例输出
提示你需要提交除了main函数之外的其他代码
样例输入
2 4
样例输出
12 14
-8 -6
#include<stdio.h>
#include <iostream>
#pragma warning(disable:4996)
#include <string>
using namespace std;
class Test
{
private:
int x, y;
public:
Test() { x = 0; y = 0; }
Test(int x, int y)
{
this->x = x;
this->y = y;
}
Test* setXY1(int x, int y)
{
this->x += x;
this->y += y;
return this;
}
Test& setXY2(int x, int y)
{
this->x -= x;
this->y -= y;
return *this;
}
void showXY()
{
cout << this->x << " " << this->y << endl;
}
};