求大神帮忙做一下这题c++

2024-11-03 05:28:35
推荐回答(2个)
回答1:

class CPoint
{
int x;
int y;
public:
CPoint(){x=y=0;}
CPoint(int a,int b)
{
x=a;
y=b;
}
void Display()
{
cout <<"宽亏x = " <慎罩神< x << " y = "<< y <<闷漏 endl;
}
};
int main()
{
CPoint p1,p2(2,3);
p1.Display();
p2.Display();
return 0;
}

回答2:

C++程序:

#include 

using namespace std;

class CPoint
{
private:
int x;
int y;
public:
CPoint():x(0), y(0)
{}
CPoint(int x, int y):x(x), 弯友y(y)
{}
void Display()
{
cout<<"("< }
};

int main()
{
CPoint p1 = CPoint(0, 0);
CPoint p2 = CPoint(2, 3);

p1.Display();
p2.Display();

return 0;
}


运行纳巧结果:

(0, 0)
(2, 3)