定义点类point, 私有数据成员横坐标x.纵坐标y,定义构造函数对其初始化,公有函数成员show负责输出x.y的值,并在main函数中定义对象验证。
#include<iostream>
using namespace std;
class point
{
private:
double x, y;
public:
point()
{cin >> x >> y;}
void show()
{cout << x << y;}
};
int main()
{
point p;
p.show();
return 0;
}