清高手帮忙,设计一个vc++程序

来源:百度知道 编辑:UC知道 时间:2024/06/09 03:31:22
设有一个描述坐标点的CPoint类,其私有变量x和y代表一个点的x,y坐标值。编写程序实现以下功能:利用构造函数传递参数,并设其默认参数值为60和75,利用成员函数display()输出这一默认的值;利用公有成员函数setpint()将坐标值修改为(80,150),并利用成员函数输出修改后的坐标值

#include <iostream.h>
class CPoint
{
private:
int x;
int y;
public:
CPoint()
{
x=60;
y=75;
}
CPoint(int x,int y)
{
this->x=x;
this->y=y;
}
void Display()
{
cout<<"point("<<x<<","<<y<<")"<<endl;
}
void setpoint(int x,int y)
{
this->x=x;
this->y=y;
}
};
void main()
{
CPoint point1;
point1.Display();
point1.setpoint(80,150);
point1.Display();

CPoint point2(100,100);
point2.Display();
}